diff --git a/src/main/browser/session.ts b/src/main/browser/session.ts index 3c93e03..e1c78b5 100644 --- a/src/main/browser/session.ts +++ b/src/main/browser/session.ts @@ -1174,7 +1174,14 @@ export class BrowserSession implements BrowserLike { this.win.focus(); } const inject = () => - this.evaluate(`(() => { try { delete window.__rpaPickResult; ${PICKER_BOOTSTRAP_SOURCE} } catch {} })()`); + this.evaluate( + `(() => { + try { window.__rpaElementPicker?.cancelHard?.(); window.__rpaElementPicker?.cancel?.(); } catch {} + try { window.__rpaPickerActive = undefined; } catch {} + try { document.getElementById('__rpa_pick_host')?.remove(); } catch {} + try { delete window.__rpaPickResult; ${PICKER_BOOTSTRAP_SOURCE} } catch {} + })()` + ); const injectionIds: string[] = []; const registerInjection = async () => { const registered = await this.cdp<{ identifier?: string }>("Page.addScriptToEvaluateOnNewDocument", { @@ -1256,8 +1263,12 @@ declare global { } const PICKER_BOOTSTRAP_SOURCE = `(() => { - if (window.__rpaPickerActive && window.__rpaPickerActive.active) return; - document.getElementById('__rpa_pick_host') && document.getElementById('__rpa_pick_host').remove(); + if (window.__rpaPickerActive && window.__rpaPickerActive.active) { + // 强杀应用等异常场景会留下 active 残留拾取器, 若直接 return 新拾取永远不生效, 必须强制接管 + try { window.__rpaElementPicker?.cancelHard?.(); window.__rpaElementPicker?.cancel?.(); } catch {} + window.__rpaPickerActive = undefined; + document.getElementById('__rpa_pick_host')?.remove(); + } window.__rpaPickResult = null; let host = null;