Skip to content

fix: bound navigation wait in waitForEventsAfterAction to the timeout - #3226

Open
rudycelekli wants to merge 1 commit into
ChromeDevTools:mainfrom
rudycelekli:fix/navigate-page-timeout-overrun
Open

rudycelekli wants to merge 1 commit into
ChromeDevTools:mainfrom
rudycelekli:fix/navigate-page-timeout-overrun

Conversation

@rudycelekli

@rudycelekli rudycelekli commented Oct 17, 2026 •

Copy link
Copy Markdown

Fixes #2943

Root cause

This is in this repo (WaitForHelper.waitForEventsAfterAction), not in Puppeteer. navigate_page runs goto(url, {timeout}) inside the helper's action and catches its timeout error. Afterwards the helper:

  1. waited again for the same, still-pending navigation for a full options.timeout (or 3 s when unset), and
  2. waited up to 3 s (#stableDomTimeout) for a stable DOM on a page that never finished navigating.

So a hanging server cost about 2 * timeout + 3 s.

Fix

  • Measure the time the action already took and wait for the navigation only for the remaining part of the timeout (never less than expectNavigationIn, to avoid racing a navigation that just finished).
  • Skip the stable-DOM wait when the navigation did not finish in time.

Actions that return quickly (click, etc.) behave as before.

Original verification (prior revision)

  • New test navigate_page returns close to the timeout when the server never responds (real Chrome, server that never responds, timeout: 1000): failed before the fix (about 5.0 s), passes after.
  • npm run test tests/tools/pages.test.ts tests/utils/WaitForHelper.test.ts, npm run typecheck, npm run check-format: pass.
  • Full npm run test: all pass except captures logs and errors from extension service worker (tests/tools/console.test.ts), which hit a "Target closed" error under full-suite load; it passes when run alone, both on main and with this change.
  • npm run gen not run: no tool descriptions or schemas changed.

Current revision verification (2026-11-19)

Rebased onto bdecb63549a0b1a6d073fdf69ecc264bf46adda9; current head is edc6b51420a20efeb44ff5bd8218abe7086cd946. The test import conflict preserves main's current mocks and getTextContent helper alongside this change's serverHooks import. The production patch has the same stable patch ID as the prior revision, and the navigation-timeout regression body is unchanged. git diff --check passes.

Fresh local functional validation is blocked by build setup: the current GN/Ninja dependency sync approached the workspace's minimum free-disk reserve and was stopped. The GN executable and generated TypeScript configs are unavailable. The attempted npm run typecheck, focused and full npm run test, npm run format, and npm run check-format therefore could not complete. No fresh test or formatting pass is claimed for this rebased revision; the results above belong to the prior revision.

The Google CLA check remains outstanding and requires the contributor's legal agreement.

@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.

@OrKoN

OrKoN commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

@rudycelekli please sign the CLA

@OrKoN OrKoN left a comment

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.

marking as needing changes

@rudycelekli

Copy link
Copy Markdown
Author

Rebased onto current main. The conflict in tests/tools/pages.test.ts keeps main's dialog mocks and this branch's serverHooks import. WaitForHelper.waitForEventsAfterAction still spends only the remaining navigation budget, and it skips the stable-DOM wait when that navigation already timed out.

The Google CLA check is still the open review. I can't sign that from here.

marco-prontera pushed a commit to marco-prontera/chrome-devtools-mcp that referenced this pull request Nov 11, 2026
Part of ChromeDevTools#3394

`WaitForHelper` decides whether an action navigated by comparing the
page URL before and after it. So a load that ends on the same URL, like
a reload or a form POST that redirects back, isn't reported at all.

This now also tracks whether the main frame loaded a new document during
the action: CDP reports each one with `Page.frameNavigated`, while
same-document navigations come as `Page.navigatedWithinDocument`. A new
document then gets the existing `Page navigated to <url>.` line and
`structuredContent.navigatedToUrl` even when its URL didn't change, in
every tool that reports navigations: `click`, `click_at`, `drag`,
`fill`, `fill_form`, `hover`, `press_key`, `type_text` and
`evaluate_script`.

I checked the tracking against whether `performance.timeOrigin` changed
in headless Chrome 156, and it matched in all 15 cases I tried, among
them a form POST redirecting back to the same URL, a cross-origin
navigation, one committing after the 100 ms window and back/forward
cache restores.

The new test covers a reload that keeps the URL and fails on `main`.
Another one, a `replaceState` that keeps the URL, passes on `main` too
but fails if same-document navigations count as new documents. `npm run
test` passes locally (macOS, Node 26, Chrome 156), and so does the suite
after `npm run bundle`.

`PageCollector` still pairs `FrameNavigatedWithinDocument` with
`framenavigated` in two places, so I'm happy to move both, and the
tracking here, onto the events from puppeteer/puppeteer#15759 once they
land. How same-document navigations are reported moved to ChromeDevTools#3410, which
builds on this. ChromeDevTools#3226 also touches `WaitForHelper.ts`, so I can rebase
on it if it lands first.
@OrKoN

OrKoN commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

@rudycelekli this still needs a signed CL and another rebase. PTAL

When a navigation did not complete, navigate_page returned long after its
timeout: the action already waited for the timeout inside goto, the helper
then waited for the same navigation for another full timeout, and finally
waited up to 3s for a stable DOM on a page that never settled.

Only wait for the remaining part of the timeout budget and skip the stable
DOM wait when the navigation timed out.

Fixes ChromeDevTools#2943

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@rudycelekli
rudycelekli force-pushed the fix/navigate-page-timeout-overrun branch from ff2661c to edc6b51 Compare November 20, 2026 02:14
@rudycelekli

Copy link
Copy Markdown
Author

Rebased onto bdecb635 as requested; the current head is edc6b514. The page-test conflict preserves main's mocks and getTextContent helper together with serverHooks. The production patch and navigation-timeout regression are unchanged, and git diff --check passes.

Fresh GN-based checks remain unverified: dependency sync was stopped at the workspace's free-disk reserve, leaving the GN binary/generated configs unavailable. I labelled the earlier test results as prior-revision evidence in the description and recorded the current limitation.

The Google CLA check still requires contributor action.

@Lightning00Blade

Copy link
Copy Markdown
Collaborator

@rudycelekli
The CLA is blocked to commits including email that has not signed the CLA - @anthropic.com marked as Co-Author.

@OrKoN

OrKoN commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

@OrKoN, friendly reminder: this PR has new commits since the last review and has been waiting for 7 day(s) (automated reminder)

@OrKoN
OrKoN self-requested a review November 27, 2026 10:14

@OrKoN OrKoN left a comment

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.

Please fix the CLA check

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.

navigate_page returns 5-9 s after its timeout when the server does not respond

3 participants