Skip to content

fix: waitForDomNetworkQuiet() can hang forever - #1284

Merged
seanmcguire12 merged 3 commits into
mainfrom
seanmcguire/stg-979-fix-waitfordomnetworkquiet-can-run-forever
Nov 18, 2025
Merged

seanmcguire12 merged 3 commits into
mainfrom
seanmcguire/stg-979-fix-waitfordomnetworkquiet-can-run-forever

Conversation

@seanmcguire12

Copy link
Copy Markdown
Member

why

  • this PR fixes an issue where waitForDomNetworkQuiet() does not resolve
  • this issue is caused by 2-3 underlying issues:
    • the first issue is that frame.waitForLoadState() was not listening for the correct lifecycle events from CDP. instead of listening for DOMContentLoaded, it was listening for domcontentloaded
    • the second issue is that frame.waitForLoadState() did not accept a timeout parameter
    • the third issue is that waitForDomNetworkQuiet() did not include the call to frame.waitForLoadState() as part of the total time that it waits for

what changed

  • added string normalization of incoming lifecycle events from CDP in frame.waitForLoadState() (fixes the first issue)
  • added a timeout parameter to frame.waitForLoadState()
  • within waitForDomNetworkQuiet(), I included the call to frame.waitForLoadState() as part of the total time that it waits for

test plan

  • existing unit tests & regression evals should be ok

@seanmcguire12 seanmcguire12 added the act These changes pertain to the act function label Nov 18, 2025
@changeset-bot

changeset-bot Bot commented Nov 18, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 094ce98

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-evals Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@seanmcguire12 seanmcguire12 removed the act These changes pertain to the act function label Nov 18, 2025
@greptile-apps

greptile-apps Bot commented Nov 18, 2025

Copy link
Copy Markdown
Contributor

Greptile Summary

  • Fixed waitForDomNetworkQuiet() hanging indefinitely by normalizing CDP lifecycle event names (DOMContentLoaded → domcontentloaded) and adding timeout support to frame.waitForLoadState()
  • Improved timeout accounting by tracking elapsed time during waitForLoadState() and using remaining budget for network monitoring phase

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-contained bug fixes that address a critical hanging issue. The implementation correctly normalizes CDP event names, adds proper timeout handling with rejection on timeout, and properly accounts for elapsed time across function boundaries. The logic is sound and defensive.
  • No files require special attention

Important Files Changed

Filename Overview
packages/core/lib/v3/understudy/frame.ts Fixed lifecycle event matching by normalizing CDP event names to lowercase and added timeout parameter to prevent indefinite hangs
packages/core/lib/v3/handlers/handlerUtils/actHandlerUtils.ts Improved timeout handling in waitForDomNetworkQuiet() by accounting for time spent in waitForLoadState() and using remaining budget

Sequence Diagram

sequenceDiagram
    participant User
    participant ActHandler
    participant waitForDomNetworkQuiet
    participant Frame
    participant CDP

    User->>ActHandler: "act(instruction)"
    ActHandler->>waitForDomNetworkQuiet: "waitForDomNetworkQuiet(frame, timeout)"
    Note over waitForDomNetworkQuiet: "Start timer (settleStart)"
    waitForDomNetworkQuiet->>Frame: "evaluate('document.readyState')"
    Frame->>CDP: "Runtime.evaluate"
    CDP-->>Frame: "readyState value"
    Frame-->>waitForDomNetworkQuiet: "readyState result"
    alt "Document not ready"
        waitForDomNetworkQuiet->>Frame: "waitForLoadState('domcontentloaded', timeout)"
        Frame->>CDP: "Page.enable"
        Frame->>CDP: "Listen for Page.lifecycleEvent"
        CDP-->>Frame: "LifecycleEvent(name='DOMContentLoaded')"
        Note over Frame: "Normalize to lowercase"
        Note over Frame: "Match 'domcontentloaded'"
        Frame-->>waitForDomNetworkQuiet: "Load state reached"
    end
    Note over waitForDomNetworkQuiet: "Calculate elapsed & remainingBudget"
    waitForDomNetworkQuiet->>CDP: "Network.enable, Page.enable"
    Note over waitForDomNetworkQuiet: "Monitor network requests"
    waitForDomNetworkQuiet->>CDP: "Listen for Network events"
    CDP-->>waitForDomNetworkQuiet: "Network quiet (500ms)"
    waitForDomNetworkQuiet-->>ActHandler: "DOM settled"
    ActHandler-->>User: "Action completed"
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format

@seanmcguire12
seanmcguire12 merged commit c0f3b98 into main Nov 18, 2025
@github-actions github-actions Bot mentioned this pull request Nov 18, 2025
seanmcguire12 pushed a commit that referenced this pull request Nov 24, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @browserbasehq/[email protected]

### Patch Changes

