Skip to content

Commit e56c6eb

Browse files
[feat]: add support for page.waitForSelector() (#1509)
# why - adds support for a new function: `page.waitForSelector()`, which works with cross-iframe selectors & cross-shadow root selectors # what changed - added `page.waitForSelector()` which returns `true` when the element that the selector points to resolves, and times out with an error when it does not resolve # test plan - added a bunch of e2e test cases, covering various CSS selector types, & cross iframe/shadow root cases <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds Page.waitForSelector() to wait for CSS or XPath targets to reach a state, piercing shadow DOM and traversing iframes. This makes waits reliable across complex trees and uses MutationObserver for efficiency. - **New Features** - Page.waitForSelector(selector, { state, timeout, pierceShadow }) with states: attached, detached, visible, hidden (defaults: visible, 30s, pierceShadow=true). - Supports CSS and XPath (xpath= or /), including open and closed shadow DOM via the V3 piercer. - Works across iframes and with '>>' hop notation; resolves the correct frame automatically. - Clear timeout errors; no polling (MutationObserver-based). - **Refactors** - Added resolveLocatorTarget to unify hop/XPath frame resolution and reuse in waitForSelector. - Exported waitForSelector locator script under dom/locatorScripts. <sup>Written for commit a238850. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --------- Co-authored-by: tkattkat <tkat@tkat.net>
1 parent 6fbf5fc commit e56c6eb

6 files changed

Lines changed: 1568 additions & 49 deletions

File tree

.changeset/silly-rooms-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
add support for page.waitForSelector()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./scripts";
22
export * from "./selectors";
33
export * from "./counts";
4+
export * from "./waitForSelector";

0 commit comments

Comments
 (0)