fix(browser): dismiss a page's beforeunload prompt instead of wedging the session - #2257
Open
Benjamin-eecs wants to merge 1 commit into
Open
fix(browser): dismiss a page's beforeunload prompt instead of wedging the session#2257Benjamin-eecs wants to merge 1 commit into
Benjamin-eecs wants to merge 1 commit into
Conversation
Benjamin-eecs
force-pushed
the
fix/browser-beforeunload-guard
branch
from
August 5, 2026 10:37
3b043ac to
ad31816
Compare
Benjamin-eecs
marked this pull request as ready for review
August 5, 2026 10:46
Benjamin-eecs
force-pushed
the
fix/browser-beforeunload-guard
branch
2 times, most recently
from
August 6, 2026 02:15
0a8515e to
dce1af7
Compare
Benjamin-eecs
force-pushed
the
fix/browser-beforeunload-guard
branch
from
August 8, 2026 12:50
dce1af7 to
763b87c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A page that arms
beforeunloadcan wedge a browser session: the next navigation opens the native "Leave site?" prompt, nothing in the CLI can answer it (the daemon owns the CDP session, sobrowser dialog dismissreports no dialog), navigation never returns, and every laterevaluatereads an empty document. Any adapter that clicks before navigating can supply the user gesture the prompt needs;twitter postwedged a session for me twice.Both attach paths, the extension and the direct-CDP
CDPBridge, install two halves: a guard registered throughPage.addScriptToEvaluateOnNewDocument, early enough to stop the site's own handler, and aPage.javascriptDialogOpeninghandler that accepts onlybeforeunloaddialogs, covering documents already loaded at attach.alert,confirmandpromptstay withbrowser dialog.Related issue: none filed; #1972 is @biospark33's twitter-scoped PR for the same wedge, and this installs the guard for every adapter in the layer that runs before page scripts.
Type of Change
Checklist
Documentation (if adding/modifying an adapter)
docs/adapters/(if new adapter)docs/adapters/index.mdtable (if new adapter)docs/.vitepress/config.mts(if new adapter)README.md/README.zh-CN.mdwhen command discoverability changedCliErrorsubclasses instead of rawErrorScreenshots / Output
Navigation-level A/B on Chrome 151.0.7922.76 over raw CDP: a page arms
beforeunloadat load, receives a real click for the user gesture, then navigates away. Without the guard the prompt opens and the navigation never completes, which is the wedge; with the guard pre-injected the navigation completes with no dialog:npx vitest run src/browser433 / 433 and the extension suite 99 / 99, with tests for the guard, the injection at attach, theCDPBridgedialog accept, keeping the two guard copies in step, and leaving non-beforeunloaddialogs alone. Typecheck, both lint gates and doc coverage pass.extension/dist/background.jsis rebuilt, as the repo tracks it.Not verified end to end through a loaded build of this extension, since the daemon tracks one extension connection at a time and the installed build holds the slot.