- [#1281](#1281)
[`fa18cfd`](fa18cfd)
Thanks [@monadoid](https://github.com/monadoid)! - Add Browserbase
session URL and debug URL accessors

- [#1264](#1264)
[`767d168`](767d168)
Thanks [@Kylejeong2](https://github.com/Kylejeong2)! - feat: adding gpt
5.1 to stagehand

- [#1282](#1282)
[`f27a99c`](f27a99c)
Thanks [@tkattkat](https://github.com/tkattkat)! - Add support for zod
4, while maintaining backwards compatibility for zod 3

- [#1295](#1295)
[`91a1ca0`](91a1ca0)
Thanks [@tkattkat](https://github.com/tkattkat)! - Patch zod handling of
non objects in extract

- [#1298](#1298)
[`1dd7d43`](1dd7d43)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - log
Browserbase session status when websocket is closed due to session
timeout

- [#1284](#1284)
[`c0f3b98`](c0f3b98)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix:
waitForDomNetworkQuiet() causing `act()` to hang indefinitely

- [#1246](#1246)
[`44bb4f5`](44bb4f5)
Thanks [@filip-michalsky](https://github.com/filip-michalsky)! - make ci
faster

- [#1300](#1300)
[`2b70347`](2b70347)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - add support
for context.addInitScript()

## @browserbasehq/[email protected]

### Patch Changes

- Updated dependencies
\[[`fa18cfd`](fa18cfd),
[`767d168`](767d168),
[`f27a99c`](f27a99c),
[`91a1ca0`](91a1ca0),
[`1dd7d43`](1dd7d43),
[`c0f3b98`](c0f3b98),
[`44bb4f5`](44bb4f5),
[`2b70347`](2b70347)]:
    -   @browserbasehq/[email protected]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
michaelfp930-WB added a commit to michaelfp930-WB/stagehand that referenced this pull request Jan 12, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @browserbasehq/[email protected]

### Patch Changes

- [#1281](browserbase/stagehand#1281)
[`fa18cfd`](browserbase/stagehand@fa18cfd)
Thanks [@monadoid](https://github.com/monadoid)! - Add Browserbase
session URL and debug URL accessors

- [#1264](browserbase/stagehand#1264)
[`767d168`](browserbase/stagehand@767d168)
Thanks [@Kylejeong2](https://github.com/Kylejeong2)! - feat: adding gpt
5.1 to stagehand

- [#1282](browserbase/stagehand#1282)
[`f27a99c`](browserbase/stagehand@f27a99c)
Thanks [@tkattkat](https://github.com/tkattkat)! - Add support for zod
4, while maintaining backwards compatibility for zod 3

- [#1295](browserbase/stagehand#1295)
[`91a1ca0`](browserbase/stagehand@91a1ca0)
Thanks [@tkattkat](https://github.com/tkattkat)! - Patch zod handling of
non objects in extract

- [#1298](browserbase/stagehand#1298)
[`1dd7d43`](browserbase/stagehand@1dd7d43)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - log
Browserbase session status when websocket is closed due to session
timeout

- [#1284](browserbase/stagehand#1284)
[`c0f3b98`](browserbase/stagehand@c0f3b98)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix:
waitForDomNetworkQuiet() causing `act()` to hang indefinitely

- [#1246](browserbase/stagehand#1246)
[`44bb4f5`](browserbase/stagehand@44bb4f5)
Thanks [@filip-michalsky](https://github.com/filip-michalsky)! - make ci
faster

- [#1300](browserbase/stagehand#1300)
[`2b70347`](browserbase/stagehand@2b70347)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - add support
for context.addInitScript()

## @browserbasehq/[email protected]

### Patch Changes

- Updated dependencies
\[[`fa18cfd`](browserbase/stagehand@fa18cfd),
[`767d168`](browserbase/stagehand@767d168),
[`f27a99c`](browserbase/stagehand@f27a99c),
[`91a1ca0`](browserbase/stagehand@91a1ca0),
[`1dd7d43`](browserbase/stagehand@1dd7d43),
[`c0f3b98`](browserbase/stagehand@c0f3b98),
[`44bb4f5`](browserbase/stagehand@44bb4f5),
[`2b70347`](browserbase/stagehand@2b70347)]:
    -   @browserbasehq/[email protected]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
felipeofdev-ai pushed a commit to felipeofdev-ai/stagehand that referenced this pull request Aug 4, 2026
# why
- this PR fixes an issue where `waitForDomNetworkQuiet()` does not
resolve
- this issue is caused by 2-3 underlying issues:
- the first issue is that `frame.waitForLoadState()` was not listening
for the correct lifecycle events from CDP. instead of listening for
`DOMContentLoaded`, it was listening for `domcontentloaded`
- the second issue is that `frame.waitForLoadState()` did not accept a
timeout parameter
- the third issue is that `waitForDomNetworkQuiet()` did not include the
call to `frame.waitForLoadState()` as part of the total time that it
waits for
# what changed
- added string normalization of incoming lifecycle events from CDP in
`frame.waitForLoadState()` (fixes the first issue)
- added a timeout parameter to `frame.waitForLoadState()`
- within `waitForDomNetworkQuiet()`, I included the call to
`frame.waitForLoadState()` as part of the total time that it waits for
# test plan
- existing unit tests & regression evals should be ok
felipeofdev-ai pushed a commit to felipeofdev-ai/stagehand that referenced this pull request Aug 4, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @browserbasehq/[email protected]

### Patch Changes

- [browserbase#1281](browserbase#1281)
[`fa18cfd`](browserbase@fa18cfd)
Thanks [@monadoid](https://github.com/monadoid)! - Add Browserbase
session URL and debug URL accessors

- [browserbase#1264](browserbase#1264)
[`767d168`](browserbase@767d168)
Thanks [@Kylejeong2](https://github.com/Kylejeong2)! - feat: adding gpt
5.1 to stagehand

- [browserbase#1282](browserbase#1282)
[`f27a99c`](browserbase@f27a99c)
Thanks [@tkattkat](https://github.com/tkattkat)! - Add support for zod
4, while maintaining backwards compatibility for zod 3

- [browserbase#1295](browserbase#1295)
[`91a1ca0`](browserbase@91a1ca0)
Thanks [@tkattkat](https://github.com/tkattkat)! - Patch zod handling of
non objects in extract

- [browserbase#1298](browserbase#1298)
[`1dd7d43`](browserbase@1dd7d43)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - log
Browserbase session status when websocket is closed due to session
timeout

- [browserbase#1284](browserbase#1284)
[`c0f3b98`](browserbase@c0f3b98)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix:
waitForDomNetworkQuiet() causing `act()` to hang indefinitely

- [browserbase#1246](browserbase#1246)
[`44bb4f5`](browserbase@44bb4f5)
Thanks [@filip-michalsky](https://github.com/filip-michalsky)! - make ci
faster

- [browserbase#1300](browserbase#1300)
[`2b70347`](browserbase@2b70347)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - add support
for context.addInitScript()

## @browserbasehq/[email protected]

### Patch Changes

- Updated dependencies
\[[`fa18cfd`](browserbase@fa18cfd),
[`767d168`](browserbase@767d168),
[`f27a99c`](browserbase@f27a99c),
[`91a1ca0`](browserbase@91a1ca0),
[`1dd7d43`](browserbase@1dd7d43),
[`c0f3b98`](browserbase@c0f3b98),
[`44bb4f5`](browserbase@44bb4f5),
[`2b70347`](browserbase@2b70347)]:
    -   @browserbasehq/[email protected]
robog-two added a commit to robog-two/clarity that referenced this pull request Oct 27, 2026
Production run 4c935101 (Ulta) signed in, judged the half-rendered single-page
app at once ("did not happen, p=0.14"), concluded it was not signed in and
restarted the sign-in, costing the person SMS codes. Three changes:

Settle. After every action, navigation and sign-in step, and before look, read
and sign_in, wait until the document is ready, no request finished, no DOM
change and no Clarity step for 500 ms, and no spinner or skeleton is in view
(capped at 8 s). An unsettled report says "Still loading after N s" and never
"did not happen". The page's fetch is not wrapped (the probe stays in the
sandbox; wrapping the page realm is visible to bot detection), so the quiet
window also counts from Clarity's own step. Adopted from Playwright's 500 ms
networkidle window (https://playwright.dev/docs/api/class-page#page-wait-for-load-state),
browser-use's wait_for_network_idle_page_load_time 0.5 s
(https://github.com/browser-use/browser-use/blob/main/browser_use/browser/profile.py)
and Stagehand's capped DOM/network quiet wait
(browserbase/stagehand#1284).

Signed in sticks. A site is signed in on firm signals (no login form, not a
sign-in address, two of: sign-out control or greeting, new cookie names, Jev's
sign_in choice), after Playwright's auth guidance (https://playwright.dev/docs/auth).
Then look says "Signed in to x (since HH:MM)", sign_in refuses to start over
without a login or code field, act refuses sign-in starters and the control
that started this run's sign-in, and go to such a page gets a note. A code
field after sign-in is a second verification: a fresh ask_code, one new code
allowed by the guard, earlier code placeholders refused.

Scrolling. look lists scroll areas ("showing ~8 of ~30 rows, more below") and
how much page is below; act scrolls a named area or the one under the centre;
an off-screen target is scrolled into view before grounding
(https://playwright.dev/docs/actionability); read scrolls the page and each
area to the end and merges the overlap, so lazy and virtualized lists are read
whole. observe.js is split into per-op sections to stay under evaluate_script's
16 KiB.

Test site: a salon with a welcome page that starts sign-in, an SPA behind a
2 s spinner with a "Verify it's you" second-code dialog, and a fixed-layout
booking page with a lazy list of times and a virtualized list of dates. Unit
tests for each piece; a live run of the browser side without models
(LiveBrowserSalonPageTest) and a Jev run (LiveBrowserSalonTest).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NgQqhHAwVmkcUr48UL6FVB
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