browse 0.8.2 → 0.8.3-alpha-95f9a9d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +181 -33
- package/dist/commands/click.js +0 -1
- package/dist/commands/network/on.js +0 -1
- package/dist/lib/cloud/api.js +5 -2
- package/dist/lib/driver/doctor.js +5 -10
- package/dist/lib/driver/mode.js +5 -3
- package/dist/lib/driver/remote-binding.js +27 -0
- package/dist/lib/driver/remote-types.js +1 -0
- package/dist/lib/driver/remote.disabled.js +18 -0
- package/dist/lib/driver/remote.js +37 -0
- package/dist/lib/driver/session-manager.js +4 -15
- package/oclif.manifest.json +449 -451
- package/package.json +16 -19
- package/skills/browse/SKILL.md +5 -1
package/README.md
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/browse)
|
|
8
8
|
[](https://www.npmjs.com/package/browse)
|
|
9
|
-
[](https://github.com/browserbase/stagehand/blob/main/packages/cli/LICENSE)
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
12
|
npm install -g browse
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
<img src="https://github.com/browserbase/
|
|
15
|
+
<img src="https://github.com/browserbase/stagehand/blob/main/packages/cli/media/browse.gif?raw=true" alt="browse CLI demo" width="100%" />
|
|
16
16
|
|
|
17
17
|
</div>
|
|
18
18
|
|
|
@@ -22,7 +22,7 @@ npm install -g browse
|
|
|
22
22
|
|
|
23
23
|
## Why browse
|
|
24
24
|
|
|
25
|
-
- **Browser interactions** — Navigate tricky, complex websites with `browse click`, `browse mouse scroll`, `browse type`, `browse select`, and
|
|
25
|
+
- **Browser interactions** — Navigate tricky, complex websites with `browse click`, `browse mouse scroll`, `browse type`, `browse select`, and 30+ more DOM commands.
|
|
26
26
|
- **Open web skills catalog** — `browse` is the official CLI for [browse.sh](https://browse.sh), the largest open web catalog. Run `browse skills add apartments.com` and your agent learns how to use that site and its APIs.
|
|
27
27
|
- **Rich debugging** — Arm your agents with network, console, and other web telemetry.
|
|
28
28
|
- **Cloud features** — Optionally use Browserbase cloud: load cookies via saved [Contexts](https://docs.browserbase.com/platform/browser/core-features/contexts), use [Verified Browsers](https://www.browserbase.com/verified), and call the [Fetch and Search APIs](https://www.browserbase.com/search).
|
|
@@ -41,36 +41,154 @@ browse screenshot --path page.png
|
|
|
41
41
|
browse stop
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
##
|
|
44
|
+
## How it works
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
`browse` runs a lightweight per-session daemon. The first command starts it, and subsequent commands reuse the same browser — so cookies, tabs, and snapshot refs persist between invocations. Run multiple isolated browsers at once with `--session <name>` (or the `BROWSE_SESSION` env var), and shut a session down with `browse stop`.
|
|
47
|
+
|
|
48
|
+
### Browser targets
|
|
49
|
+
|
|
50
|
+
Every driver command accepts the same flags to pick where the browser runs. Mix and match per command:
|
|
51
|
+
|
|
52
|
+
| Flag | Target |
|
|
53
|
+
|------|--------|
|
|
54
|
+
| _(default)_ | Managed local browser, or remote when `BROWSERBASE_API_KEY` is set |
|
|
55
|
+
| `--local` | Managed local browser (add `--headed` / `--headless`) |
|
|
56
|
+
| `--remote` | Remote Browserbase session (uses `BROWSERBASE_API_KEY`) |
|
|
57
|
+
| `--auto-connect` | Auto-discover and attach to a local Chrome with remote debugging enabled |
|
|
58
|
+
| `--cdp <url\|port>` | Attach directly to a CDP endpoint (port, `http(s)://`, or `ws(s)://`) |
|
|
59
|
+
| `--target-id <id>` | Select a specific CDP target when attaching to an existing browser |
|
|
47
60
|
|
|
48
61
|
```bash
|
|
49
|
-
browse open https://example.com
|
|
62
|
+
browse open https://example.com # default target
|
|
50
63
|
browse open https://example.com --local --headed
|
|
51
64
|
browse open https://example.com --remote
|
|
52
65
|
browse open https://example.com --auto-connect
|
|
53
66
|
browse open https://example.com --cdp 9222
|
|
54
67
|
browse open https://example.com --cdp ws://127.0.0.1:9222/devtools/browser/<id> --target-id <target-id>
|
|
55
|
-
browse snapshot --compact
|
|
56
|
-
browse click @0-12
|
|
57
|
-
browse fill @0-8 "hello"
|
|
58
|
-
browse mouse click 240 320
|
|
59
|
-
browse get title
|
|
60
|
-
browse screenshot --path page.png
|
|
61
|
-
browse tab list
|
|
62
|
-
browse tab switch <target-id>
|
|
63
|
-
browse network on
|
|
64
|
-
browse cdp 9222 --pretty
|
|
65
|
-
browse status
|
|
66
|
-
browse stop
|
|
67
68
|
```
|
|
68
69
|
|
|
69
|
-
|
|
70
|
+
Run `browse doctor` to diagnose session and browser-connection prerequisites for any target.
|
|
71
|
+
|
|
72
|
+
## Commands
|
|
73
|
+
|
|
74
|
+
### Navigation
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
browse open <url> # Open a URL (--wait load|domcontentloaded|networkidle, --timeout <ms>)
|
|
78
|
+
browse reload # Reload the active page
|
|
79
|
+
browse back # Navigate backward
|
|
80
|
+
browse forward # Navigate forward
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Snapshot & refs
|
|
84
|
+
|
|
85
|
+
The accessibility snapshot is the recommended way for agents to discover elements. It prints a tree of refs like `@0-12` that the element commands accept directly.
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
browse snapshot # Accessibility snapshot + cached refs
|
|
89
|
+
browse snapshot --compact # Tree only, no ref maps
|
|
90
|
+
browse snapshot --filter submit # Filter lines by text or /regex/, keeping ancestors
|
|
91
|
+
browse snapshot --max-depth 4 # Trim output deeper than this depth
|
|
92
|
+
browse refs # Show refs cached from the last snapshot
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Element actions
|
|
96
|
+
|
|
97
|
+
Targets accept a snapshot ref (`@0-12`), an XPath, or a CSS selector.
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
browse click @0-12 # Click (also accepts selectors)
|
|
101
|
+
browse fill @0-8 "hello" # Fill an input (--press-enter to submit)
|
|
102
|
+
browse select @0-9 "CA" # Select an option (--value for <option value>)
|
|
103
|
+
browse type "hello world" # Type at the current focus (--delay, --mistakes)
|
|
104
|
+
browse press Enter # Press a key (alias: browse key) e.g. Meta+K, Escape
|
|
105
|
+
browse upload @0-4 ./resume.pdf # Upload file(s) (repeat --file for more)
|
|
106
|
+
browse highlight @0-12 # Highlight an element (--duration <ms>)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Mouse (raw coordinates)
|
|
110
|
+
|
|
111
|
+
Use these when you need pixel coordinates instead of a ref. Add `--return-xpath` to get the XPath under the cursor.
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
browse mouse click 240 320 # Click coordinates (--button, --click-count)
|
|
115
|
+
browse mouse hover 240 320 # Move the mouse
|
|
116
|
+
browse mouse scroll 400 500 0 600 # Scroll from a point by (dx, dy)
|
|
117
|
+
browse mouse drag 100 100 400 400 # Drag between two points (--steps, --delay)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Page info & state
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
browse get url # Read page data / element state:
|
|
124
|
+
browse get title # url, title, text, html, value, box,
|
|
125
|
+
browse get text @0-12 # visible, checked, markdown
|
|
126
|
+
browse get markdown body
|
|
127
|
+
browse get box 'button[type=submit]'
|
|
128
|
+
browse is visible @0-12 # Check element state: visible, checked
|
|
129
|
+
browse eval 'document.title' # Evaluate JavaScript in the page
|
|
130
|
+
browse viewport 1280 720 # Set viewport size (--scale for device pixel ratio)
|
|
131
|
+
browse cursor # Enable a visible cursor overlay
|
|
132
|
+
browse screenshot --path page.png # Screenshot (--full-page, --type, --quality, --clip)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Waiting
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
browse wait load # Wait for a load state
|
|
139
|
+
browse wait load networkidle --timeout 45000
|
|
140
|
+
browse wait selector @0-12 --state visible # visible|hidden|attached|detached
|
|
141
|
+
browse wait timeout 1000 # Wait a fixed number of ms
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Tabs
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
browse tab list # List tabs (with stable targetIds)
|
|
148
|
+
browse tab new [url] # Open a new tab and make it active
|
|
149
|
+
browse tab switch <target-id> # Switch active tab (index or targetId)
|
|
150
|
+
browse tab close [target-id] # Close a tab (defaults to the active tab)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Prefer the `targetId` from `browse tab list` over the index for stable agent workflows.
|
|
154
|
+
|
|
155
|
+
### Network capture
|
|
156
|
+
|
|
157
|
+
Capture request/response traffic for the active session to a local directory.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
browse network on # Start capturing
|
|
161
|
+
browse network off # Stop capturing
|
|
162
|
+
browse network path # Print the capture directory
|
|
163
|
+
browse network clear # Clear captured requests
|
|
164
|
+
```
|
|
70
165
|
|
|
71
166
|
> [!NOTE]
|
|
72
167
|
> `browse network on` writes request/response headers and bodies to a local owner-only capture directory. These files can include cookies, authorization headers, and other secrets — use network capture only on trusted machines and run `browse network clear` when done.
|
|
73
168
|
|
|
169
|
+
### Session & daemon
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
browse status # Show daemon status for a session
|
|
173
|
+
browse stop # Stop the daemon (--force to kill an unresponsive browser)
|
|
174
|
+
browse doctor # Diagnose session and browser-connection prerequisites
|
|
175
|
+
browse cdp 9222 # Attach to a CDP endpoint and stream DevTools events (--domain, --pretty)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Global flags
|
|
179
|
+
|
|
180
|
+
These apply across driver commands:
|
|
181
|
+
|
|
182
|
+
| Flag | Description |
|
|
183
|
+
|------|-------------|
|
|
184
|
+
| `-s, --session <name>` | Named browser session (or `BROWSE_SESSION` env var) |
|
|
185
|
+
| `--local` / `--remote` | Choose a managed local or remote Browserbase browser |
|
|
186
|
+
| `--headed` / `--headless` | Window visibility for managed local sessions |
|
|
187
|
+
| `--auto-connect` | Attach to a local Chrome with remote debugging enabled |
|
|
188
|
+
| `--cdp <url\|port>` | Attach directly to a CDP endpoint |
|
|
189
|
+
| `--target-id <id>` | Select a specific CDP target |
|
|
190
|
+
| `--json` | Emit machine-readable JSON (available on most commands) |
|
|
191
|
+
|
|
74
192
|
## Open web skills catalog
|
|
75
193
|
|
|
76
194
|
Use [browse.sh](https://browse.sh), the largest open-source catalog of skills to reliably perform any task on the internet. Find a specialized skill to navigate `apartments.com`, for example, and drastically reduce your agent's time and token costs.
|
|
@@ -78,6 +196,7 @@ Use [browse.sh](https://browse.sh), the largest open-source catalog of skills to
|
|
|
78
196
|
```bash
|
|
79
197
|
browse skills install # install the bundled browse CLI skill
|
|
80
198
|
browse skills list # list the public Browse.sh catalog
|
|
199
|
+
browse skills list --all # include every catalog entry
|
|
81
200
|
browse skills find reviews # search by slug, domain, title, tag…
|
|
82
201
|
browse skills find yelp.com/extract-reviews
|
|
83
202
|
browse skills add yelp.com/extract-reviews # install a catalog skill
|
|
@@ -86,23 +205,37 @@ browse skills add mcdonalds.order.online/order-delivery-42q71n
|
|
|
86
205
|
|
|
87
206
|
## Browserbase cloud commands
|
|
88
207
|
|
|
89
|
-
Manage projects, sessions, contexts, and extensions, or call the Fetch and Search APIs directly.
|
|
208
|
+
Manage projects, sessions, contexts, and extensions, or call the Fetch and Search APIs directly. These commands use `BROWSERBASE_API_KEY`.
|
|
90
209
|
|
|
91
210
|
```bash
|
|
211
|
+
# Projects
|
|
92
212
|
browse cloud projects list
|
|
93
213
|
browse cloud projects get <project-id>
|
|
94
214
|
browse cloud projects usage <project-id>
|
|
95
|
-
|
|
215
|
+
|
|
216
|
+
# Sessions
|
|
217
|
+
browse cloud sessions list # --limit, --status, --json
|
|
96
218
|
browse cloud sessions get <session-id>
|
|
97
|
-
browse cloud sessions create
|
|
98
|
-
browse cloud sessions
|
|
219
|
+
browse cloud sessions create # --proxies, --verified, --region, --solve-captchas…
|
|
220
|
+
browse cloud sessions update <session-id> --status REQUEST_RELEASE
|
|
221
|
+
browse cloud sessions debug <session-id> # live debugger URLs
|
|
99
222
|
browse cloud sessions logs <session-id>
|
|
100
|
-
browse cloud sessions downloads get <session-id>
|
|
101
|
-
browse cloud sessions uploads create <session-id>
|
|
223
|
+
browse cloud sessions downloads get <session-id> # --output ./downloads.zip
|
|
224
|
+
browse cloud sessions uploads create <session-id> ./file.pdf
|
|
225
|
+
|
|
226
|
+
# Contexts
|
|
102
227
|
browse cloud contexts create
|
|
103
228
|
browse cloud contexts get <context-id>
|
|
104
|
-
browse cloud
|
|
105
|
-
browse cloud
|
|
229
|
+
browse cloud contexts update <context-id> # refresh the upload URL
|
|
230
|
+
browse cloud contexts delete <context-id>
|
|
231
|
+
|
|
232
|
+
# Extensions
|
|
233
|
+
browse cloud extensions upload ./extension.zip
|
|
234
|
+
browse cloud extensions get <extension-id>
|
|
235
|
+
browse cloud extensions delete <extension-id>
|
|
236
|
+
|
|
237
|
+
# Fetch & Search APIs
|
|
238
|
+
browse cloud fetch <url> # markdown by default
|
|
106
239
|
browse cloud search <query>
|
|
107
240
|
```
|
|
108
241
|
|
|
@@ -113,14 +246,24 @@ browse cloud search <query>
|
|
|
113
246
|
Browserbase [Functions](https://docs.browserbase.com/platform/runtime/overview) let you deploy browser agents and automation scripts directly onto Browserbase's infrastructure. Build locally, test instantly, and deploy as APIs.
|
|
114
247
|
|
|
115
248
|
```bash
|
|
116
|
-
browse functions init my-function
|
|
117
|
-
browse functions dev index.ts
|
|
118
|
-
browse functions publish index.ts
|
|
119
|
-
browse functions publish index.ts --dry-run
|
|
249
|
+
browse functions init my-function # scaffold a new project (--package-manager)
|
|
250
|
+
browse functions dev index.ts # local development server (--port, --verbose)
|
|
251
|
+
browse functions publish index.ts # package and upload (--dry-run to preview)
|
|
120
252
|
browse functions invoke <function-id> --params '{"url":"https://example.com"}'
|
|
121
253
|
browse functions invoke --check-status <invocation-id>
|
|
122
254
|
```
|
|
123
255
|
|
|
256
|
+
## Templates
|
|
257
|
+
|
|
258
|
+
Discover and scaffold ready-to-run Browserbase example projects.
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
browse templates list # --tag, --source, --wide, --json
|
|
262
|
+
browse templates find amazon # search by slug, title, category, or tag
|
|
263
|
+
browse templates clone google-trends-keywords
|
|
264
|
+
browse templates clone amazon-product-scraping --language python ./my-scraper
|
|
265
|
+
```
|
|
266
|
+
|
|
124
267
|
## Configuration
|
|
125
268
|
|
|
126
269
|
Set your Browserbase API key to enable remote sessions and cloud commands:
|
|
@@ -131,12 +274,17 @@ export BROWSERBASE_API_KEY=bb_live_...
|
|
|
131
274
|
|
|
132
275
|
Local driver commands (`--local`) work without an API key.
|
|
133
276
|
|
|
277
|
+
| Variable | Description |
|
|
278
|
+
|----------|-------------|
|
|
279
|
+
| `BROWSERBASE_API_KEY` | Enables `--remote` sessions and all `browse cloud` / `functions` commands |
|
|
280
|
+
| `BROWSE_SESSION` | Default session name (alternative to `-s, --session`) |
|
|
281
|
+
|
|
134
282
|
## Links
|
|
135
283
|
|
|
136
284
|
- [browse.sh](https://browse.sh) — open web skills catalog
|
|
137
285
|
- [Browserbase docs](https://docs.browserbase.com)
|
|
138
|
-
- [GitHub](https://github.com/browserbase/cli) · [Issues](https://github.com/browserbase/
|
|
286
|
+
- [GitHub](https://github.com/browserbase/stagehand/tree/main/packages/cli) · [Issues](https://github.com/browserbase/stagehand/issues)
|
|
139
287
|
|
|
140
288
|
## License
|
|
141
289
|
|
|
142
|
-
[MIT](https://github.com/browserbase/
|
|
290
|
+
[MIT](https://github.com/browserbase/stagehand/blob/main/packages/cli/LICENSE)
|
package/dist/commands/click.js
CHANGED
|
@@ -4,7 +4,6 @@ import { driverCommandFlags, runDriverCommandFromFlags, } from "../lib/driver/co
|
|
|
4
4
|
export default class Click extends BrowseCommand {
|
|
5
5
|
static description = "Click an element by snapshot ref, XPath, or selector. Use `browse mouse click` for raw coordinates.";
|
|
6
6
|
static examples = [
|
|
7
|
-
"browse snapshot --compact",
|
|
8
7
|
"browse click @0-12",
|
|
9
8
|
"browse click 'button[type=submit]'",
|
|
10
9
|
"browse click @0-12 --session research",
|
|
@@ -4,7 +4,6 @@ export default class NetworkOn extends BrowseCommand {
|
|
|
4
4
|
static description = "Enable network capture for the active browser session.";
|
|
5
5
|
static examples = [
|
|
6
6
|
"browse network on",
|
|
7
|
-
"browse network path",
|
|
8
7
|
"browse network on --session research",
|
|
9
8
|
];
|
|
10
9
|
static flags = {
|
package/dist/lib/cloud/api.js
CHANGED
|
@@ -12,8 +12,11 @@ export function resolveApiKey(args) {
|
|
|
12
12
|
const apiKey = args.apiKey ?? process.env.BROWSERBASE_API_KEY;
|
|
13
13
|
return (apiKey ||
|
|
14
14
|
fail([
|
|
15
|
-
"Missing Browserbase API key.
|
|
16
|
-
|
|
15
|
+
"Missing Browserbase API key. Cloud commands (search, fetch, sessions, functions, ...) need one.",
|
|
16
|
+
"Set BROWSERBASE_API_KEY or pass --api-key.",
|
|
17
|
+
`Get a key at ${browserbaseSettingsUrl}.`,
|
|
18
|
+
"",
|
|
19
|
+
"No key? Local browser automation needs none. Try: browse open <url> --local",
|
|
17
20
|
].join("\n"), 1, {
|
|
18
21
|
resultCode: "missing_api_key",
|
|
19
22
|
requestHadHttpResponse: false,
|
|
@@ -6,6 +6,7 @@ import { isProcessAlive } from "./daemon/process.js";
|
|
|
6
6
|
import { discoverLocalCdp, } from "./local-cdp-discovery.js";
|
|
7
7
|
import { hasExplicitDriverTarget } from "./command-cli.js";
|
|
8
8
|
import { resolveConnectionTarget, targetsCompatible } from "./mode.js";
|
|
9
|
+
import { getRemote } from "./remote-binding.js";
|
|
9
10
|
const DEFAULT_URL = "https://example.com";
|
|
10
11
|
export async function buildDoctorReport(options, deps = {}) {
|
|
11
12
|
const checks = [];
|
|
@@ -176,18 +177,12 @@ async function checkTargetPrerequisite(target, flags, session, env, deps) {
|
|
|
176
177
|
};
|
|
177
178
|
}
|
|
178
179
|
if (target.kind === "remote") {
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
message: "BROWSERBASE_API_KEY is set",
|
|
182
|
-
name: "browserbase",
|
|
183
|
-
status: "ok",
|
|
184
|
-
};
|
|
185
|
-
}
|
|
180
|
+
const result = (await getRemote()).remoteDoctorCheck(env);
|
|
186
181
|
return {
|
|
187
|
-
fix:
|
|
188
|
-
message:
|
|
182
|
+
...(result.fix ? { fix: result.fix } : {}),
|
|
183
|
+
message: result.message,
|
|
189
184
|
name: "browserbase",
|
|
190
|
-
status: "fail",
|
|
185
|
+
status: result.ok ? "ok" : "fail",
|
|
191
186
|
};
|
|
192
187
|
}
|
|
193
188
|
if (target.kind === "auto-connect") {
|
package/dist/lib/driver/mode.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fail } from "../errors.js";
|
|
2
|
+
import { getRemote } from "./remote-binding.js";
|
|
2
3
|
import { resolveWsTarget } from "./resolve-ws.js";
|
|
3
4
|
function resolveHeadless(flags) {
|
|
4
5
|
if (flags.headed && flags.headless) {
|
|
@@ -45,17 +46,18 @@ export async function resolveConnectionTarget(flags) {
|
|
|
45
46
|
flags.headed ? "--headed" : null,
|
|
46
47
|
flags.headless ? "--headless" : null,
|
|
47
48
|
]);
|
|
48
|
-
return
|
|
49
|
+
return (await getRemote()).resolveExplicitRemoteTarget(flags);
|
|
49
50
|
}
|
|
50
51
|
if (flags.local) {
|
|
51
52
|
return { kind: "managed-local", headless: resolveHeadless(flags) };
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
+
const autoRemote = (await getRemote()).autoSelectRemoteTarget();
|
|
55
|
+
if (autoRemote) {
|
|
54
56
|
failOnConflictingFlags("remote mode", [
|
|
55
57
|
flags.headed ? "--headed" : null,
|
|
56
58
|
flags.headless ? "--headless" : null,
|
|
57
59
|
]);
|
|
58
|
-
return
|
|
60
|
+
return autoRemote;
|
|
59
61
|
}
|
|
60
62
|
return { kind: "managed-local", headless: resolveHeadless(flags) };
|
|
61
63
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
let cached;
|
|
2
|
+
/**
|
|
3
|
+
* Load the Browserbase capability. The full build ships `remote.js`; the
|
|
4
|
+
* local-only build omits it, so we fall back to `remote.disabled.js`. The full
|
|
5
|
+
* specifier is held in a variable so the local-only TypeScript program can
|
|
6
|
+
* exclude `remote.ts` without the compiler eagerly pulling it back in.
|
|
7
|
+
*/
|
|
8
|
+
export async function getRemote() {
|
|
9
|
+
if (cached)
|
|
10
|
+
return cached;
|
|
11
|
+
const fullModule = "./remote.js";
|
|
12
|
+
try {
|
|
13
|
+
cached = (await import(fullModule));
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
// The full build ships remote.js; the local-only build omits it. Only fall
|
|
17
|
+
// back to the disabled stub when the module is genuinely absent — rethrow
|
|
18
|
+
// any other error so a real failure inside remote.ts isn't masked as
|
|
19
|
+
// "remote disabled".
|
|
20
|
+
const code = error?.code;
|
|
21
|
+
if (code !== "ERR_MODULE_NOT_FOUND" && code !== "MODULE_NOT_FOUND") {
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
cached = (await import("./remote.disabled.js"));
|
|
25
|
+
}
|
|
26
|
+
return cached;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stub Browserbase capability used by `build:local-only`. It contains no API
|
|
3
|
+
* key handling and never reaches the cloud. Any attempt to use a remote target
|
|
4
|
+
* fails loudly.
|
|
5
|
+
*/
|
|
6
|
+
const DISABLED_MESSAGE = "Remote (Browserbase) mode is disabled in this local-only build of browse. Rebuild without local-only to use cloud sessions.";
|
|
7
|
+
export function resolveExplicitRemoteTarget() {
|
|
8
|
+
throw new Error(DISABLED_MESSAGE);
|
|
9
|
+
}
|
|
10
|
+
export function autoSelectRemoteTarget() {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
export function remoteStagehandOptions() {
|
|
14
|
+
throw new Error(DISABLED_MESSAGE);
|
|
15
|
+
}
|
|
16
|
+
export function remoteDoctorCheck() {
|
|
17
|
+
return { ok: true, message: "remote disabled (local-only build)" };
|
|
18
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Real Browserbase capability. This is the ONLY module that reads
|
|
3
|
+
* `BROWSERBASE_API_KEY`; it is excluded from `build:local-only` so that
|
|
4
|
+
* local-only artifacts cannot reach Browserbase.
|
|
5
|
+
*/
|
|
6
|
+
export function resolveExplicitRemoteTarget() {
|
|
7
|
+
return { kind: "remote" };
|
|
8
|
+
}
|
|
9
|
+
export function autoSelectRemoteTarget() {
|
|
10
|
+
return process.env.BROWSERBASE_API_KEY ? { kind: "remote" } : null;
|
|
11
|
+
}
|
|
12
|
+
export function remoteStagehandOptions() {
|
|
13
|
+
const apiKey = process.env.BROWSERBASE_API_KEY;
|
|
14
|
+
if (!apiKey) {
|
|
15
|
+
throw new Error("Missing BROWSERBASE_API_KEY for remote mode. Pass --local to run a managed local browser (no key needed), or set BROWSERBASE_API_KEY for cloud sessions.");
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
apiKey,
|
|
19
|
+
browserbaseSessionCreateParams: {
|
|
20
|
+
userMetadata: { browse_cli: "true" },
|
|
21
|
+
},
|
|
22
|
+
disableAPI: true,
|
|
23
|
+
disablePino: true,
|
|
24
|
+
env: "BROWSERBASE",
|
|
25
|
+
verbose: 0,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function remoteDoctorCheck(env) {
|
|
29
|
+
if (env.BROWSERBASE_API_KEY) {
|
|
30
|
+
return { ok: true, message: "BROWSERBASE_API_KEY is set" };
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
ok: false,
|
|
34
|
+
message: "BROWSERBASE_API_KEY is not set",
|
|
35
|
+
fix: "export BROWSERBASE_API_KEY=...",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -3,6 +3,7 @@ import { emptyRefMaps, resolveSelector as resolveCachedSelector, } from "./comma
|
|
|
3
3
|
import { executeDriverCommand } from "./commands/registry.js";
|
|
4
4
|
import { discoverLocalCdp } from "./local-cdp-discovery.js";
|
|
5
5
|
import { NetworkCapture } from "./network-capture.js";
|
|
6
|
+
import { getRemote } from "./remote-binding.js";
|
|
6
7
|
const INIT_FAILURE_RETRY_MS = 5_000;
|
|
7
8
|
export class DriverSessionManager {
|
|
8
9
|
session;
|
|
@@ -182,7 +183,7 @@ export class DriverSessionManager {
|
|
|
182
183
|
}
|
|
183
184
|
async initialize() {
|
|
184
185
|
const resolvedTarget = await this.resolveTarget();
|
|
185
|
-
const options = this.stagehandOptions(resolvedTarget);
|
|
186
|
+
const options = await this.stagehandOptions(resolvedTarget);
|
|
186
187
|
const stagehand = new Stagehand(options);
|
|
187
188
|
try {
|
|
188
189
|
await stagehand.init();
|
|
@@ -203,21 +204,9 @@ export class DriverSessionManager {
|
|
|
203
204
|
}
|
|
204
205
|
return { kind: "cdp", endpoint: discovered.wsUrl };
|
|
205
206
|
}
|
|
206
|
-
stagehandOptions(target) {
|
|
207
|
+
async stagehandOptions(target) {
|
|
207
208
|
if (target.kind === "remote") {
|
|
208
|
-
|
|
209
|
-
throw new Error("Missing BROWSERBASE_API_KEY. Set it or pass --local for a managed local browser.");
|
|
210
|
-
}
|
|
211
|
-
return {
|
|
212
|
-
apiKey: process.env.BROWSERBASE_API_KEY,
|
|
213
|
-
browserbaseSessionCreateParams: {
|
|
214
|
-
userMetadata: { browse_cli: "true" },
|
|
215
|
-
},
|
|
216
|
-
disableAPI: true,
|
|
217
|
-
disablePino: true,
|
|
218
|
-
env: "BROWSERBASE",
|
|
219
|
-
verbose: 0,
|
|
220
|
-
};
|
|
209
|
+
return (await getRemote()).remoteStagehandOptions();
|
|
221
210
|
}
|
|
222
211
|
if (target.kind === "managed-local") {
|
|
223
212
|
return {
|