Skip to content

Return simple getter results directly - #2436

Open
monadoid wants to merge 1 commit into
v4-spikefrom
return-simple-getter-results-directly
Open

Return simple getter results directly#2436
monadoid wants to merge 1 commit into
v4-spikefrom
return-simple-getter-results-directly

Conversation

@monadoid

@monadoid monadoid commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR removes some unnecessary objects and simplifies them to just their values - where it makes sense to and we won't need to extend them later.

Previously, the TypeScript SDK received an object from the protocol and unwrapped its single field:

async count(): Promise<number> {
  const result = await this.rpcClient.send(
    StagehandMethods.locatorCount,
    this.descriptor,
  );
  return result.count; // unwrapped here
}

Now the protocol returns the value directly, so the SDK can return it without unwrapping:

async count(): Promise<number> {
  return await this.rpcClient.send(
    StagehandMethods.locatorCount,
    this.descriptor,
  );
}

The user facing SDKs remain the identical before and after:

const count = await locator.count(); // number
const url = await page.url(); // string
const cookies = await context.cookies(); // Cookie[]
Method and protocol result change Why the object is unnecessary
page.url: { url: string }string
page.title: { title: string }string
Each method explicitly names the scalar being retrieved. Navigation details and other page metadata belong in separate APIs.
locator.count: { count: number }number Count is the complete result. Match details or grouping would be a separate query.
locator.is_checked: { checked: boolean }boolean
locator.is_visible: { visible: boolean }boolean
Predicate methods naturally return booleans. Additional element states or diagnostics should be separate queries.
locator.input_value: { value: string }string
locator.inner_text: { text: string }string
locator.inner_html: { html: string }string
locator.text_content: { textContent: string }string
Each method names the exact DOM scalar being retrieved. Element metadata and diagnostics are separate concerns.
locator.select_option: { values: string[] }string[] The successfully selected values are the meaningful operation result. Target evidence or event diagnostics would be separate instrumentation.
context.clipboard_read_text: { text: string }string readText is deliberately text-specific. Rich clipboard data would require a broader clipboard method.
context.cookies: { cookies: Cookie[] }Cookie[] A complete cookie collection is the conventional result. New cookie attributes belong on Cookie; pagination is not currently needed.
context.get_domain_policy: { policy: DomainPolicy | null }DomainPolicy | null Policy fields naturally belong inside DomainPolicy. Configured and effective policies could be separate APIs if that distinction is needed.

page.wait_for_selector is intentionally unchanged because its result semantics need a separate decision. Coordinate operation results also remain structured objects.

@changeset-bot

changeset-bot Bot commented Jul 26, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 070a0f1

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.

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

@monadoid
monadoid marked this pull request as ready for review July 28, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant