-
Notifications
You must be signed in to change notification settings - Fork 670
wait for dom settle with CDP network events #768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 32b5df1 The changes in this PR will be included in the next version bump. 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR replaces browser-side mutation observers with CDP network event monitoring for DOM settling detection, addressing execution context errors during navigation.
- Implements new
_waitForSettledDom
inlib/StagehandPage.ts
using CDP to track network requests and determine DOM readiness - Adds intelligent handling of stalled iframe document requests with a 2-second timeout
- Introduces a 500ms "quiet window" requirement after network activity stops before considering DOM settled
- Removes
waitForDomSettle
from browser-side code (global.d.ts
,utils.ts
,process.ts
) - Adds
devtools-protocol
dependency for CDP network event monitoring
5 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile
const hasDoc = !!(await this.page.title().catch(() => false)); | ||
if (!hasDoc) await this.page.waitForLoadState("domcontentloaded"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Check if page.title() throws for reasons other than missing document - may need more specific error handling
* If no new request appears before the timer fires, the promise | ||
* resolves → **DOM is considered settled**. | ||
* 7. A global guard (`timeoutMs` or `stagehand.domSettleTimeoutMs`, | ||
* default ≈ 30 s) ensures we always resolve; if it fires we log how many |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: lower the default timeout
why
page.evaluate: Execution context was destroyed, most likely because of a navigation
page.evaluate
would throw an errorwhat changed
test plan