Skip to content

fix(script): clear dialog state after evaluate_script auto-handles a dialog - #2425

Closed
ch-bas wants to merge 1 commit into
ChromeDevTools:mainfrom
ch-bas:fix/evaluate-script-dialog-wedge
Closed

ch-bas wants to merge 1 commit into
ChromeDevTools:mainfrom
ch-bas:fix/evaluate-script-dialog-wedge

Conversation

@ch-bas

@ch-bas ch-bas commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #2424

Problem

After evaluate_script runs a script that opens a JS dialog (alert/confirm/prompt), every subsequent dialog-blocked tool fails with a misleading A dialog is open (...) error — even though the dialog was already auto-handled and is gone. The session stays wedged until handle_dialog is called or the page is navigated/closed.

McpPage stores every dialog in #dialog via a persistent 'dialog' listener. The page-evaluation path of evaluate_script passes handleDialog (default 'accept') so the dialog is auto-accepted, but — unlike the sibling service-worker path (script.ts:100-102) and navigate_page (pages.ts:274-278) — it never clears #dialog. Since evaluate_script and most tools are blockedByDialog: true, the next one throws on throwIfDialogOpen().

Fix

On the page path, clear the dialog state when a dialog was handled, mirroring the worker path:

if (result.dialogHandled) {
  mcpPage.clearDialog();
}

Testing

  • Added clears the dialog state after auto-handling a dialog: evaluates () => { confirm('hello'); return 'done'; } and asserts getDialog() is undefined and throwIfDialogOpen() doesn't throw. Fails on main (getDialog() returns the already-accepted dialog) and passes with this change.
  • npm run test tests/tools/script.test.ts — all tests pass.
  • ESLint + Prettier clean on both changed files.

…dialog

The page-evaluation path of evaluate_script passes handleDialog (default
'accept') to waitForEventsAfterAction, so a dialog opened by the script is
auto-accepted. But unlike the sibling service-worker path (which calls
clearDialog() when result.dialogHandled) and navigate_page, the page path
never clears McpPage's stored dialog reference.

The persistent 'dialog' listener on McpPage records every dialog in
#dialog, so after the auto-accepted dialog is gone, #dialog still points at
it. evaluate_script and many other tools are blockedByDialog: true, so the
next such tool hits throwIfDialogOpen() and fails with a misleading
'A dialog is open' error, wedging the session until handle_dialog is
called or the page is navigated/closed.

Clear the dialog state on the page path too, mirroring the worker path.
Adds a regression test that fails on the previous behavior.

Fixes ChromeDevTools#2424
@OrKoN
OrKoN requested a review from Lightning00Blade July 27, 2026 11:55

@Lightning00Blade Lightning00Blade left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR,
I recently added a change to Puppeteer, it will allows to track the dialog state regardless where it got handled.
puppeteer/puppeteer#15225
Then we can handle this inside throwIfDialogOpen, which would mean we don't have to track each individual place this could happen.
Because of that I will close this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

evaluate_script wedges all dialog-blocked tools: stale dialog state not cleared after auto-handling

2 participants