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
> Once this package is [published to npm](https://app.stainlessapi.com/docs/guides/publish), this will become: `npm install browserbase`
19
-
20
17
## Usage
21
18
22
19
The full API of this library can be found in [api.md](api.md).
23
20
24
21
<!-- prettier-ignore -->
25
22
```js
26
-
importBrowserbasefrom'browserbase';
23
+
importBrowserbasefrom'@browserbasehq/sdk';
27
24
28
25
constclient=newBrowserbase({
29
26
apiKey:process.env['BROWSERBASE_API_KEY'], // This is the default and can be omitted
@@ -44,7 +41,7 @@ This library includes TypeScript definitions for all request params and response
44
41
45
42
<!-- prettier-ignore -->
46
43
```ts
47
-
importBrowserbasefrom'browserbase';
44
+
importBrowserbasefrom'@browserbasehq/sdk';
48
45
49
46
const client =newBrowserbase({
50
47
apiKey: process.env['BROWSERBASE_API_KEY'], // This is the default and can be omitted
@@ -218,11 +215,11 @@ add the following import before your first import `from "Browserbase"`:
218
215
```ts
219
216
// Tell TypeScript and the package to use the global web fetch instead of node-fetch.
220
217
// Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
221
-
import'browserbase/shims/web';
222
-
importBrowserbasefrom'browserbase';
218
+
import'@browserbasehq/sdk/shims/web';
219
+
importBrowserbasefrom'@browserbasehq/sdk';
223
220
```
224
221
225
-
To do the inverse, add `import "browserbase/shims/node"` (which does import polyfills).
222
+
To do the inverse, add `import "@browserbasehq/sdk/shims/node"` (which does import polyfills).
226
223
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)).
227
224
228
225
### Logging and middleware
@@ -232,7 +229,7 @@ which can be used to inspect or alter the `Request` or `Response` before/after e
`browserbase` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various
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, `browserbase` 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 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.
7
7
8
8
It uses [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to
9
9
automatically select the correct shims for each environment. However, conditional exports are a fairly new
@@ -15,32 +15,32 @@ getting the wrong raw `Response` type from `.asResponse()`, for example.
15
15
16
16
The user can work around these issues by manually importing one of:
17
17
18
-
-`import 'browserbase/shims/node'`
19
-
-`import 'browserbase/shims/web'`
18
+
-`import '@browserbasehq/sdk/shims/node'`
19
+
-`import '@browserbasehq/sdk/shims/web'`
20
20
21
21
All of the code here in `_shims` handles selecting the automatic default shims or manual overrides.
22
22
23
23
### How it works - Runtime
24
24
25
-
Runtime shims get installed by calling `setShims` exported by `browserbase/_shims/registry`.
25
+
Runtime shims get installed by calling `setShims` exported by `@browserbasehq/sdk/_shims/registry`.
26
26
27
-
Manually importing `browserbase/shims/node` or `browserbase/shims/web`, calls `setShims` with the respective runtime shims.
27
+
Manually importing `@browserbasehq/sdk/shims/node` or `@browserbasehq/sdk/shims/web`, calls `setShims` with the respective runtime shims.
28
28
29
-
All client code imports shims from `browserbase/_shims/index`, which:
29
+
All client code imports shims from `@browserbasehq/sdk/_shims/index`, which:
30
30
31
31
- checks if shims have been set manually
32
-
- if not, calls `setShims` with the shims from `browserbase/_shims/auto/runtime`
33
-
- re-exports the installed shims from `browserbase/_shims/registry`.
32
+
- if not, calls `setShims` with the shims from `@browserbasehq/sdk/_shims/auto/runtime`
33
+
- re-exports the installed shims from `@browserbasehq/sdk/_shims/registry`.
34
34
35
-
`browserbase/_shims/auto/runtime` exports web runtime shims.
36
-
If the `node` export condition is set, the export map replaces it with `browserbase/_shims/auto/runtime-node`.
35
+
`@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`.
37
37
38
38
### How it works - Type time
39
39
40
-
All client code imports shim types from `browserbase/_shims/index`, which selects the manual types from `browserbase/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `browserbase/_shims/auto/types`.
40
+
All client code imports shim types from `@browserbasehq/sdk/_shims/index`, which selects the manual types from `@browserbasehq/sdk/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `@browserbasehq/sdk/_shims/auto/types`.
41
41
42
-
`browserbase/_shims/manual-types` exports an empty namespace.
43
-
Manually importing `browserbase/shims/node` or `browserbase/shims/web` merges declarations into this empty namespace, so they get picked up by `browserbase/_shims/index`.
42
+
`@browserbasehq/sdk/_shims/manual-types` exports an empty namespace.
43
+
Manually importing `@browserbasehq/sdk/shims/node` or `@browserbasehq/sdk/shims/web` merges declarations into this empty namespace, so they get picked up by `@browserbasehq/sdk/_shims/index`.
44
44
45
-
`browserbase/_shims/auto/types` exports web type definitions.
46
-
If the `node` export condition is set, the export map replaces it with `browserbase/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.
45
+
`@browserbasehq/sdk/_shims/auto/types` exports web type definitions.
46
+
If the `node` export condition is set, the export map replaces it with `@browserbasehq/sdk/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.
0 commit comments