feat: auto-dismiss native dialogs in action helpers#316
Closed
edenowong wants to merge 1 commit intobrowser-use:mainfrom
Closed
feat: auto-dismiss native dialogs in action helpers#316edenowong wants to merge 1 commit intobrowser-use:mainfrom
edenowong wants to merge 1 commit intobrowser-use:mainfrom
Conversation
Native dialogs (alert/confirm/prompt/beforeunload) freeze the JS thread, causing action helpers to hang silently — agent has no signal that the run is stuck behind a modal it never expected. Daemon already tracks pending dialogs via Page.javascriptDialogOpening; helpers now check and dismiss after each action. - _check_and_dismiss_dialog(accept=True, prompt_text="") — new helper - goto_url, click_at_xy, press_key, dispatch_key — auto-check post-action - BH_NO_AUTO_DISMISS=1 to opt out per process - 9 unit tests covering all paths (dialog/no-dialog, accept t/f, prompt text, env opt-out, helper integration) Manual API in interaction-skills/dialogs.md still works for callers that need cancel-by-default or specific prompt responses.
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.
Summary
Native dialogs (
alert/confirm/prompt/beforeunload) freeze the JS thread, causing action helpers to silently hang behind a modal the agent never expected. The daemon already tracks pending dialogs viaPage.javascriptDialogOpening, but helpers don't consult it. This PR makes action helpers auto-detect and dismiss after each action so a stray dialog doesn't deadlock the run.Changes
_check_and_dismiss_dialog(accept=True, prompt_text="")inhelpers.py. Reuses the existing_send({"meta": "pending_dialog"})daemon channel thatpage_info()already uses.goto_url(catchesbeforeunload)click_at_xypress_keydispatch_key[auto-dismissed <type>] <message>per dismissal so runs are debuggable.BH_NO_AUTO_DISMISS=1for callers that need to inspect dialogs manually (the existing API ininteraction-skills/dialogs.mdstill works).accept=Truematches the JS-stub pattern ininteraction-skills/dialogs.md(confirm returns true, beforeunload leaves).Why
Currently agents get stuck on sites that throw an unexpected
confirm()mid-flow (e.g. "Are you sure you want to leave?", form-validation alerts, beforeunload on navigation). The screenshot looks normal, the click coordinates are right, but every subsequent action silently no-ops because the JS thread is frozen. The fix is one CDP call (Page.handleJavaScriptDialog) — making it implicit in the action helpers eliminates an entire class of silent-hang failure mode.Test plan
test_dialog_auto_dismiss.pycovering:Page.handleJavaScriptDialogcalled with correct argsaccept=Falseandprompt_text=overridesBH_NO_AUTO_DISMISS=1opt-outclick_at_xy,press_key,goto_urlNotes
self.dialogonPage.javascriptDialogClosed(daemon.py:168), so there's no infinite-loop risk after dismissal.type_text/scroll/upload_file— these don't typically trigger dialogs synchronously and the next action will catch any that slip through.interaction-skills/dialogs.mdis unchanged; this only affects the default behavior of the wrapped helpers.Summary by cubic
Auto-dismiss native
alert/confirm/prompt/beforeunloaddialogs after each action helper to prevent runs hanging behind unexpected modals. This makes interactions more reliable by unfreezing the JS thread automatically._check_and_dismiss_dialog(accept=True, prompt_text="")that checks daemonpending_dialogand callsPage.handleJavaScriptDialog.goto_url,click_at_xy,press_key, anddispatch_key.[auto-dismissed <type>] <message>for debugging.BH_NO_AUTO_DISMISS=1for manual dialog handling.Written for commit af66c7c. Summary will update on new commits.