You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To do the inverse, add `import "@browserbasehq/sdk/shims/node"` (which does import polyfills).
238
+
To force the legacy Node.js shim, add `import "@browserbasehq/sdk/shims/node"` (which does import polyfills).
239
239
This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/browserbase/sdk-node/tree/main/src/_shims#readme)).
240
240
241
241
### Logging and middleware
@@ -262,9 +262,13 @@ This is intended for debugging purposes only and may change in the future withou
262
262
263
263
### Configuring an HTTP(S) Agent (e.g., for proxies)
264
264
265
-
By default, this library uses a stable agent for all http/https requests to reuse TCP connections, eliminating many TCP & TLS handshakes and shaving around 100ms off most requests.
265
+
By default, modern Node.js uses `globalThis.fetch` and no node:http Agent is attached. In older
266
+
Node.js environments, or when you force the legacy Node.js shim, this library uses a stable agent
267
+
for all http/https requests to reuse TCP connections, eliminating many TCP & TLS handshakes.
266
268
267
-
If you would like to disable or customize this behavior, for example to use the API behind a proxy, you can pass an `httpAgent` which is used for all requests (be they http or https), for example:
269
+
If you would like to customize agent behavior, for example to use the API behind a proxy, you can
270
+
pass an `httpAgent`. In modern Node.js this uses the legacy `node-fetch` transport for that request
Copy file name to clipboardExpand all lines: src/_shims/README.md
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,9 @@
3
3
`@browserbasehq/sdk` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various
4
4
edge runtimes, as well as both CommonJS (CJS) and EcmaScript Modules (ESM).
5
5
6
-
To do this, `@browserbasehq/sdk` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node.
6
+
To do this, `@browserbasehq/sdk` provides shims for using `globalThis.fetch` in modern Node.js,
7
+
falling back to `node-fetch` in older Node.js environments, or using the global `fetch` API built
8
+
into non-Node runtimes.
7
9
8
10
It uses [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to
9
11
automatically select the correct shims for each environment. However, conditional exports are a fairly new
@@ -33,7 +35,8 @@ All client code imports shims from `@browserbasehq/sdk/_shims/index`, which:
33
35
- re-exports the installed shims from `@browserbasehq/sdk/_shims/registry`.
34
36
35
37
`@browserbasehq/sdk/_shims/auto/runtime` exports web runtime shims.
36
-
If the `node` export condition is set, the export map replaces it with `@browserbasehq/sdk/_shims/auto/runtime-node`.
38
+
If the `node` export condition is set, the export map replaces it with `@browserbasehq/sdk/_shims/auto/runtime-node`,
39
+
which prefers native `globalThis.fetch` when available and falls back to the Node runtime shim when needed.
0 commit comments