diff options
| author | Igor Soarez <igor@soarez.org> | 2026-11-08 15:32:11 +0000 |
|---|---|---|
| committer | Igor Soarez <igor@soarez.org> | 2026-11-08 15:32:11 +0000 |
| commit | 56356bd3400c104eb0b7af1322ff515c155ef7a4 (patch) | |
| tree | 193aa48263fb7a90bb1e229be5a1ab4288f71deb /extensions/chrome-profile-bridge/browser-extension | |
| parent | 0edeb17be41b4f57e40b16b9c86bf5ce85add971 (diff) | |
overlay.clear: click the page body outside the prompt, and wait for it to go
Measured on 1Password's inline menu: blur and Escape did not free the tab, a
click outside did. overlay.clear now also sends pointer/mouse events to the
body and polls the debugger for about a second instead of checking once.
Diffstat (limited to 'extensions/chrome-profile-bridge/browser-extension')
| -rw-r--r-- | extensions/chrome-profile-bridge/browser-extension/service_worker.js | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/extensions/chrome-profile-bridge/browser-extension/service_worker.js b/extensions/chrome-profile-bridge/browser-extension/service_worker.js index 73aabc5..b1710ef 100644 --- a/extensions/chrome-profile-bridge/browser-extension/service_worker.js +++ b/extensions/chrome-profile-bridge/browser-extension/service_worker.js @@ -709,7 +709,7 @@ async function overlayBlockedError(tabId) { } // Injected into the page by overlay.clear. Removes other extensions' iframes (including inside -// open shadow roots), blurs the focused field and sends Escape to the page. +// open shadow roots), blurs the focused field, sends Escape and clicks the page body. function clearForeignOverlays(ownId) { const removed = []; const visit = (root) => { @@ -726,6 +726,12 @@ function clearForeignOverlays(ownId) { const active = document.activeElement; if (active && active !== document.body && typeof active.blur === "function") active.blur(); document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", code: "Escape", bubbles: true })); + // A click outside is what closes a password manager's inline menu (measured on 1Password: this, + // not Escape or blur, is what freed the tab). Sent to the body, so no page control is clicked. + for (const type of ["pointerdown", "mousedown", "pointerup", "mouseup", "click"]) { + const Ctor = type.startsWith("pointer") && typeof PointerEvent === "function" ? PointerEvent : MouseEvent; + document.body.dispatchEvent(new Ctor(type, { bubbles: true, cancelable: true, view: window, button: 0, clientX: 900, clientY: 500 })); + } return { removed }; } @@ -738,14 +744,16 @@ async function clearOverlay(params) { } catch (error) { throw new Error(`Could not run the clean-up on tab ${tab.id}: ${error?.message || error}`); } - await sleep(250); - const remaining = (await findForeignExtensionTargets()).filter((t) => t.tabId === tab.id).map((t) => String(t.url || "").replace(/[?#].*$/, "")); - let debuggerAttachable = true; - try { - await attachDebugger(tab.id); - } catch { - debuggerAttachable = false; + // The prompt takes a moment to go: try the debugger for up to about a second. + let debuggerAttachable = false; + for (let attempt = 0; attempt < 6 && !debuggerAttachable; attempt++) { + await sleep(attempt === 0 ? 150 : 200); + try { + await attachDebugger(tab.id); + debuggerAttachable = true; + } catch {} } + const remaining = (await findForeignExtensionTargets()).filter((t) => t.tabId === tab.id).map((t) => String(t.url || "").replace(/[?#].*$/, "")); return { tab: { id: tab.id, url: tab.url, title: tab.title }, removedFrames: injected.removed, remainingForeignTargets: remaining, debuggerAttachable, cleared: debuggerAttachable && remaining.length === 0 }; } |
