Fix/include native selector state into snapshot#2105
Open
imorhun wants to merge 2 commits into
Open
Conversation
Capture native AX selected/checked state as a single node state and render it in snapshot outlines so Stagehand logs align with Playwright-style aria snapshots for selects and radios.
🦋 Changeset detectedLatest commit: 68a51d3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
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 |
Contributor
|
This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run. |
Contributor
There was a problem hiding this comment.
No issues found across 7 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant CDP as Chrome DevTools Protocol
participant AX as a11yTree.ts
participant Constants as constants.ts
participant TreeFormat as treeFormatUtils.ts
participant Snapshot as Snapshot Output
Note over CDP,Snapshot: Accessibility Snapshot with Native Selector State
CDP->>AX: AXNode tree with properties
AX->>AX: decorateRoles() iterates nodes
AX->>Constants: Read state/role constants
AX->>AX: resolveA11yState() extracts state
alt Node has checked=true
AX->>AX: Set state="checked"
else Node has selected=true
AX->>AX: Set state="selected"
else No boolean state
AX->>AX: state=undefined
end
AX->>AX: Build A11yNode with state field
AX-->>TreeFormat: Decorated node tree
TreeFormat->>TreeFormat: formatTreeLine() processes each node
TreeFormat->>Constants: Check A11Y_SELECTED_VISIBLE_ROLES
alt state="checked"
TreeFormat->>TreeFormat: Append [checked] to label
else state="selected" AND role in visible set
TreeFormat->>TreeFormat: Append [selected] to label
else Otherwise
TreeFormat->>TreeFormat: No state flag
end
TreeFormat-->>Snapshot: Formatted output with state markers
Note over Snapshot: Final rendered snapshot<br/>e.g., option: Option B [selected]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Stagehand accessibility snapshot output was missing native selection state markers (
selected/checked) that are visible in PlaywrightariaSnapshot({ mode: "ai" }).That mismatch made it impossible to extract the selected/checked item for dropdowns and radio groups.
Example:
Before this fix, Stagehand-style snapshot output did not indicate the selected option:
Expected (and now aligned more closely with Playwright-style output): selected state is explicit:
What Changed
statefield onA11yNode:state?: "selected" | "checked"a11yTreeto:selected/checkedstatevaluesnapshot/constants.tsfor:[selected]1/0,"true"/"false")treeFormatUtilsto render:[checked]when state is checked[selected]only for selectable option-like roles (Playwright-like behavior)[selected]rendering oncombobox/selectcontainer nodesTest Plan
pnpm --filter @browserbasehq/stagehand run build:esmpnpm --filter @browserbasehq/stagehand run test:core -- packages/core/dist/esm/tests/unit/snapshot-a11y-tree-utils.test.js packages/core/dist/esm/tests/unit/snapshot-tree-format-utils.test.js