Repository navigation
Commit 100e201
authored
feat(sdk-go): add Browserbase ClientOptions to launch and connect (#3123)
# 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 `BrowserbaseClientOptions` struct, set as `ClientOptions
*BrowserbaseClientOptions` on both `BrowserbaseLaunchOptions` and
`BrowserbaseConnectOptions`:
- `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/http` client, 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.Timeout` itself. 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 `Timeout` or `MaxRetries`, invalid header names, and header
values containing control characters are rejected before any request is
sent.
- `ClientOptions` is never sent in the session-create body; a test
checks the body contents.
- Removes `pendingGoBrowserFields` from 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
- [x] `go vet`; gofmt (prints nothing); `go test -race` on every package
except examples; generator `--check`; `scripts/check-examples.sh`
- [x] New `browserbase_client_options_test.go` uses `httptest` servers
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);
- `MaxRetries` set 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 `HTTPClient` being 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.
- [x] Mutation-checked: with the per-attempt deadline removed, the
timeout test fails in about 5s with a clear message.
- [x] `rules/ast-grep` parity tests (Go exemption removed), docs tests,
the TS suite, oxfmt, oxlint, `check-changesets`
- [ ] Plain `go test ./...` fails only because
`packages/sdk-go/examples` doesn't build as a single package; that was
already the case. CI and the justfile exclude `/examples`.
- [ ] No live Browserbase session was launched1 parent a837acf commit 100e201
7 files changed
Lines changed: 782 additions & 67 deletions
File tree
- .changeset
- packages
- docs/v4/configuration
- sdk-go
- rules/ast-grep
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
| 183 | + | |
184 | 184 | | |
| 185 | + | |
| 186 | + | |
185 | 187 | | |
186 | 188 | | |
187 | 189 | | |
| |||
192 | 194 | | |
193 | 195 | | |
194 | 196 | | |
| 197 | + | |
195 | 198 | | |
| 199 | + | |
196 | 200 | | |
197 | 201 | | |
198 | 202 | | |
| |||
203 | 207 | | |
204 | 208 | | |
205 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
206 | 230 | | |
207 | | - | |
| 231 | + | |
208 | 232 | | |
209 | 233 | | |
210 | 234 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
43 | 62 | | |
44 | 63 | | |
45 | 64 | | |
46 | 65 | | |
| 66 | + | |
47 | 67 | | |
48 | 68 | | |
49 | 69 | | |
| |||
55 | 75 | | |
56 | 76 | | |
57 | 77 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
62 | 83 | | |
63 | 84 | | |
64 | 85 | | |
| |||
68 | 89 | | |
69 | 90 | | |
70 | 91 | | |
71 | | - | |
| 92 | + | |
72 | 93 | | |
73 | 94 | | |
74 | 95 | | |
| |||
198 | 219 | | |
199 | 220 | | |
200 | 221 | | |
201 | | - | |
| 222 | + | |
202 | 223 | | |
203 | 224 | | |
204 | 225 | | |
| |||
232 | 253 | | |
233 | 254 | | |
234 | 255 | | |
235 | | - | |
| 256 | + | |
236 | 257 | | |
237 | 258 | | |
238 | 259 | | |
| |||
249 | 270 | | |
250 | 271 | | |
251 | 272 | | |
252 | | - | |
| 273 | + | |
253 | 274 | | |
254 | 275 | | |
255 | 276 | | |
256 | 277 | | |
257 | 278 | | |
258 | | - | |
| 279 | + | |
259 | 280 | | |
260 | | - | |
| 281 | + | |
261 | 282 | | |
262 | 283 | | |
263 | 284 | | |
264 | | - | |
| 285 | + | |
265 | 286 | | |
266 | 287 | | |
267 | 288 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
646 | 646 | | |
647 | 647 | | |
648 | 648 | | |
| 649 | + | |
| 650 | + | |
649 | 651 | | |
650 | | - | |
| 652 | + | |
651 | 653 | | |
| 654 | + | |
652 | 655 | | |
653 | 656 | | |
654 | 657 | | |
| |||
659 | 662 | | |
660 | 663 | | |
661 | 664 | | |
662 | | - | |
| 665 | + | |
663 | 666 | | |
664 | 667 | | |
665 | | - | |
| 668 | + | |
666 | 669 | | |
667 | 670 | | |
668 | 671 | | |
| |||
672 | 675 | | |
673 | 676 | | |
674 | 677 | | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
675 | 681 | | |
676 | 682 | | |
677 | 683 | | |
| |||
0 commit comments