Repository navigation
fix: fail take_snapshot promptly when the accessibility tree does not arrive - #3227
Closed
rudycelekli wants to merge 1 commit into
Closed
rudycelekli wants to merge 1 commit into
rudycelekli wants to merge 1 commit into
Conversation
… arrive take_snapshot awaited Accessibility.getFullAXTree with no bound of its own, so on a page with a pending navigation or a crashed renderer it stalled until the protocol timeout (180 s) while holding the tool lock. Race the request against a 10 s timeout and reject with an actionable error instead. Fixes ChromeDevTools#2939 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
OrKoN
requested changes
Oct 18, 2026
| interestingOnly: !verbose, | ||
| }); | ||
| let timer: ReturnType<typeof setTimeout> | undefined; | ||
| const timeout = new Promise<never>((_, reject) => { |
Collaborator
There was a problem hiding this comment.
there are multiple places with the similar race code and I believe some in-flight PRs also add them, we should extract a re-usable helper or better use the Deferred class from Puppeteer.
johan-gorter
pushed a commit
to johan-gorter/chrome-devtools-mcp
that referenced
this pull request
Oct 20, 2026
…omeDevTools#3265) This PR applies the review comments from two stale PRs. A reviewer requested changes on each PR more than 2 days ago. There are two commits, one for each fix. ## take_snapshot timeout (from ChromeDevTools#3227) - `take_snapshot` waited for Puppeteer's `protocolTimeout` (180 s) when the page did not return the accessibility tree. The tool held the tool lock during this time. - `TextSnapshot.create()` now rejects after 10 s. The error tells the agent to navigate, reload, or select another page. - Review request: "extract a re-usable helper or better use the Deferred class from Puppeteer". This PR adds `withTimeout()` in `src/utils/timeout.ts`. It uses Puppeteer's `Deferred.race`. `src/third_party/index.ts` exports `Deferred`. - In this PR, only `TextSnapshot` calls `withTimeout()`. A separate PR can move the other timeout races to it. ## emulate geolocation (from ChromeDevTools#3145) - `emulate` without `geolocation` set the position to latitude 0, longitude 0. The tool description says that this clears the override. - Review request: "fix this in Puppeteer first". puppeteer/puppeteer#15590 adds `page.setGeolocation(null)`, and it ships in Puppeteer 25.15.0. This repository already uses 25.15.0. `McpPage.emulate()` now calls `setGeolocation(null)` and does not use an internal API. - User-visible change: each `emulate` call without `geolocation` now removes the geolocation override. Before, it set the position to 0,0. ## Tests - `tests/utils/timeout.test.ts`: the helper returns the value when the promise settles first. It rejects with `TimeoutError` when the promise does not settle in time. - `tests/TextSnapshot.test.ts`: a never-resolving `accessibility.snapshot` rejects after 10 s. The test fails on `main`. - `tests/McpPage.test.ts`: `emulate({})` calls `setGeolocation(null)`. The test fails on `main`. - `npm run test` passes. Closes ChromeDevTools#3227 Closes ChromeDevTools#3145 Fixes ChromeDevTools#2939 Fixes ChromeDevTools#2964 Co-authored-by: Rudy Mizrahi Celekli <[email protected]> Co-authored-by: nancy <[email protected]> --------- Co-authored-by: Rudy Mizrahi Celekli <[email protected]> Co-authored-by: nancy <[email protected]>
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.
Fixes #2939
Root cause
TextSnapshot.create()awaitspage.pptrPage.accessibility.snapshot()(CDPAccessibility.getFullAXTree) with no bound of its own. When the page cannot answer (pending navigation that never completes, or a crashed renderer), the request only fails at Puppeteer'sprotocolTimeout(180 s), whiletake_snapshotholds the tool lock so other calls queue behind it.Fix
Race the accessibility snapshot against a 10 s timeout and reject with an actionable error ("Timed out after 10000ms waiting for the accessibility tree. The page may be busy with a pending navigation or its renderer may have crashed. Try navigating or reloading the page, or select another page."). The abandoned request's late rejection is swallowed to avoid an unhandled rejection. This is the "fail promptly with an error that says why" option from the issue; it does not attempt a fallback snapshot of the previously displayed document.
Verification
tests/TextSnapshot.test.ts(never-resolvingaccessibility.snapshotstub + fakesetTimeout): fails before the fix, passes after.tests/TextSnapshot.test.ts,tests/McpPage.test.ts,tests/McpResponse.test.tsandtests/tools/snapshot.test.tspass (all individual tests passed).npm run typecheckandnpm run check-formatpass.Not run
npm run testsuite was not run. In my environment the real-browser test files (e.g.TextSnapshot,McpPage,McpResponse) reported a file-level timeout after all their tests had passed, and the same happens on unmodifiedmainforTextSnapshot.test.ts.🤖 Generated with Claude Code