fix(browser): ensure tab activation before copy/paste in WeChat editor

When posting articles via browser automation, the HTML preview tab
needs to be active before copying content, and the editor tab needs
to be active before pasting. Without explicit Target.activateTarget
calls, AppleScript Cmd+C/Cmd+V would act on the wrong tab, causing
the editor body to remain empty after paste.

This fix adds Target.activateTarget before both copy and paste
operations, ensuring the correct tab is in focus for system-level
clipboard operations.
This commit is contained in:
FENG/XIAODONG
2026-05-09 22:13:06 +08:00
parent aa1a967a9f
commit 0b3b7d13b5
@@ -180,6 +180,10 @@ async function copyHtmlFromBrowser(cdp: CdpConnection, htmlFilePath: string, con
}, { sessionId });
await sleep(300);
console.log('[wechat] Activating HTML tab for copy...');
await cdp.send('Target.activateTarget', { targetId });
await sleep(300);
console.log('[wechat] Copying content...');
await sendCopy(cdp, sessionId);
await sleep(1000);
@@ -189,6 +193,11 @@ async function copyHtmlFromBrowser(cdp: CdpConnection, htmlFilePath: string, con
}
async function pasteFromClipboardInEditor(session: ChromeSession): Promise<void> {
console.log('[wechat] Activating editor tab for paste...');
if (session.targetId) {
await session.cdp.send('Target.activateTarget', { targetId: session.targetId });
await sleep(300);
}
console.log('[wechat] Pasting content...');
await sendPaste(session.cdp, session.sessionId);
await sleep(1000);