Repository navigation
feat(sdk-ts): add role and text locator builders - #3191
Open
supremeboxlogos wants to merge 6 commits into
Open
supremeboxlogos wants to merge 6 commits into
supremeboxlogos wants to merge 6 commits into
Conversation
🦋 Changeset detectedLatest commit: fea6d6d The changes in this PR will be included in the next version bump. This PR includes changesets to release 21 packages
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 |
Contributor
There was a problem hiding this comment.
1 issue found across 11 files
Confidence score: 4/5
packages/docs/v4/reference/locator.mdxadvertises role/text builders to Python and Go users, though those SDKs don’t expose them. Keep that guidance in the TypeScript tab or label it as TypeScript-only.
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/docs/v4/reference/locator.mdx">
<violation number="1" location="packages/docs/v4/reference/locator.mdx:7">
P2: This shared introduction and the matching rules advertise role/text builders to Python and Go users, but those SDKs do not expose these methods. Move the role/text guidance into the TypeScript tab or label it as TypeScript-only.</violation>
</file>
Architecture diagram
sequenceDiagram
participant Dev as TS SDK Consumer
participant Page as Page (sdk-ts)
participant Loc as Locator (sdk-ts)
participant Query as locatorQuery.ts
participant Proto as stagehand-protocol
participant RPC as RPC Client
participant Browser as Browser Extension
Note over Dev,Browser: Lazy Locator Builder Flow
Dev->>Page: getByRole("button", { name: "Save" })
Page->>Query: roleQueryStep(role, options)
Query->>Query: Convert RegExp to {source, flags}
Query->>Proto: encodeLocatorQuery([step])
Proto-->>Page: Encoded selector string
Page->>Loc: new Locator(descriptor)
Loc-->>Dev: Lazy Locator (no RPC)
Dev->>Loc: getByText("Draft")
Loc->>Query: textQueryStep(text, options)
Query->>Proto: encodeLocatorQuery([...steps])
Proto-->>Loc: Updated descriptor
Loc-->>Dev: Composed Lazy Locator
Note over Dev,Browser: Scoped Descendant Composition
Dev->>Loc: locator("span")
Loc->>Loc: appendLocatorStep(descriptor, {kind:"selector"})
Loc->>Loc: Preserve previous nth index in query order
Loc-->>Dev: Composed Lazy Locator
Note over Dev,Browser: nth Selection Preservation
Dev->>Page: locator("#cards").nth(1)
Page->>Loc: Locator with nth=1
Dev->>Loc: getByRole("heading", { level: 3 })
Loc->>Loc: appendLocatorStep - moves nth into query steps
Loc->>Loc: Clear descriptor.nth, embed as {kind:"nth"}
Dev->>Loc: getByText("Two")
Loc->>Loc: Append text step after nth
Loc-->>Dev: Scoped locator preserving index
Note over Dev,Browser: Action Execution (existing path)
Dev->>Loc: click({ timeout: 5000 })
Loc->>RPC: send("locator.click", descriptor)
RPC->>Browser: RPC call with encoded query
Browser-->>RPC: Result
RPC-->>Loc: Click completed
Loc-->>Dev: void
Note over Dev,Browser: Local Option Validation
Dev->>Page: getByRole("heading", { level: 0 })
alt Invalid options (level=0)
Page-->>Dev: Throw validation error (no RPC)
else Valid options
Page-->>Dev: Returns lazy Locator
end
Note over Dev,Browser: RegExp Handling
Dev->>Page: getByText(/Alpha\nBeta/, { exact: true })
Page->>Query: Convert to {source: "Alpha\\nBeta", flags: ""}
Query->>Proto: Encode with native RegExp data
Proto-->>Page: Selector string
Page-->>Dev: Lazy Locator with regex preserved
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| --- | ||
|
|
||
| Create a `Locator` from a page selector, then reuse it for element interactions and state queries. `first()` and `nth()` refine the local locator descriptor; the resulting descriptor is sent with later operations. | ||
| Create a `Locator` from a page selector, role, or text, then reuse it for element interactions and state queries. Builders are synchronous and lazy: they record a query without contacting the browser. Each later action or read resolves that query against the current DOM. |
Contributor
There was a problem hiding this comment.
P2: This shared introduction and the matching rules advertise role/text builders to Python and Go users, but those SDKs do not expose these methods. Move the role/text guidance into the TypeScript tab or label it as TypeScript-only.
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/docs/v4/reference/locator.mdx, line 7:
<comment>This shared introduction and the matching rules advertise role/text builders to Python and Go users, but those SDKs do not expose these methods. Move the role/text guidance into the TypeScript tab or label it as TypeScript-only.</comment>
<file context>
@@ -4,16 +4,27 @@ description: "Target elements and perform focused DOM interactions"
---
-Create a `Locator` from a page selector, then reuse it for element interactions and state queries. `first()` and `nth()` refine the local locator descriptor; the resulting descriptor is sent with later operations.
+Create a `Locator` from a page selector, role, or text, then reuse it for element interactions and state queries. Builders are synchronous and lazy: they record a query without contacting the browser. Each later action or read resolves that query against the current DOM.
-Selectors pierce shadow DOM, including closed roots.
</file context>
2 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
why
Expose readable role/text queries in TypeScript as a language-sized review. Stacked on #3190; no Python/Go public API changes.
what changed
test plan