feat(sdk-go): add Browserbase ClientOptions to launch and connect
Merged
MI
8d ago+782+782+012345678901234567890123456789-67-67-01234567890123456789
why
Stacked on #3119 (Python), which is stacked on #3118 (TypeScript). Those PRs add Browserbase client options to browserbase.launch() / browserbase.connect() in TS and Python. This PR adds the Go equivalent, so the three SDKs are at parity again and the parity test no longer needs a Go exemption.
what changed
- New
BrowserbaseClientOptionsstruct, set asClientOptions *BrowserbaseClientOptionson bothBrowserbaseLaunchOptionsandBrowserbaseConnectOptions:Timeout time.Duration: applies to each attempt; 0 keeps the 60s default.MaxRetries *int: nil keeps the default of 2.DefaultHeaders map[string]string,DefaultQuery map[string]string.HTTPClient *http.Client: owned by the caller and never modified.
- Go talks to Browserbase over its own
net/httpclient, so the internal options it already had (HTTP client, max retries) are now exposed, plus headers and query. - The timeout is applied per attempt through the request context, both for the default client and for a client the caller passes in, and it also covers reading the response body. The default client no longer sets
http.Client.Timeoutitself. If an attempt times out, only requests that are safe to resend (retrieve, release, delete) are retried, each with a new deadline. Creates fail immediately. - Negative
TimeoutorMaxRetries, invalid header names, and header values containing control characters are rejected before any request is sent. ClientOptionsis never sent in the session-create body; a test checks the body contents.- Removes
pendingGoBrowserFieldsfrom the cross-language parity test. - Docs: the client-options section is a TypeScript / Python / Go tab group again.
- Adds a minor changeset for
@browserbasehq/stagehand-go. This PR is the only change in the stack that releases Go.
header precedence
Same rule as TS and Python: DefaultHeaders override Stagehand's own headers on conflict, including X-BB-API-Key and User-Agent. Both Browserbase SDKs apply caller default headers last; this was checked in their source (@browserbasehq/sdk index.js defaultHeaders, and the Python _base_client). Go still rejects invalid header names or values before sending.
test plan
-
go vet; gofmt (prints nothing);go test -raceon every package except examples; generator--check;scripts/check-examples.sh - New
browserbase_client_options_test.gouseshttptestservers to cover:- options reaching requests, and later changes to the caller's maps having no effect;
- default headers and query on POST and GET, with caller defaults overriding Stagehand's headers (mutation-checked);
MaxRetriesset to 0 and 1, and the default;- the per-attempt timeout, including a retry getting a new deadline and the deadline covering the response body;
- a caller
HTTPClientbeing used and left unmodified; - invalid options failing with zero requests reaching the server, on both launch and connect;
- full launch and connect through the real factory.
- Mutation-checked: with the per-attempt deadline removed, the timeout test fails in about 5s with a clear message.
-
rules/ast-grepparity tests (Go exemption removed), docs tests, the TS suite, oxfmt, oxlint,check-changesets - Plain
go test ./...fails only becausepackages/sdk-go/examplesdoesn't build as a single package; that was already the case. CI and the justfile exclude/examples. - No live Browserbase session was launched