元素拾取强制接管残留拾取器, 修复强杀应用后拾取永远走旧逻辑
- 根因: 应用被强杀时页面上残留 active 拾取器(__rpaPickerActive.active=true 永久为真), 引导脚本防重入守卫直接 return, 之后每次拾取都由旧代码残留监听器响应, 选择器无法更新 - 引导脚本改为强制接管: 发现 active 残留先 cancelHard/cancel 并清状态再启动 - pickElement 注入前同步清理残留拾取器/宿主元素/结果变量
This commit is contained in:
parent
cf1e560802
commit
6a27ede6d9
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user