browse 0.8.1 → 0.8.2-alpha-e7d3b55

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Browserbase, Inc.
3
+ Copyright (c) 2024 Browserbase Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,19 +1,49 @@
1
- # Browse CLI
1
+ <div align="center">
2
2
 
3
- > Single CLI your AI agents need to access the internet reliably.
3
+ # >_ browse
4
+
5
+ ### The single CLI your AI agents need to access the internet reliably.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/browse.svg?style=flat-square&color=000000)](https://www.npmjs.com/package/browse)
8
+ [![npm downloads](https://img.shields.io/npm/dm/browse.svg?style=flat-square&color=000000)](https://www.npmjs.com/package/browse)
9
+ [![license](https://img.shields.io/npm/l/browse.svg?style=flat-square&color=000000)](https://github.com/browserbase/stagehand/blob/main/packages/cli/LICENSE)
4
10
 
5
11
  ```bash
6
12
  npm install -g browse
7
13
  ```
8
14
 
9
- ## Main features:
10
- 1. **Browser interactions** — Navigate tricky and complex websites with `browse click`, `browse mouse scroll`, `browse type`, `browse select`, and 20+ more DOM manipulation commands.
11
- 2. **Web skills catalog** — `browse` is the official CLI for [browse.sh](https://browse.sh), the largest open web catalog. Your agent can run `browse skills add apartments.com` to learn how to use that website and APIs.
12
- 3. **Rich debugging** — Arm your agents with network, console, and other web telemetry.
13
- 4. **Cloud features** — Optionally use Browserbase cloud features, such as loading cookies via saved [Contexts](https://docs.browserbase.com/platform/browser/core-features/contexts), using [Verified Browsers](https://www.browserbase.com/verified), and the [Fetch and Search APIs](https://www.browserbase.com/search).
15
+ <img src="https://github.com/browserbase/stagehand/blob/main/packages/cli/media/browse.gif?raw=true" alt="browse CLI demo" width="100%" />
16
+
17
+ </div>
18
+
19
+ ---
20
+
21
+ `browse` gives any agent — or any terminal — a reliable way to drive a real browser, learn how to use specific websites, and tap into Browserbase's cloud. One command to navigate the open web, capture telemetry while you do it, and reuse skills the community has already built.
22
+
23
+ ## Why browse
24
+
25
+ - **Browser interactions** — Navigate tricky, complex websites with `browse click`, `browse mouse scroll`, `browse type`, `browse select`, and 20+ more DOM commands.
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
+ - **Rich debugging** — Arm your agents with network, console, and other web telemetry.
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).
29
+
30
+ ## Quick start
31
+
32
+ ```bash
33
+ npm install -g browse
34
+
35
+ browse open https://example.com
36
+ browse snapshot --compact
37
+ browse click @0-12
38
+ browse fill @0-8 "hello"
39
+ browse get title
40
+ browse screenshot --path page.png
41
+ browse stop
42
+ ```
14
43
 
44
+ ## Driver commands
15
45
 
16
- ## Driver Commands
46
+ Drive a real browser from the terminal — locally, over CDP, or on a remote Browserbase session.
17
47
 
18
48
  ```bash
19
49
  browse open https://example.com
@@ -38,61 +68,49 @@ browse stop
38
68
 
39
69
  Use `--local`, `--remote`, `--auto-connect`, or `--cdp <url|port>` per command to choose the browser target. Use `--target-id <id>` with `--cdp` when attaching to a specific CDP target. Driver commands use `BROWSERBASE_API_KEY` for remote Browserbase sessions.
40
70
 
41
- [!NOTE]
42
- Security note: `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, so use network capture only on trusted machines and run `browse network clear` when done.
71
+ > [!NOTE]
72
+ > `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.
43
73
 
44
- ## Open Web Skills Catalog
45
-
46
- Your CLI can directly use [browse.sh](https://browse.sh), the largest open-source catalog of skills to reliably perform any task on the internet. For example, find a specialized skill to navigate `apartments.com` and reduce your agent time and token costs drastically.
74
+ ## Open web skills catalog
47
75
 
76
+ 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.
48
77
 
49
78
  ```bash
50
- browse skills install
51
- browse skills list
52
- browse skills find reviews
79
+ browse skills install # install the bundled browse CLI skill
80
+ browse skills list # list the public Browse.sh catalog
81
+ browse skills find reviews # search by slug, domain, title, tag…
53
82
  browse skills find yelp.com/extract-reviews
54
- browse skills add yelp.com/extract-reviews
83
+ browse skills add yelp.com/extract-reviews # install a catalog skill
55
84
  browse skills add mcdonalds.order.online/order-delivery-42q71n
56
85
  ```
57
86
 
58
- `browse skills install` installs the bundled `browse` CLI skill from this package.
59
- `browse skills list` lists the public Browse.sh skill catalog.
60
- `browse skills find` searches the public Browse.sh skill catalog by slug, domain, title, description, category, alias, or tag.
61
- `browse skills add` installs catalog skills from `browserbase/browse.sh` or generated skills from Browserbase-hosted public storage.
87
+ ## Browserbase cloud commands
62
88
 
63
- ## Browserbase Cloud Commands
89
+ Manage projects, sessions, contexts, and extensions, or call the Fetch and Search APIs directly.
64
90
 
65
91
  ```bash
66
- browse --help
67
- browse cloud --help
68
92
  browse cloud projects list
69
93
  browse cloud projects get <project-id>
70
94
  browse cloud projects usage <project-id>
71
95
  browse cloud sessions list
72
96
  browse cloud sessions get <session-id>
73
97
  browse cloud sessions create
74
- browse cloud sessions update <session-id>
75
98
  browse cloud sessions debug <session-id>
76
99
  browse cloud sessions logs <session-id>
77
100
  browse cloud sessions downloads get <session-id>
78
101
  browse cloud sessions uploads create <session-id> <file>
79
102
  browse cloud contexts create
80
103
  browse cloud contexts get <context-id>
81
- browse cloud contexts update <context-id>
82
- browse cloud contexts delete <context-id>
83
104
  browse cloud extensions upload <file>
84
- browse cloud extensions get <extension-id>
85
- browse cloud extensions delete <extension-id>
86
105
  browse cloud fetch <url>
87
106
  browse cloud search <query>
88
107
  ```
89
108
 
90
- `browse cloud fetch` requests markdown-formatted page content by default. Use `--format raw` for the original response body, or `--format json --schema <schema>` for structured extraction.
91
-
92
- ## Functions Commands
109
+ `browse cloud fetch` returns markdown-formatted page content by default. Use `--format raw` for the original response body, or `--format json --schema <schema>` for structured extraction.
93
110
 
94
- Browserbase [Functions](https://docs.browserbase.com/platform/runtime/overview) let you deploy browser agents or automation scripts directly onto Browserbase’s infrastructure. Start in your local environment, configure agents or write browser scripts, test them instantly, and deploy directly as cloud functions invokable as APIs.
111
+ ## Functions
95
112
 
113
+ 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.
96
114
 
97
115
  ```bash
98
116
  browse functions init my-function
@@ -102,3 +120,23 @@ browse functions publish index.ts --dry-run
102
120
  browse functions invoke <function-id> --params '{"url":"https://example.com"}'
103
121
  browse functions invoke --check-status <invocation-id>
104
122
  ```
123
+
124
+ ## Configuration
125
+
126
+ Set your Browserbase API key to enable remote sessions and cloud commands:
127
+
128
+ ```bash
129
+ export BROWSERBASE_API_KEY=bb_live_...
130
+ ```
131
+
132
+ Local driver commands (`--local`) work without an API key.
133
+
134
+ ## Links
135
+
136
+ - [browse.sh](https://browse.sh) — open web skills catalog
137
+ - [Browserbase docs](https://docs.browserbase.com)
138
+ - [GitHub](https://github.com/browserbase/stagehand/tree/main/packages/cli) · [Issues](https://github.com/browserbase/stagehand/issues)
139
+
140
+ ## License
141
+
142
+ [MIT](https://github.com/browserbase/stagehand/blob/main/packages/cli/LICENSE)
@@ -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 = {
@@ -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. Set BROWSERBASE_API_KEY or pass --api-key.",
16
- `You can find your API key at ${browserbaseSettingsUrl}.`,
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
- if (env.BROWSERBASE_API_KEY) {
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: "export BROWSERBASE_API_KEY=...",
188
- message: "BROWSERBASE_API_KEY is not set",
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") {
@@ -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 { kind: "remote" };
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
- if (process.env.BROWSERBASE_API_KEY) {
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 { kind: "remote" };
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
- if (!process.env.BROWSERBASE_API_KEY) {
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 {