Skip to content

Conversation

@seanmcguire12
Copy link
Member

@seanmcguire12 seanmcguire12 commented Jan 9, 2026

why

  • to expose a public API for the snapshotting functionality used by stagehand internally

what changed

  • added a new page.snapshot() function, which returns a SnapshotResult object containing:
    • a stringified, hierarchical tree representation of the DOM (the same one that is given to the LLM internally)
    • an xpath map, which contains a mapping of xpaths for elements on the page, keyed by IDs
    • a URL map, which contains a mapping of all URLs inlcuded in the page, keyed by IDs

test plan

  • we already have comprehensive testing for the internals of this function (captureHybridSnapshot()), and this new function does not have any additional branching logic. existing unit tests & evals should suffice.

Summary by cubic

Exposes a public page.snapshot() API to capture a formatted DOM snapshot with xpath and URL maps. Addresses STG-1082 by making the internal snapshotter available to users.

  • New Features

    • Added page.snapshot(): returns SnapshotResult { formattedTree, xpathMap, urlMap } using captureHybridSnapshot (pierces shadow DOM).
    • Introduced StagehandSnapshotError for snapshot failures (keeps original cause).
    • Exported SnapshotResult type.
  • Refactors

    • StagehandError now accepts and stores an optional cause for better error chaining.

Written for commit e89840f. Summary will update on new commits.

@seanmcguire12 seanmcguire12 marked this pull request as ready for review January 9, 2026 21:11
@changeset-bot
Copy link

changeset-bot bot commented Jan 9, 2026

🦋 Changeset detected

Latest commit: e89840f

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

This PR includes changesets to release 3 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-evals Patch
@browserbasehq/stagehand-server 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

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 4 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name=".changeset/tiny-pens-serve.md">

<violation number="1" location=".changeset/tiny-pens-serve.md:2">
P2: New public API method should use 'minor' version bump, not 'patch'. According to semver, adding new functionality like `page.snapshot()` requires a minor version increment.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@seanmcguire12 seanmcguire12 merged commit 5dad639 into main Jan 9, 2026
32 of 33 checks passed
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.

4 participants