# why
locator chains need to enter an iframe when the next query searches
inside it. for example, `iframe.checkout -> button` should find buttons
in the checkout document, while a chain ending at `iframe.checkout`
should select the iframe element itself.
this adds internal chain resolution across iframe documents, including
nested frames & cross-origin frames that run in a separate browser
process.
# what changed
- added `FrameChainResolver` for queries that move between ordinary
element scopes & iframe documents. explicit frame hops require
iframe/frame targets.
- batch queries within each document & restore the original scope order
before removing duplicate elements or applying `nth`. a sequence of
main-page scope, iframe, & another main-page scope keeps that order in
the results.
- retain intermediate elements inside their owning documents. only
iframe hosts needed for entry & requested final targets need backend
node ids; count mode does not export final elements.
- reuse frame lookup by exact element identity & retry delayed
discovery. detect navigation, detachment, & session changes during
resolution so results from different documents cannot be mixed.
- share one deadline across frame entry, readiness, & queries. release
temporary objects in every participating session, including replies
arriving after timeout.
### note
public locator chaining comes in the next pr
# test plan
added `frameChainResolution.test.ts` & `frameChainResolver.test.ts`
covering:
- iframe selection versus entry, explicit hops, multiple matched frames,
empty documents, & nested same-origin/cross-origin frames in real
chrome.
- css, xpath, & text queries inside child documents, including open &
closed shadow roots.
- actions on the exact resolved button after another button takes its
selector.
- mixed-document ordering in count, selected, & all-target modes;
positions before/after queries; & overlapping scopes deduplicated by
element identity.
- 500 & 1,000 matches per document: the same number of query calls at
both sizes, with node-description calls only for iframe entry &
requested final targets. frame discovery still has its own protocol
calls.
- navigation or removal during resolution, including an iframe removed
after matching but before entry, & discovery delayed behind an
already-known sibling.
- unavailable worlds, bounded default waits, shared deadlines,
cancellation, session adoption, & bounded concurrent target descriptions
that preserve order.
- cleanup across sessions after success, failure, & late replies.
temporary handles become unusable, consumer-owned handles remain usable,
& one stalled cleanup does not prevent cleanup in another session.
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Resolves locator chains across iframe documents so `iframe.checkout ->
button` queries inside the checkout document, while a chain ending at
`iframe.checkout` still selects the iframe element itself.
- Adds `FrameChainResolver` for chains moving between ordinary element
scopes and iframe documents, including nested and cross-origin frames;
explicit frame hops require an iframe or frame target.
- Batches queries within each document and restores original scope order
before deduplicating matches or applying `nth`.
- Retries frame entry when a session swap adopts the frame
mid-installation, keeping the original deadline and rejecting if
ownership changes after results are collected.
- Rejects resolution when an iframe detaches, navigates, or changes
session mid-chain.
- Shares one deadline across frame entry, readiness, and queries, and
releases temporary objects in every session, including replies arriving
after timeout.
- This is internal chain resolution; public locator chaining is a
separate follow-up.
<sup>Written for commit b7ae92929b4d8a5a561c58cbc006c8d47cbc286d.
Summary will update on new commits.</sup>
<a
href="https://cubic.dev/pr/browserbase/stagehand/pull/3537?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<a
href="https://www.cubic.dev/action/auto-fix/pr/browserbase/stagehand/3537?returnTo=https%3A%2F%2Fgithub.com%2Fbrowserbase%2Fstagehand%2Fpull%2F3537&source=description"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img
alt="Turn on auto-fix"
src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->