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

Annotations for Scrollable elements in a11y-dom hybrid #463

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

seanmcguire12
Copy link
Collaborator

why

  • we want the LLM to be able to find scrollable containers in observe calls
  • we don't have this level of granularity with the a11y tree alone

what changed

  • changed the getMainScrollableElement function in process.ts to getScrollableElements, which now optionally returns a list of all the scrollable elements on the page unless the topN param is specified.
  • For usage in processAllOfDom, we set topN to 1 to maintain the existing behaviour.
  • added a new function in process.ts called getScrollableElementXpaths which calls getScrollableElements and then calls generateXpaths on each of the returned elements. This function returns a list of xpaths for each scrollable element on the page.
  • exposed the new getScrollableElementXpaths globally so that it can be called from a11y/utils.ts
  • created a new function findScrollableElementIds in a11y/utils.ts which calls the getScrollableElementXpaths function from the browser context, evaluates the returned xpaths, and returns their corresponding backendDOMId's
  • updated getAccessibilityTree to prepend the string Scrollable to the role of all the scrollable elements in the a11y tree

example

LLM input before this PR:

Screenshot 2025-02-04 at 2 47 22 PM

LLM input after this PR:

Screenshot 2025-02-04 at 2 48 04 PM

Copy link

changeset-bot bot commented Feb 4, 2025

🦋 Changeset detected

Latest commit: a335bca

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 observe These changes pertain to the observe function text-extract These changes pertain to text-extract labels 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 text-extract These changes pertain to text-extract
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants