From 6a27ede6d9c2a35b812a8d3e4a075ab9741f2188 Mon Sep 17 00:00:00 2001 From: yu <1919727607@qq.com> Date: Thu, 5 Nov 2026 11:41:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=83=E7=B4=A0=E6=8B=BE=E5=8F=96=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E6=8E=A5=E7=AE=A1=E6=AE=8B=E7=95=99=E6=8B=BE=E5=8F=96?= =?UTF-8?q?=E5=99=A8,=20=E4=BF=AE=E5=A4=8D=E5=BC=BA=E6=9D=80=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=90=8E=E6=8B=BE=E5=8F=96=E6=B0=B8=E8=BF=9C=E8=B5=B0?= =?UTF-8?q?=E6=97=A7=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 根因: 应用被强杀时页面上残留 active 拾取器(__rpaPickerActive.active=true 永久为真), 引导脚本防重入守卫直接 return, 之后每次拾取都由旧代码残留监听器响应, 选择器无法更新 - 引导脚本改为强制接管: 发现 active 残留先 cancelHard/cancel 并清状态再启动 - pickElement 注入前同步清理残留拾取器/宿主元素/结果变量 --- src/main/browser/session.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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;