-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[v2]: retry on max depth exceeded #1389
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: e9d058c 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 |
Greptile OverviewGreptile SummaryThis PR adds resilient DOM.getDocument handling to avoid CBOR stack limit errors on complex pages. When the initial request fails due to stack limits, the code retries with progressively smaller depth values (-1 → 256 → 128 → ... → 1) and hydrates missing child nodes using DOM.describeNode calls. Key changes:
Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Client as StagehandPage
participant Utils as lib/a11y/utils.ts
participant CDP as CDP Session
Client->>Utils: buildBackendIdMaps()
Utils->>Utils: getDomTreeWithFallback()
Utils->>CDP: DOM.getDocument(depth=-1)
alt CBOR stack error
CDP-->>Utils: Error: CBOR stack limit exceeded
Utils->>CDP: DOM.getDocument(depth=256)
alt Success with truncated tree
CDP-->>Utils: Partial DOM tree
Utils->>Utils: hydrateDomTree()
loop For each node needing expansion
Utils->>CDP: DOM.describeNode(nodeId, depth)
alt CBOR error
CDP-->>Utils: Error
Utils->>CDP: DOM.describeNode(lower depth)
end
CDP-->>Utils: Node children
Utils->>Utils: mergeDomNodes()
end
end
else Success
CDP-->>Utils: Complete DOM tree
end
Utils-->>Client: BackendIdMaps
|
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.
Additional Comments (1)
-
lib/index.ts, line 825-833 (link)style: This init script registration is now redundant since
StagehandContext.init()on line 816 already adds the same guarded script to the context. The runtime guard (if (!window.__stagehandInjected)) prevents double execution, but this block could be removed to clean up the code.
12 files reviewed, 1 comment
15f6d8a to
6f252b7
Compare
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.
No issues found across 12 files
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.
11 files reviewed, no comments
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 v2, this PR will be updated. # Releases ## @browserbasehq/[email protected] ### Patch Changes - [#1389](#1389) [`575226f`](575226f) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Retry DOM.getDocument on max depth exceeded with exponential backoff - [#1386](#1386) [`dbffb75`](dbffb75) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Remove deprecated internal usage of page.evaluate ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies \[[`575226f`](575226f), [`dbffb75`](dbffb75)]: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies \[[`575226f`](575226f), [`dbffb75`](dbffb75)]: - @browserbasehq/[email protected] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
why
what changed
test plan
Summary by cubic
Retries DOM.getDocument with decreasing depths and hydrates missing nodes to avoid CBOR stack limit errors on complex pages. Also injects the Stagehand init script at the Playwright context level and removes window-scoped helpers to eliminate page.evaluate dependencies.
Bug Fixes
Refactors
Written for commit e9d058c. Summary will update automatically on new commits.