Skip to content

accept locators for screenshot mask in golang sdk - #2656

Merged
seanmcguire12 merged 2 commits into
v4-spikefrom
go-screenshot-mask-parity
Aug 10, 2026
Merged

accept locators for screenshot mask in golang sdk#2656
seanmcguire12 merged 2 commits into
v4-spikefrom
go-screenshot-mask-parity

Conversation

@seanmcguire12

@seanmcguire12 seanmcguire12 commented Aug 9, 2026

Copy link
Copy Markdown
Member

why

  • for consistency with TS/Python screenshot masks, Go should accept page-bound locator wrappers instead of generated locator descriptor schemas

what changed

  • adds a handwritten Go ScreenshotOptions type for Page.Screenshot
  • changes ScreenshotOptions.Mask to accept []*PageLocator
  • converts mask locators to generated LocatorDescriptor values before sending the page.screenshot RPC
  • validates that mask locators belong to the screenshot target page before sending the request
  • preserves existing screenshot options like animations, caret, clip, full page, mask color, omit background, quality, scale, style, timeout, and type

SDK Shape

Go:

png, err := page.Screenshot(ctx, &stagehand.ScreenshotOptions{
	FullPage: &fullPage,
	Mask: []*stagehand.PageLocator{
		page.Locator(".secret"),
	},
	MaskColor: &maskColor,
})

behavioural notes:

  • Page.Screenshot still returns decoded screenshot bytes
  • nil screenshot options still send no protocol options
  • mask locators serialize to generated LocatorDescriptor values internally, including pageId, selector, and optional nth
  • mask locators from another page are rejected before RPC
  • non-mask screenshot options continue to pass through unchanged
  • TS/Python screenshot behavior and protocol schemas are unchanged

test plan

  • Go SDK tests cover handwritten ScreenshotOptions conversion to generated protocol options
  • Go SDK tests cover *PageLocator mask serialization, including nth
  • Go SDK tests cover cross-page mask locator rejection before RPC
  • Go SDK tests cover preservation of existing non-mask screenshot options

Summary by cubic

Go SDK: Page.Screenshot now accepts page-bound locator masks with strict validation while keeping screenshot behavior unchanged. This also moves act/observe/extract to locator-based scoping across SDKs, updates snapshotting, and standardizes examples to read result data via .data.

  • New Features

    • Page.Screenshot Mask accepts []*PageLocator; nil and cross-page locators are rejected; converts to protocol descriptors before RPC.
    • act/observe/extract accept locator and ignoreLocators (with .nth), validate same-page locators, and serialize in TS batch callbacks.
    • Snapshot capture uses focusLocator/ignoreLocators; locator-scoped calls bypass server cache (responses show cache status DISABLED).
  • Migration

    • Go: replace *PageScreenshotOptions with *ScreenshotOptions; pass page.Locator("...") in Mask.
    • Replace selector/ignoreSelectors with locator/ignoreLocators for act/observe/extract in TS/Python/Go; use .nth(index) when needed.
    • Examples now access result.data instead of the full response.

Written for commit 0baf98c. Summary will update on new commits.

Review in cubic

@changeset-bot

changeset-bot Bot commented Aug 9, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 0baf98c

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.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

@seanmcguire12
seanmcguire12 marked this pull request as ready for review August 9, 2026 21:30

@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.

All reported issues were addressed across 3 files

Architecture diagram
sequenceDiagram
    participant Caller as Go SDK Caller
    participant Page as Page.Screenshot
    participant Conv as screenshotProtocolOptions
    participant Desc as locatorDescriptorsForScreenshot
    participant RPC as Protocol Client (rpc.call)

    Caller->>Page: Screenshot(ctx, &ScreenshotOptions{Mask: []*PageLocator})
    Page->>Page: Get target pageID
    Page->>Conv: screenshotProtocolOptions(options, pageID)
    alt options == nil
        Conv-->>Page: nil protocol options
    else options != nil
        Conv->>Conv: Copy non-mask options to PageScreenshotOptions
        alt options.Mask != nil
            Conv->>Desc: locatorDescriptorsForScreenshot(mask, pageID)
            loop each mask locator
                Desc->>Desc: locator.Descriptor() -> pageId, selector, nth
                alt locator.PageID != pageID
                    Desc-->>Page: error: mask locator must belong to the target page
                    Page-->>Caller: error (no RPC sent)
                end
            end
            Desc-->>Conv: []LocatorDescriptor
            Conv->>Conv: Set protocolOptions.Mask
        end
        Conv-->>Page: *PageScreenshotOptions
    end
    Page->>RPC: page.screenshot (PageScreenshotParams)
    RPC-->>Page: PageScreenshotResult (base64 data)
    Page->>Page: Decode base64 payload
    Page-->>Caller: []byte screenshot
Loading

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

Re-trigger cubic

Comment thread packages/sdk-go/page.go Outdated
@seanmcguire12
seanmcguire12 requested a review from a team as a code owner August 9, 2026 23:55
@seanmcguire12
seanmcguire12 removed the request for review from a team August 10, 2026 00:53
@seanmcguire12
seanmcguire12 force-pushed the go-screenshot-mask-parity branch from ad42af0 to c30f5c8 Compare August 10, 2026 01:08
@seanmcguire12
seanmcguire12 force-pushed the go-screenshot-mask-parity branch from c30f5c8 to 0baf98c Compare August 10, 2026 02:41
@seanmcguire12
seanmcguire12 changed the base branch from locator-inputs to v4-spike August 10, 2026 02:42
@seanmcguire12
seanmcguire12 merged commit 1ea9b63 into v4-spike Aug 10, 2026
7 checks passed
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.

2 participants