Repository navigation
fix: add proactive tool rejection when dialog is open - #1978
Merged
Merged
Conversation
samiyac
force-pushed
the
mcp-dialog-pt3
branch
2 times, most recently
from
April 29, 2026 11:36
3010e87 to
5f9ee9d
Compare
OrKoN
reviewed
Apr 29, 2026
OrKoN
reviewed
Apr 29, 2026
OrKoN
reviewed
Apr 29, 2026
OrKoN
approved these changes
Apr 29, 2026
samiyac
enabled auto-merge
April 29, 2026 13:53
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).
This was referenced May 7, 2026
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.
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.
Adding proactive rejection of tool execution for tools which currently get blocked due to open dialogs (related to #1069 )