Skip to content

feat(extension): integrate role/text waits and snapshots - #3189

Open
supremeboxlogos wants to merge 5 commits into
amel/role-text-locators-matchingfrom
amel/role-text-locators-integration
Open

supremeboxlogos wants to merge 5 commits into
amel/role-text-locators-matchingfrom
amel/role-text-locators-integration

Conversation

@supremeboxlogos

Copy link
Copy Markdown
Member

why

Complete extension integration for role and text query plans without exposing SDK builders. Stacked on #3188.

what changed

  • Route selector waits through the matching engine, observing text/ARIA mutations and polling property-only state changes with deterministic cleanup.
  • Reuse the canonical frame resolver for snapshot scopes and exclusions; carry existing XPath frame-prefix metadata instead of duplicating traversal.
  • Distinguish invalid-query evaluation errors from transient snapshot lookup failures, preserving useful messages and original causes.
  • Regenerate the embedded extension ZIP. Public SDK methods remain in the following language-specific PRs.

test plan

  • 947 extension/discovery tests passed; 10 existing todos.
  • 59 real-Chrome cases passed, including mutation/property waits, shadow controls, frame scopes, actions, and upstream matching comparisons.
  • Extension typecheck, extension/SDK builds, packaged-script and deterministic ZIP checks passed.
  • Reviewed the split against the previously verified full implementation; no new smoke-test infrastructure.

@changeset-bot

changeset-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2c50dc8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
@browserbasehq/stagehand-extension Patch
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-python Patch
@browserbasehq/stagehand-go Patch
browse Patch
@browserbasehq/stagehand-examples Patch
@browserbasehq/stagehand-integrations-claude-cua-sdk Patch
@browserbasehq/stagehand-integrations Patch
@browserbasehq/eve Patch
@browserbasehq/stagehand-integrations-gemini-cua-sdk Patch
@browserbasehq/stagehand-integrations-example-pi-facade Patch
@browserbasehq/stagehand-integrations-claude-agent-sdk Patch
@browserbasehq/stagehand-integrations-example-claude-code-facade Patch
@browserbasehq/stagehand-integrations-codex-sdk Patch
@browserbasehq/stagehand-integrations-example-codex-facade Patch
@browserbasehq/stagehand-integrations-cursor-sdk Patch
@browserbasehq/stagehand-integrations-example-cursor-facade Patch
@browserbasehq/stagehand-integrations-deepagents-sdk Patch
@browserbasehq/stagehand-integrations-eve-sdk Patch
@browserbasehq/stagehand-integrations-fx-sdk Patch
@browserbasehq/stagehand-integrations-mastra-sdk Patch
@browserbasehq/stagehand-integrations-example-mastra-facade Patch
@browserbasehq/stagehand-integrations-pi-sdk Patch
@browserbasehq/stagehand-integrations-example-vercel-ai-facade 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

…ocators-integration

# Conflicts:
#	packages/sdk-go/internal/extensionassets/stagehand-extension.zip

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found and verified against the latest diff

Confidence score: 3/5

  • In waitForSelector.ts, semantic waits with pierceShadow: true can miss matches inside closed shadow roots. Update querySemanticSelector to traverse closed roots as well as open ones.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/extension/dom/locatorScripts/waitForSelector.ts">

<violation number="1" location="packages/extension/dom/locatorScripts/waitForSelector.ts:204">
P2: With `pierceShadow: true`, semantic waits cannot find matches inside closed shadow roots: `querySemanticSelector` traverses only `.shadowRoot`, while the previous wait path uses `getOpenOrClosedShadowRoot`. Extend semantic traversal to use the extension's closed-root resolver; otherwise attached waits time out and detached waits can succeed prematurely.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

const pierceShadow = pierceShadowRaw !== false;
const steps = typeof selectorRaw === "string" ? undefined : selectorRaw;
const query = steps
? () => querySemanticSelector(steps, document, { pierceShadow })[0] ?? null

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.

P2: With pierceShadow: true, semantic waits cannot find matches inside closed shadow roots: querySemanticSelector traverses only .shadowRoot, while the previous wait path uses getOpenOrClosedShadowRoot. Extend semantic traversal to use the extension's closed-root resolver; otherwise attached waits time out and detached waits can succeed prematurely.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/extension/dom/locatorScripts/waitForSelector.ts, line 204:

<comment>With `pierceShadow: true`, semantic waits cannot find matches inside closed shadow roots: `querySemanticSelector` traverses only `.shadowRoot`, while the previous wait path uses `getOpenOrClosedShadowRoot`. Extend semantic traversal to use the extension's closed-root resolver; otherwise attached waits time out and detached waits can succeed prematurely.</comment>

<file context>
@@ -191,21 +189,34 @@ const setupShadowObservers = (
   const pierceShadow = pierceShadowRaw !== false;
+  const steps = typeof selectorRaw === "string" ? undefined : selectorRaw;
+  const query = steps
+    ? () => querySemanticSelector(steps, document, { pierceShadow })[0] ?? null
+    : () => findElement(selector, pierceShadow);
+  const observationOptions: MutationObserverInit = {
</file context>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant