Skip to content

stagehand-python@4.6.0a0.dev1750

@seanmcguire12 seanmcguire12 tagged this 01 Dec 01:04
# why
this pr adds internal annotated page content capture, which calls
chromium's `Page.getAnnotatedPageContent` method & decodes the response
using the schema from the previous pr.

# what changed
- added `captureAnnotatedPageContent()` to the internal `Page`, with one
capture request through the page's main session & actionable information
enabled.
- capture & decoding use the caller's `Progress`, sharing its remaining
deadline & cancellation. late responses are discarded without decoding
or restarting the operation.
- structured results retain hierarchy, frame/document identity, source
node ids, & redaction metadata. capture does not filter nodes by action
eligibility.
- unavailable methods produce `AnnotatedPageContentUnavailableError`
with the original error as its cause. other browser errors, timeouts,
cancellation, & decoding failures retain their own errors.

# test plan
added tests covering:
- main-session capture, actionable request options, structured metadata,
& ownership of the caller's operation budget.
- expired deadlines, cancellation before/during capture, late
success/failure responses, & deadlines exceeded during decoding.
- unavailable methods, other browser failures, malformed responses, &
invalid or unsupported payloads.
- live hierarchy, text, disabled controls, & source node ids resolving
to the original elements.
- same-origin & out-of-process iframes, distinct document identities, &
node resolution through each owning session.
- open/closed & nested shadow roots, slotted text, & source identity
within shadow roots.
- password redaction, including fields switched from password to text,
without exposing their values.



<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds internal capture of annotated page content through Chromium's
`Page.getAnnotatedPageContent` CDP method, completing the internal
capture pipeline previously opened by the decoding work.

- Captures through the page's main session with actionable information
enabled, preserving hierarchy, frame/document identity, source node ids,
and redaction metadata.
- Runs under the caller's `Progress`, sharing its deadline and
cancellation; late responses are discarded without decoding.
- Unsupported browsers raise `AnnotatedPageContentUnavailableError` with
the original error as cause; other browser errors, malformed responses,
and decode failures keep their own errors.
- CDP `-32601` responses for `Page.getAnnotatedPageContent` are now
logged quietly as debug instead of errors, and protocol error details
are preserved as the error cause.
- Verified against live Chrome across same-origin and out-of-process
iframes, open and closed shadow roots, password redaction, and content
refresh after edits or navigation; remains internal with no public
`page.apc()` or RPC endpoint.

<sup>Written for commit 52481875f66ccbba82a60388dd33b8207bd2d549.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/browserbase/stagehand/pull/3588?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<a
href="https://www.cubic.dev/action/auto-fix/pr/browserbase/stagehand/3588?returnTo=https%3A%2F%2Fgithub.com%2Fbrowserbase%2Fstagehand%2Fpull%2F3588&source=description"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img
alt="Turn on auto-fix"
src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
Assets 2
Loading