mirror of
https://github.com/JimLiu/baoyu-skills.git
synced 2026-07-12 22:09:48 +08:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user