Skip to content
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

Hybrid of a11y tree & DOM for input to observe #459

Merged
merged 14 commits into from
Feb 6, 2025
Merged

Conversation

seanmcguire12
Copy link
Collaborator

why

  • sometimes the role for an AXNode is something useless like none or generic. this isn't very helpful context for the LLM

what changed

  • if the role for an AXNode is none or generic, we replace it with the tagName of its corresponding DOM element

before this PR:

Screenshot 2025-02-03 at 7 11 53 PM

after this PR:

Screenshot 2025-02-03 at 7 14 09 PM

Copy link

changeset-bot bot commented Feb 4, 2025

🦋 Changeset detected

Latest commit: 5a7bd49

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

This PR includes changesets to release 1 package
Name Type
@browserbasehq/stagehand 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

@seanmcguire12 seanmcguire12 added the observe These changes pertain to the observe function label Feb 4, 2025
@seanmcguire12 seanmcguire12 requested review from miguelg719 and kamath and removed request for miguelg719 February 4, 2025 03:25
Copy link
Collaborator

@miguelg719 miguelg719 left a comment

Choose a reason for hiding this comment

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

This looks good to me, you're cooking here

parentId: node.parentId,
childIds: node.childIds,
xpath: node.xpath,
Copy link
Collaborator

Choose a reason for hiding this comment

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

for large websites it makes sense to compute the xpaths at runtime for the candidates selected by observe

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah nice catch, we arent precomputing them, i'll take them out of the AXNode type since they are unused

@@ -99,6 +107,10 @@ export function buildHierarchicalTree(nodes: AccessibilityNode[]): TreeResult {
...(hasValidName && { name: node.name }), // Only include name if it exists and isn't empty
...(node.description && { description: node.description }),
...(node.value && { value: node.value }),
...(node.backendDOMNodeId !== undefined && {
Copy link
Collaborator

Choose a reason for hiding this comment

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

isnt backendDOMNodeId === nodeId?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no, nodeId is a11y specific (remember we used to have negative values for nodeIds)

lib/a11y/utils.ts Outdated Show resolved Hide resolved
level: 1,
});

// fs.writeFileSync("../hybrid_tree.txt", hierarchicalTree.simplified);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// fs.writeFileSync("../hybrid_tree.txt", hierarchicalTree.simplified);

@seanmcguire12 seanmcguire12 merged commit 62a29ee into main Feb 6, 2025
6 checks passed
@github-actions github-actions bot mentioned this pull request Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
observe These changes pertain to the observe function
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants