Skip to content

After evaluate_script auto-handles a dialog, the next response still reports an open dialog that must be handled #2958

Description

@coygeek

Description of the bug

When a script run by evaluate_script opens alert, confirm, or prompt, the dialog is handled automatically (dialogAction defaults to accept) and the call returns its result. The next tool response for that page (observed with take_snapshot) nevertheless starts with # Open dialog ... Call handle_dialog to handle it before continuing., although no dialog is open. handle_dialog then reports "Successfully accepted the dialog" for the dialog that was already handled. The notice disappears only after that extra handle_dialog call or a navigation. Both tested builds behave the same. Closed #2424 reported this stale state (titled "stale dialog state not cleared after auto-handling"; later tools threw A dialog is open). Its fix, PR #2437, changed only throwIfDialogOpen to skip handled dialogs, so the state is still not cleared and the notice remains; this report is the unmet part of #2424's expectation.

Actual behavior

Both builds:

handle_dialog (control, no dialog yet) -> isError=true, "Error: No open dialog found"
evaluate_script -> isError=false, returned "after"
take_snapshot   -> isError=false, structuredContent.dialog = {"type":"alert","message":"hello-alert","defaultValue":""}
  # Open dialog
  alert: hello-alert.
  Call handle_dialog to handle it before continuing.
  ## Latest page snapshot
  ...
handle_dialog   -> isError=false, "Successfully accepted the dialog"
take_snapshot   -> no dialog section
navigate_page reload, take_snapshot -> no dialog section

The first take_snapshot was not blocked (since PR #2437, throwIfDialogOpen ignores handled dialogs), but its response still carries the open-dialog notice and the structured dialog field.

Reproduction

  1. Serve any HTML page from a loopback server, for example save <!doctype html><title>nav</title><p>nav page</p> as nav.html in an empty directory and run python3 -m http.server PORT --bind 127.0.0.1.
  2. Start the server under test with --experimentalStructuredContent (only needed to see the structured dialog field) and send these tools/call requests. The first handle_dialog is a control taken before any dialog exists:
{"name":"new_page","arguments":{"url":"http://127.0.0.1:PORT/nav.html"}}
{"name":"handle_dialog","arguments":{"pageId":2,"action":"accept"}}
{"name":"evaluate_script","arguments":{"pageId":2,"function":"() => { alert('hello-alert'); return 'after'; }"}}
{"name":"take_snapshot","arguments":{"pageId":2}}
{"name":"handle_dialog","arguments":{"pageId":2,"action":"accept"}}
{"name":"take_snapshot","arguments":{"pageId":2}}
{"name":"navigate_page","arguments":{"pageId":2,"type":"reload"}}
{"name":"take_snapshot","arguments":{"pageId":2}}

The sequence was run once per build for this report; an earlier run without --experimentalStructuredContent and without the control call gave the same notice on both builds.

Expectation

dialogAction is described as "Handle dialogs while execution. "accept", "dismiss", or string for response of window.prompt. Defaults to accept." Once the dialog has been handled, no dialog is open. The # Open dialog section tells the agent "Call handle_dialog to handle it before continuing", so it should appear only while a dialog is actually open. After the evaluate_script call returns, the following take_snapshot should not contain the notice, and handle_dialog should not claim to accept a dialog that no longer exists.

MCP configuration

--headless --isolated --no-usage-statistics --no-performance-crux unless the reproduction states otherwise (update checks disabled with CHROME_DEVTOOLS_MCP_NO_UPDATE_CHECKS=1).

Chrome DevTools MCP version

1.10.1 (npm) and main 5ddb0a3 (local build)

Chrome version

154.0.8037.98 (stable)

Node version

v22.23.2

Operating system

macOS 27.0

Environment details

  • chrome-devtools-mcp 1.10.1 from npm (the release build).
  • chrome-devtools-mcp built from main at commit 5ddb0a3 (the main build).
  • Google Chrome 154.0.8037.98 stable, headless; Node v22.23.2; macOS 27.
  • Both builds were started with --headless --isolated --no-usage-statistics --no-performance-crux and CHROME_DEVTOOLS_MCP_NO_UPDATE_CHECKS=1, and driven by a scripted stdio MCP client. In a fresh isolated session the page opened by new_page has page ID 2.

Evidence

  • Expected source: dialogAction parameter description (src/tools/script.ts:78-83 on the main build) and the notice text in src/McpResponse.ts:1014-1027 on the main build.
  • Failure source: scripted MCP runs above on both builds. McpResponse prints the notice whenever page.getDialog() returns a dialog, without checking whether it was handled (src/McpResponse.ts:1014), while McpPage.throwIfDialogOpen() checks !this.#dialog.handled (src/McpPage.ts:331-337). The page branch of evaluate_script does not clear the stored dialog after waitForEventsAfterAction handles it (the service-worker branch does, src/tools/script.ts:147-148).
  • Evidence provenance: observed
  • Local verification: reproduced
  • Reproduction completeness: complete

Fix check

With the steps above, the take_snapshot after evaluate_script contains no # Open dialog section and no dialog field in structuredContent, and handle_dialog called then returns the same Error: No open dialog found as the control call before any dialog. Control: a dialog opened by click (not auto-handled) still produces the # Open dialog notice, blocks dialog-blocked tools, and is accepted by handle_dialog.

Additional context

The full open and closed issue and PR corpus was screened as of 2026-10-06. Closed #2424 ("evaluate_script wedges all dialog-blocked tools: stale dialog state not cleared after auto-handling") had the same trigger. PR #2425, which cleared the stored dialog after auto-handling, was closed without merging; the merged fix, PR #2437 ("don't throw if Dialog was handled"), changed only the throw. This report reports the remaining symptom of that state: the response notice. A separate defect, where evaluate_script is not blocked when a dialog was already open before the call, is a different trigger and is not covered here.

Activity

  1. added theissue type on Oct 13, 2026
  2. added a commit that references this issue on Oct 19, 2026
    2ab93a3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions