feat(sdk): allow injecting a Browserbase client
Closed
PR
1mo ago+206+206+012345678901234567890123456789-10-10-01234567890123456789
why
Applications that centralize Browserbase setup need to reuse an existing
@browserbasehq/sdk client when launching or attaching Stagehand browsers.
Today, browserbase.launch() and browserbase.connect() always create a new
Browserbase client. This prevents callers from supplying their own configured
Browserbase management client and endpoint.
what changed
- Add an optional
client?: Browserbaseoption to TypeScript
browserbase.launch()andbrowserbase.connect(). - Reuse the supplied client for Browserbase session and extension lifecycle
operations, including session create, retrieve, release, and extension
provisioning/cleanup. - Preserve existing behavior when
clientis omitted. - Keep
apiKeyfor Stagehand runtime authentication. - Document that the supplied client controls Browserbase management requests;
baseUrlis therefore not used for those requests. - Add TypeScript factory, lifecycle, contract, package-consumer, and
cross-language schema-parity coverage. - Add a minor Changeset for
@browserbasehq/stagehand.
test plan
-
pnpm build -
pnpm fmt:check -
pnpm check -
pnpm test— 33 workspace tasks passed; 80 test files / 627 tests - Focused SDK coverage — 20 test files / 282 tests
- Published-package consumer type fixture
- Cross-language schema-parity test
- Go SDK test, vet, build, generator, and example checks
- Full
justPython coverage was not run because the disposable validation
sandbox did not includeuv. - The Go extension-pack consistency check reports a pre-existing mismatch
in the committed embedded extension archive; this PR changes neither
artifact.
Summary by cubic
Adds an optional client option to browserbase.launch() and browserbase.connect() so callers can reuse an existing @browserbasehq/sdk client for session and extension lifecycle management. Previously these methods always created a new Browserbase client; now they use the supplied client, and existing behavior is unchanged when client is omitted.
- When
clientis provided, it determines the Browserbase management endpoint;baseUrlis ignored for those calls. apiKeystill configures Stagehand runtime authentication.