Skip to content

fix: fail take_snapshot promptly when the accessibility tree does not arrive - #3227

Closed
rudycelekli wants to merge 1 commit into
ChromeDevTools:mainfrom
rudycelekli:fix/take-snapshot-ax-tree-timeout
Closed

rudycelekli wants to merge 1 commit into
ChromeDevTools:mainfrom
rudycelekli:fix/take-snapshot-ax-tree-timeout

Conversation

@rudycelekli

Copy link
Copy Markdown

Fixes #2939

Root cause

TextSnapshot.create() awaits page.pptrPage.accessibility.snapshot() (CDP Accessibility.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's protocolTimeout (180 s), while take_snapshot holds 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

  • New mock-based unit test in tests/TextSnapshot.test.ts (never-resolving accessibility.snapshot stub + fake setTimeout): fails before the fix, passes after.
  • Other tests in tests/TextSnapshot.test.ts, tests/McpPage.test.ts, tests/McpResponse.test.ts and tests/tools/snapshot.test.ts pass (all individual tests passed).
  • npm run typecheck and npm run check-format pass.

Not run

  • The issue's end-to-end Case A / Case B repros against real Chrome and the MCP server were not run; the fix is covered by the mocked unit test only.
  • The full npm run test suite 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 unmodified main for TextSnapshot.test.ts.
  • The 10 s value is a judgment call; happy to adjust.

🤖 Generated with Claude Code

… 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]>
@google-cla

google-cla Bot commented Oct 17, 2026

Copy link
Copy Markdown

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.

Comment thread src/TextSnapshot.ts
interestingOnly: !verbose,
});
let timer: ReturnType<typeof setTimeout> | undefined;
const timeout = new Promise<never>((_, reject) => {

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.

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.

@OrKoN OrKoN closed this in #3265 Oct 20, 2026
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]>
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.

take_snapshot stalls for 180 s on a page with a pending navigation or a crashed renderer

2 participants