Skip to content

fix: add proactive tool rejection when dialog is open - #1978

Merged
samiyac merged 1 commit into
mainfrom
mcp-dialog-pt3
Apr 29, 2026
Merged

samiyac merged 1 commit into
mainfrom
mcp-dialog-pt3

Conversation

@samiyac

@samiyac samiyac commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Adding proactive rejection of tool execution for tools which currently get blocked due to open dialogs (related to #1069 )

@samiyac
samiyac force-pushed the mcp-dialog-pt3 branch 2 times, most recently from 3010e87 to 5f9ee9d Compare April 29, 2026 11:36
Comment thread src/tools/emulation.ts Resolved
Comment thread src/McpPage.ts Resolved
@samiyac samiyac changed the title fix: add proactive tool rejection when dialog is open - for tools in emulation, memory, screenshot, snapshot fix: add proactive tool rejection when dialog is open Apr 29, 2026
Comment thread src/index.ts Resolved
@samiyac
samiyac enabled auto-merge April 29, 2026 13:53
@samiyac
samiyac added this pull request to the merge queue Apr 29, 2026
Merged via the queue into main with commit 6ce254e Apr 29, 2026
20 checks passed
@samiyac
samiyac deleted the mcp-dialog-pt3 branch April 29, 2026 14:06
pull Bot pushed a commit to Mu-L/chrome-devtools-mcp that referenced this pull request May 4, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.24.0](ChromeDevTools/chrome-devtools-mcp@chrome-devtools-mcp-v0.23.0...chrome-devtools-mcp-v0.24.0)
(2026-05-02)


### 🎉 Features

* agentic browsing in lighthouse
([ChromeDevTools#1931](ChromeDevTools#1931))
([5fa2750](ChromeDevTools@5fa2750))
* **cli:** generate commands for conditional tools
([ChromeDevTools#1962](ChromeDevTools#1962))
([b2b3e99](ChromeDevTools@b2b3e99))
* group identical consecutive console messages in list_console_messages
([ChromeDevTools#1939](ChromeDevTools#1939))
([dbddb2e](ChromeDevTools@dbddb2e))
* support MCP client roots feature
([ChromeDevTools#1945](ChromeDevTools#1945))
([def53dd](ChromeDevTools@def53dd))


### 🛠️ Fixes

* add proactive tool rejection when dialog is open
([ChromeDevTools#1978](ChromeDevTools#1978))
([6ce254e](ChromeDevTools@6ce254e))
* always allow tmpdir access with client roots
([ChromeDevTools#1984](ChromeDevTools#1984))
([a90378a](ChromeDevTools@a90378a))
* **cli:** re-generate cli correctly
([ChromeDevTools#1969](ChromeDevTools#1969))
([8cbdb8d](ChromeDevTools@8cbdb8d))
* handle errors due to open dialogs during tool calls
([ChromeDevTools#1953](ChromeDevTools#1953))
([06b331f](ChromeDevTools@06b331f))
* note about missing elements should not show in verbose mode
([ChromeDevTools#1950](ChromeDevTools#1950))
([80bee1e](ChromeDevTools@80bee1e))
* **telemetry:** bucketize string length
([ChromeDevTools#1972](ChromeDevTools#1972))
([bf3cb58](ChromeDevTools@bf3cb58))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
twotnguyen pushed a commit to twotnguyen/chrome-devtools-mcp that referenced this pull request Oct 16, 2026
Fixes ChromeDevTools#2936

## Problem

When a dialog is already open on the page, `evaluate_script` does not
fail fast like other `blockedByDialog: true` tools. It waits for the CDP
protocol timeout (180 s) and holds the tool lock the whole time, so
every other tool call is queued behind it.

Root cause: `evaluate_script` is defined with `defineTool` (not
`definePageTool`) because it can also target a service worker.
`ToolHandler` runs `page.throwIfDialogOpen()` only in the page-scoped
branch, so the `blockedByDialog: true` flag on `evaluate_script` has no
effect. It is the only non-page-scoped tool with that flag. The check
was originally applied to all tools (ChromeDevTools#1978) and was later limited to
page-scoped tools in ChromeDevTools#2030, so that non-page tools do not have to
resolve a page.

## Behavior change

Before this change, `evaluate_script` could still run while a dialog
that was already open and recorded on the page (for example one opened
by a timer, as in the last part of ChromeDevTools#2936) was showing. It now returns `A
dialog is open (...)` in that case, and `handle_dialog` is the way
forward.

## Fix

In the page path of the `evaluate_script` handler, call
`mcpPage.throwIfDialogOpen()` after the target page is resolved and
before any evaluation. `blockedByDialog` is now `false` on
`evaluate_script`, because the flag has no effect on a `defineTool`
tool, and `ToolDefinition` and `BrowserlessToolDefinition` narrow
`blockedByDialog` to `false`, so the compiler rejects `true` on any
non-page tool (`PageToolDefinition` keeps `boolean`). The call now fails
with the same `A dialog is open (<type>: <message>).` error as other
blocked tools.

- `ToolHandler` is unchanged, so non-page tools still do not need a page
(the ChromeDevTools#2030 behavior is kept). A generic check there would also have to
tell the page path from the `serviceWorkerId` path, and would block
worker evaluations that a page dialog does not affect, so the check
lives in the handler where the target page is already resolved.
- The service worker path is unchanged, because a page dialog does not
block a worker.
- The error response is the bare `A dialog is open (...)` error. Unlike
page-scoped tools, it does not include the `# Open dialog ... Call
handle_dialog` hint, because `ToolHandler` only attaches the page to the
response for page-scoped tools. A TODO in `script.ts` tracks adding the
hint once `Response` can attach the page for non-page-scoped tools.
- `throwIfDialogOpen()` ignores dialogs that were already handled
(ChromeDevTools#2437), so a dialog that `evaluate_script` auto-handled through
`dialogAction` does not block later calls.
- A dialog that opens during the script is still handled per
`dialogAction`.

## Tests

- `tests/tools/script.test.ts`: a mock-based handler test. When
`throwIfDialogOpen` throws, the handler rejects with that error and
never calls `waitForEventsAfterAction`.
- `tests/index.test.ts` (e2e, Dialogs): a click opens an alert, then
`evaluate_script` returns `isError` with `A dialog is open (alert: test
dialog).`.

## Verification

- With the issue's scenario against a local build, `main` returned
`Runtime.evaluate timed out ...` after 180008 ms. With this change it
returns `Error: A dialog is open (alert: hello alert).` in 4 ms.
- Both new tests fail when the fix is reverted. The e2e test hits a
client request timeout, and the handler test reports `Missing expected
rejection`.
- `tests/ToolHandler.test.ts`, `tests/tools/script.test.ts`,
`tests/McpPage.test.ts` and `tests/index.test.ts` pass, along with `npm
run build`, eslint and prettier on the changed files.
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.

2 participants