Skip to content

fix(extension): hop into iframes selected by attribute predicates - #3418

Open
brennanbutler01 wants to merge 1 commit into
browserbase:mainfrom
brennanbutler01:fix/deep-xpath-iframe-attribute-hop
Open

brennanbutler01 wants to merge 1 commit into
browserbase:mainfrom
brennanbutler01:fix/deep-xpath-iframe-attribute-hop

Conversation

@brennanbutler01

@brennanbutler01 brennanbutler01 commented Nov 9, 2026 •

Copy link
Copy Markdown

why

Deep XPaths that select an iframe by an attribute predicate never crossed the frame boundary. parseXPath stripped only a trailing positional predicate when computing the step name, so IFRAME_STEP_RE recognized iframe[2] but not iframe[@name='main'] — planDeepXPathTarget("//iframe[@name='main']//button") kept the iframe step in the final selector and resolved it as an element in the parent frame, failing even though the target exists inside the iframe. Positional form (//iframe[1]//button) worked.

Closes #3416

what changed

  • parseXPath (understudy/deepLocator.ts) and parseXPathToSteps (understudy/a11y/snapshot/focusSelectors.ts) now strip all bracketed predicates when computing the step name, so any iframe/frame step is recognized as a hop regardless of how it is selected.
  • IFRAME_STEP_RE simplified to /^i?frame$/i — both call sites feed it predicate-stripped names.
  • Hop selectors are unchanged in output: buildXPathFromSteps still uses the raw step text, so predicates stay in the hop selector and the correct iframe element is still selected.
  • The same fix applies to the a11y snapshot focus-frame walker, which had the identical positional-only assumption, so focus resolution is consistent with deep-locator resolution.

test plan

  • Extended packages/extension/tests/deep-locator.test.ts: attribute-predicate hop (//iframe[@name='main']//button), mixed positional+attribute hop (//iframe[2][@title='content']//button), and a predicate-free hop regression case. All hop selectors preserve their raw predicates.
  • pnpm --filter ./packages/extension test:unit → 73 files / 1191 tests passing, extension typecheck clean.

Summary by cubic

Deep XPaths selecting an iframe by attribute predicate (e.g. //iframe[@name='main']//button) now cross the frame boundary; previously only positional predicates like //iframe[1] worked, and attribute-selected iframes resolved against the parent frame and failed. Closes #3416.

  • Strips all bracketed predicates when computing step names in both deepLocator.ts and focusSelectors.ts, so any iframe/frame step is recognized as a hop.
  • Hop selectors keep their raw predicates, so the correct iframe element is still selected.
  • Applies the same fix to the a11y snapshot focus-frame walker for consistent focus resolution.

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

View guided diff

parseXPath stripped only a trailing positional predicate when computing
the step name, so IFRAME_STEP_RE (/^i?frame(?:\[\d+])?$/) recognized
iframe[2] but not iframe[@name='main']. Deep XPaths that selected the
iframe by attribute never crossed the frame boundary: the remaining path
was resolved in the parent frame and failed.

Strip all bracketed predicates for the step name in both parseXPath
(deepLocator) and parseXPathToSteps (a11y focus selectors), so any
iframe/frame step hops; hop selectors keep their full raw predicates
(Closes browserbase#3416)

Amp-Thread-ID: https://ampcode.com/threads/T-01a1bd90-aa00-7234-b10d-723391130866
Co-authored-by: Amp <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 01:13
@changeset-bot

changeset-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a7ab255

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run.
Approving the latest commit mirrors it into an internal PR owned by the approver.
If new commits are pushed later, the internal PR stays open but is marked stale until someone approves the latest external commit and refreshes it.

@github-actions github-actions Bot added external-contributor Tracks PRs mirrored from external contributor forks. external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. labels Nov 9, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. external-contributor Tracks PRs mirrored from external contributor forks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deepLocator deep-XPath only treats positionally-indexed iframe steps as frame hops — iframe[@name='…'] paths resolve in the wrong frame

2 participants