Skip to content

Migrate SDK consumers to browser context - #2584

Open
miguelg719 wants to merge 1 commit into
miguelgonzalez/stg-2763-wire-browsercontextfrom
miguelgonzalez/stg-2763-migrate-browsercontext
Open

Migrate SDK consumers to browser context#2584
miguelg719 wants to merge 1 commit into
miguelgonzalez/stg-2763-wire-browsercontextfrom
miguelgonzalez/stg-2763-migrate-browsercontext

Conversation

@miguelg719

@miguelg719 miguelg719 commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

why

Consumers must move to the browser-owned context before the Stagehand accessors can be removed.

what changed

Migrates TypeScript, Python, and Go examples, tests, smoke coverage, and v4 documentation to browser context access.

No changeset: this targets the unreleased v4 API.

test plan

  • SDK unit tests
  • Cross-language example parity tests
  • Documentation reference checks

Summary by cubic

Switch all SDK docs, examples, and tests to use the browser-owned context with browser factories and Stagehand.create({ browser }). Completes STG-2763 by replacing stagehand.context with browser.context (or stagehand.browser.context when accessed via Stagehand).

  • Migration
    • TypeScript/Python: replace stagehand.context.* with browser.context.* (or stagehand.browser.context.* as needed). Prefer const [page] = await browser.context.pages() over activePage(). Examples, READMEs, and quickstarts updated; no .init().
    • Docs: v4 basics, first steps, configuration, quickstart, and references now use browserbase.launch, localBrowser.launch/connect, and Stagehand.create({ browser }). Observability reads the session ID from browser.browserbaseSessionId. Clipboard/context/page references use browser.context. Install guides say to pass env values to the browser factory.
    • Go: adopt LaunchLocalBrowser + Create flow; examples use browser.Context().Pages()[0] instead of ActivePage(). Tests (and thin client) use client.Browser().Context(). Guidance in idiomatic_go.md updated.
    • TS tests: access context via stagehand.browser.context; smoke/integration and object-model/create tests updated to reflect no .init and no stagehand.context access.

Written for commit c3d09c4. Summary will update on new commits.

Review in cubic

@miguelg719
miguelg719 requested a review from a team as a code owner August 4, 2026 19:19
@changeset-bot

changeset-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: c3d09c4

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

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

cubic analysis

All reported issues were addressed across 49 files

Linked issue analysis

Linked issue: STG-2763: Change stagehand.context to browser.context

Status Acceptance criteria Notes
Replace references to stagehand.context in v4 docs with stagehand.browser.context / browser.context The diffs show many documentation files updated to reference stagehand.browser.context or browser.context instead of stagehand.context.
Update TypeScript SDK examples and tests to use browser.context when a browser instance is in scope (or stagehand.browser.context otherwise) TypeScript examples and numerous tests were updated to use browser.context or stagehand.browser.context consistently.
Update Python SDK examples and tests to use stagehand.browser.context Python examples, smoke scripts, README, and tests were modified to reference stagehand.browser.context/new_page/active_page instead of stagehand.context.
Update Go SDK examples, tests, and client usages to obtain the BrowserContext via client.Browser().Context() or browser.Context() as appropriate Go client tests, examples, and live tests were updated to call client.Browser().Context() or browser.Context() depending on the example scope, indicating the intended migration of consumers.
Architecture diagram
sequenceDiagram
    participant App as Consumer Application
    participant Stagehand as Stagehand Instance
    participant Browser as Browser Instance
    participant Ctx as BrowserContext
    participant Page as Page Object
    participant Clipboard as BrowserClipboard

    Note over App,Clipboard: Browser-Owned Context Access Pattern (NEW)

    App->>Stagehand: create({ browser })
    Stagehand->>Browser: associate with Stagehand

    App->>Browser: get context
    Browser-->>App: browser.context

    alt Active Page Access
        App->>App: stagehand.browser.context.activePage()
        App->>Stagehand: .browser.context (proxy)
        Stagehand->>Browser: .context
        Browser-->>App: BrowserContext
        App->>Ctx: activePage()
        Ctx-->>App: Page | undefined
    end

    alt New Page Creation
        App->>App: stagehand.browser.context.newPage()
        App->>Ctx: newPage({ url })
        Ctx->>Browser: create new tab
        Browser-->>Ctx: Page object
        Ctx-->>App: Page
    end

    alt Clipboard Operations
        App->>Stagehand: .browser.context.clipboard
        Stagehand->>Browser: .context.clipboard
        Browser-->>App: BrowserClipboard instance
        App->>Clipboard: writeText("Hello")
        Clipboard->>Ctx: clipboard operation
        Ctx-->>App: done
    end

    alt Context Lifecycle
        App->>App: stagehand.browser.context.close()
        App->>Ctx: close()
        Ctx->>Browser: close context
        Browser-->>App: confirmed
    end

    opt Go SDK Pattern
        App->>App: client.Browser().Context()
        App->>Stagehand: .Browser()
        Stagehand-->>App: Browser instance
        App->>Browser: .Context()
        Browser-->>App: BrowserContext
    end

    opt Python SDK Pattern
        App->>Stagehand: .browser.context
        Stagehand-->>App: browser property
        App->>Browser: .context
        Browser-->>App: BrowserContext
    end
Loading

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

Re-trigger cubic

Comment thread packages/sdk-ts/README.md
Comment thread packages/sdk-ts/tests/stagehandCreate.test.ts Outdated
Comment thread packages/sdk-go/stagehand_live_test.go
@miguelg719
miguelg719 force-pushed the miguelgonzalez/stg-2763-migrate-browsercontext branch from d348739 to a575be4 Compare August 4, 2026 19:27
@miguelg719
miguelg719 force-pushed the miguelgonzalez/stg-2763-migrate-browsercontext branch 2 times, most recently from 84cceac to 126b0f4 Compare August 4, 2026 20:25
@miguelg719
miguelg719 force-pushed the miguelgonzalez/stg-2763-migrate-browsercontext branch from 126b0f4 to acbb699 Compare August 4, 2026 21:59
@miguelg719
miguelg719 force-pushed the miguelgonzalez/stg-2763-migrate-browsercontext branch from acbb699 to 8f4820c Compare August 4, 2026 23:42
@miguelg719
miguelg719 force-pushed the miguelgonzalez/stg-2763-migrate-browsercontext branch from 8f4820c to f7cf3df Compare August 4, 2026 23:45
@miguelg719
miguelg719 force-pushed the miguelgonzalez/stg-2763-migrate-browsercontext branch from f7cf3df to c3d09c4 Compare August 4, 2026 23:48
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