From 0b3b7d13b52ff9e8400e896f850fcec948a09d70 Mon Sep 17 00:00:00 2001 From: FENG/XIAODONG Date: Sat, 9 May 2026 22:13:06 +0800 Subject: [PATCH] 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. --- skills/baoyu-post-to-wechat/scripts/wechat-article.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/skills/baoyu-post-to-wechat/scripts/wechat-article.ts b/skills/baoyu-post-to-wechat/scripts/wechat-article.ts index fc1bec5..2e52cd5 100644 --- a/skills/baoyu-post-to-wechat/scripts/wechat-article.ts +++ b/skills/baoyu-post-to-wechat/scripts/wechat-article.ts @@ -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 { + 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);