-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: incorrect nested iframe xpaths #891
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
Conversation
🦋 Changeset detectedLatest commit: 7b5d562 The changes in this PR will be included in the next version bump. 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
This PR fixes a critical bug in the XPath generation system for nested iframes. The core issue was that when multiple sibling iframes existed on a page, the XPath mapping would incorrectly overwrite previous siblings' paths, causing act() operations to fail. This was due to using the parent frame as the key in the internal seg map.
The fix changes the seg map to be keyed by the frame itself rather than its parent frame, ensuring each iframe's XPath information is preserved independently. This is a robust solution that maintains the integrity of the XPath hierarchy while fixing the sibling iframe issue.
The changes include:
- Modified
lib/a11y/utils.tsto use frame instead of parentFrame as map key - Added a new required
framefield to FrameSnapshot interface - Added a new eval test case 'nested_iframes_2' to validate the fix
Confidence score: 5/5
- This PR is very safe to merge as it fixes a clear bug without introducing new complexity
- The score is 5 because the change is well-isolated, includes tests, and fixes a clear logical error in the original implementation
- While all changes look good, pay special attention to
lib/a11y/utils.tsas it contains the core fix
4 files reviewed, no comments
Edit PR Review Bot Settings | Greptile
|
@seanmcguire12 = 🐐 |
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @browserbasehq/stagehand@2.4.2 ### Patch Changes - [#865](#865) [`6b4e6e3`](6b4e6e3) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - improve type safety for trimTrailingTextNode - [#897](#897) [`e77d018`](e77d018) Thanks [@miguelg719](https://github.com/miguelg719)! - Fix selfHeal to remember intially received arguments - [#920](#920) [`c20adb9`](c20adb9) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: tab handling on API - [#882](#882) [`b86df93`](b86df93) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - remove elements that don't have xpaths from observe response - [#905](#905) [`023c2c2`](023c2c2) Thanks [@tkattkat](https://github.com/tkattkat)! - Delete old images from anthropic cua client - [#925](#925) [`8c28647`](8c28647) Thanks [@miguelg719](https://github.com/miguelg719)! - Remove \_refreshPageFromApi() - [#887](#887) [`87e09c6`](87e09c6) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: allow xpaths with prepended 'xpath=' for targeted extract - [#864](#864) [`a611115`](a611115) Thanks [@miguelg719](https://github.com/miguelg719)! - Temporarily patch custom clients serialization error on api - [#881](#881) [`69913fe`](69913fe) Thanks [@miguelg719](https://github.com/miguelg719)! - Pass sdk version number to API for debugging - [#913](#913) [`b1b83a1`](b1b83a1) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - move iframe out of 'experimental' - [#891](#891) [`be8497c`](be8497c) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: nested iframe xpath bug - [#883](#883) [`98704c9`](98704c9) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - add timeout for JS click - [#907](#907) [`04978bd`](04978bd) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - store mapping of CDP frame ID -> page ## @browserbasehq/stagehand-evals@1.0.6 ### Patch Changes - Updated dependencies \[[`6b4e6e3`](6b4e6e3), [`e77d018`](e77d018), [`c20adb9`](c20adb9), [`b86df93`](b86df93), [`023c2c2`](023c2c2), [`8c28647`](8c28647), [`87e09c6`](87e09c6), [`a611115`](a611115), [`69913fe`](69913fe), [`b1b83a1`](b1b83a1), [`be8497c`](be8497c), [`98704c9`](98704c9), [`04978bd`](04978bd)]: - @browserbasehq/stagehand@2.4.2 ## @browserbasehq/stagehand-examples@1.0.6 ### Patch Changes - Updated dependencies \[[`6b4e6e3`](6b4e6e3), [`e77d018`](e77d018), [`c20adb9`](c20adb9), [`b86df93`](b86df93), [`023c2c2`](023c2c2), [`8c28647`](8c28647), [`87e09c6`](87e09c6), [`a611115`](a611115), [`69913fe`](69913fe), [`b1b83a1`](b1b83a1), [`be8497c`](be8497c), [`98704c9`](98704c9), [`04978bd`](04978bd)]: - @browserbasehq/stagehand@2.4.2 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
why
actoften failed on websites where the HTML follows this patterngetAccessibilityTreeWithFrames()populates an internal map:seg: Map<Frame | null, string>frameXpaththe XPath segment (/html/body/iframe[2], …) pointing from that iframe’s parent document to the iframe element itselfseg.set(snapshot.parentFrame, snapshot.frameXpath);frameXpathwould get overwritten/lostwhat changed
segmap by the frame itself so that siblings are no longer overwrittentest plan