browser-pilot-cli 0.1.6 → 0.2.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Browser Pilot contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -10,10 +10,25 @@ npm install -g browser-pilot-cli
10
10
 
11
11
  ### 1. Enable Chrome remote debugging (one-time)
12
12
 
13
- Open `chrome://inspect/#remote-debugging` in Chrome (144+) and click Allow. No command-line flags, no restart needed.
13
+ Open `chrome://inspect/#remote-debugging` in Chrome (144+) and enable remote
14
+ debugging. No command-line flags or restart are needed. Chrome may show its
15
+ separate Allow dialog when `bp connect` requests the actual connection.
14
16
 
15
17
  > Chrome 136 disabled the old `--remote-debugging-port` flag for security. Chrome 144 introduced this new UI toggle as the replacement — browser-pilot uses this.
16
18
 
19
+ Check every installed supported browser and its exact setup state with:
20
+
21
+ ```bash
22
+ bp browsers
23
+ ```
24
+
25
+ Discovery is passive: `bp browsers`, bridge startup, and `initialize` never open
26
+ a Chrome WebSocket and never display the Allow dialog.
27
+
28
+ Use `bp connect --browser <id|product|channel>` for an explicit choice. Product
29
+ embedders can pass the same selector to `browser-pilot bridge --stdio
30
+ --browser <selector>`; otherwise selection follows a stable platform order.
31
+
17
32
  ### 2. Install the plugin for your agent
18
33
 
19
34
  **Claude Code:**
@@ -53,7 +68,9 @@ The agent will use `bp` commands automatically. Your real login sessions are pre
53
68
  - **Real login sessions** — Operates your actual browser profile. Cookies, extensions, logins all intact
54
69
  - **CLI-native** — Any agent with bash access can use it. No MCP protocol, no SDK integration needed
55
70
  - **Auto-snapshot** — Every action returns page state with numbered `[ref]` elements, so the agent always knows what's on screen
56
- - **Lightweight** — 78KB npm package. No bundled Chromium (unlike Playwright's 400MB+)
71
+ - **Adaptive page views** — Bounded read, text search, DOM metadata, page geometry, and annotated screenshots let an agent choose the smallest useful representation
72
+ - **Verified page primitives** — Scroll and dropdown tools return fresh state and typed evidence instead of requiring ad hoc JavaScript
73
+ - **Lightweight npm install** — About 200KB as an npm tarball. No bundled Chromium (unlike Playwright's 400MB+)
57
74
  - **Rich editor support** — Works with contenteditable editors (Draft.js, ProseMirror, Quill, Slate) and Shadow DOM elements out of the box
58
75
 
59
76
  ## Comparison
@@ -67,7 +84,7 @@ The agent will use `bp` commands automatically. Your real login sessions are pre
67
84
  | **Auto-snapshot after action** | Yes | Yes | No | Yes |
68
85
  | **Network interception** | Yes (block/mock/headers) | Yes | Yes | No |
69
86
  | **Multi-browser** | Chromium-only | Chromium + Firefox + WebKit | Chromium-only | Chromium-only |
70
- | **Dialog auto-handling** | Yes | Yes | No | Yes |
87
+ | **Dialog handling** | Explicit | Automatic | Manual | Automatic |
71
88
  | **JSON output** | Default | MCP structured | MCP structured | Python objects |
72
89
  | **File upload** | Auto-detect input | Yes | No | Yes |
73
90
 
@@ -86,7 +103,100 @@ CLI Process ──── HTTP/Unix Socket ──── Daemon Process (persisten
86
103
  └── Pilot window (agent operates here)
87
104
  ```
88
105
 
89
- The daemon maintains a single CDP WebSocket connection. A pulsing blue glow around the Pilot window indicates the agent is active.
106
+ The Broker maintains isolated state for each Agent. A private connection
107
+ supervisor owns the Broker's single browser-level CDP WebSocket and proxies it
108
+ to the daemon. It also owns only Browser Pilot-created tabs so it can clean them
109
+ after a Broker crash without touching user-opened tabs. A pulsing blue glow
110
+ around a Pilot window indicates Agent activity.
111
+
112
+ ## Platform Evolution
113
+
114
+ Browser Pilot now routes direct `bp` commands and embedded clients through the
115
+ same Agent-neutral, multi-client Browser Broker.
116
+ The approved architecture and execution plans are:
117
+
118
+ - [Platform specification](docs/architecture/browser-pilot-platform-spec.md)
119
+ - [Universal Agent integration plan](docs/plans/universal-agent-integration.md)
120
+ - [Browser capability and reliability plan](docs/plans/browser-capability-evolution.md)
121
+ - [Stdio bridge integration contract](docs/integration/stdio-bridge.md)
122
+ - [Stdio black-box conformance suite](docs/integration/stdio-conformance.md)
123
+ - [Reference consumer adapters](https://github.com/relixiaobo/browser-pilot/tree/main/examples/adapters),
124
+ including Tenon and OpenClaw lifecycle mappings
125
+
126
+ The public integration direction remains CLI-only: one-shot commands for direct
127
+ Agent use and a persistent `bridge --stdio` mode for products that embed the
128
+ official executable. Browser Pilot will not require an extension, Native SDK,
129
+ or MCP server. The repository's consumer adapters are source examples built
130
+ only on the stdio contract; they are intentionally excluded from the npm
131
+ package and do not create a second public library API.
132
+
133
+ The dedicated Pilot window remains the default managed tab set for independent
134
+ Agent work. The Broker architecture also includes all eligible user tabs in the
135
+ Agent's inventory without a separate grant step, so an Agent can operate a page
136
+ the user already opened. Invoking or exposing the tool is the authorization
137
+ boundary; products may apply their own approval UX or remove operations when
138
+ launching the bridge. Bulk cleanup remains limited to managed tabs, and user
139
+ tabs remain open when a session ends.
140
+
141
+ The `browser-pilot bridge --stdio` transport, Broker lifecycle, browser tool
142
+ dispatch, event replay, protected Artifacts, and protocol 1.1 transport limit
143
+ negotiation are implemented. Browser disconnect and explicit reconnect handling, scoped
144
+ download Artifacts, Workspace resource isolation, and typed watchdog events for
145
+ stalled navigation, selected-frame detach, pending dialogs, and repeated
146
+ browser-observable no-progress actions are also implemented. Bounded page
147
+ search, DOM metadata lookup, scrolling, native/ARIA dropdown operations,
148
+ Observation page geometry, and viewport screenshot annotations adapt the most
149
+ useful browser-use inspection patterns to the same scoped Broker contract. An
150
+ internal managed-target janitor is the sole owner of the browser-level CDP
151
+ connection, proxies daemon traffic over private IPC, and closes only
152
+ Broker-created tabs and their managed popup descendants if the daemon exits or
153
+ crashes. It does not persist target IDs or close user tabs. Broker startup and
154
+ browser discovery are passive. Only `bp connect` or the versioned
155
+ `browser.connect` tool requests Chrome authorization; concurrent clients share
156
+ one in-flight request, and a failed or dropped connection is never retried by a
157
+ timer.
158
+ Compatible Agent products reuse one per-user Broker through protocol
159
+ negotiation. Protected shutdown cannot terminate live embedded clients, and an
160
+ incompatible product must explicitly select a separate `BROWSER_PILOT_HOME`.
161
+ Global npm installation, local npm/npx use, and product-bundled absolute-path
162
+ launches are covered by distribution black-box tests. Native self-contained
163
+ release artifacts use one executable for the public CLI and its private Broker
164
+ and janitor roles, with no runtime download or system-Node fallback.
165
+
166
+ ## Installation and Embedding
167
+
168
+ Agent-managed installation remains supported:
169
+
170
+ ```bash
171
+ npm install -g browser-pilot-cli
172
+ bp connect
173
+ bp tabs
174
+ ```
175
+
176
+ A project can pin Browser Pilot locally and run the same CLI without a global
177
+ installation:
178
+
179
+ ```bash
180
+ npm install --save-exact browser-pilot-cli@0.2.1
181
+ npx --no-install browser-pilot tabs
182
+ ```
183
+
184
+ Agent products should pin either the npm package or a native archive from the
185
+ GitHub release. Launch an absolute path directly with `bridge --stdio`; do not
186
+ invoke a shell, import `src/*`, or depend on Broker locator/socket files. The
187
+ npm form launches `node_modules/browser-pilot-cli/dist/cli.js` with the
188
+ product's pinned Node runtime. The native archive launches its single
189
+ `browser-pilot` executable and does not require Node to be installed.
190
+
191
+ Each native archive contains `manifest.json`, per-file `SHA256SUMS`, licenses,
192
+ and an adjacent archive checksum. The manifest reports the actual signature
193
+ kind: Developer ID or ad-hoc on macOS, Authenticode or unsigned on Windows, and
194
+ unsigned on Linux. Release automation never labels an artifact signed when its
195
+ signing credentials were unavailable.
196
+
197
+ All three forms use the same protocol and compatible per-user Broker. Use a
198
+ distinct absolute `BROWSER_PILOT_HOME` only when a product deliberately needs
199
+ an incompatible isolated Broker.
90
200
 
91
201
  ## Commands
92
202
 
@@ -96,8 +206,15 @@ The daemon maintains a single CDP WebSocket connection. A pulsing blue glow arou
96
206
  |---------|---------|-------------|
97
207
  | `bp open <url>` | snapshot | Navigate to URL |
98
208
  | `bp snapshot` | snapshot | Get interactive elements |
209
+ | `bp read [selector]` | text | Get bounded readable page/region content |
210
+ | `bp search <text>` | matches | Find bounded visible text and nearby context |
211
+ | `bp find <selector>` | elements | Inspect bounded DOM metadata and requested attributes |
212
+ | `bp scroll [direction]` | snapshot | Scroll page/element/text and return fresh state |
213
+ | `bp dropdown <target>` | options | List native or exposed ARIA dropdown options |
214
+ | `bp select <target> <option>` | snapshot | Select and verify a dropdown option |
99
215
  | `bp click <ref>` | snapshot | Click element by ref number (`--double`, `--right`) |
100
- | `bp click 0 --xy x,y` | snapshot | Click at viewport coordinates (canvas, maps) |
216
+ | `bp click --xy x,y` | snapshot | Click at viewport coordinates (canvas, maps) |
217
+ | `bp locate <selector>` | coords | Get element center x,y + size (for `click --xy`) |
101
218
  | `bp type <ref> <text>` | snapshot | Type into element (`--clear`, `--submit`) |
102
219
  | `bp keyboard <text>` | snapshot | Type via keyboard events (`--click`, `--clear`) |
103
220
  | `bp press <key>` | snapshot | Press key (Enter, Escape, Control+a, Meta+c) |
@@ -107,7 +224,7 @@ The daemon maintains a single CDP WebSocket connection. A pulsing blue glow arou
107
224
 
108
225
  | Command | Description |
109
226
  |---------|-------------|
110
- | `bp screenshot [file]` | Capture screenshot (`--full`, `--selector`) |
227
+ | `bp screenshot [file]` | Capture screenshot (`--full`, `--selector`, `--annotate [refs]`) |
111
228
  | `bp pdf [file]` | Save page as PDF (`--landscape`) |
112
229
  | `bp cookies [domain]` | View cookies (includes HttpOnly) |
113
230
 
@@ -118,10 +235,16 @@ The daemon maintains a single CDP WebSocket connection. A pulsing blue glow arou
118
235
  | `bp upload <filepath>` | Upload file (auto-finds `<input type="file">`) |
119
236
  | `bp auth <user> <pass>` | Set HTTP Basic Auth credentials (`--clear`) |
120
237
  | `bp frame [index]` | List or switch iframe context (0 = top) |
238
+ | `bp dialogs` | List pending JavaScript dialogs |
239
+ | `bp dialog <id> --accept\|--dismiss` | Explicitly respond to a dialog (`--prompt`) |
121
240
 
122
- Dialogs (`alert`/`confirm`/`prompt`) are auto-handled by the daemon.
241
+ Dialogs remain pending until explicitly accepted or dismissed. One-shot CLI
242
+ dialogs are scoped to the compatibility Workspace and isolated from embedded
243
+ Broker clients.
123
244
 
124
- Popup windows (target="_blank", window.open) are auto-detected. Run `bp tabs` to see and switch to them.
245
+ Run `bp tabs` to list Pilot-managed tabs, their popups, and eligible tabs the
246
+ user opened elsewhere in the same browser. `bp tab <n>` switches control to any
247
+ listed tab.
125
248
 
126
249
  ### Network
127
250
 
@@ -141,10 +264,10 @@ Popup windows (target="_blank", window.open) are auto-detected. Run `bp tabs` to
141
264
  | Command | Description |
142
265
  |---------|-------------|
143
266
  | `bp connect` | Connect to Chrome, create pilot window |
144
- | `bp disconnect` | Close pilot window, stop daemon |
145
- | `bp tabs` | List pilot tabs (auto-adopts popups) |
146
- | `bp tab <n>` | Switch tab |
147
- | `bp close` | Close current tab (`--all`) |
267
+ | `bp disconnect` | Close the CLI Pilot window; stop the daemon when no embedded client is live |
268
+ | `bp tabs` | List all controllable tabs in the current browser |
269
+ | `bp tab <n>` | Switch to any listed managed or user tab |
270
+ | `bp close` | Close the current tab (`--all` closes Pilot-managed tabs only) |
148
271
 
149
272
  ## Refs
150
273
 
@@ -163,14 +286,22 @@ Action commands return a snapshot of interactive elements, each with a `[ref]` n
163
286
 
164
287
  Use the number in subsequent commands: `bp click 1`, `bp type 2 "hello"`.
165
288
 
166
- Refs are scoped to the current page — they refresh automatically after every action. Elements inside Shadow DOM are included automatically.
289
+ Refs are scoped to the current page — they refresh automatically after every
290
+ action. Elements inside Shadow DOM are included automatically. Snapshot JSON
291
+ may also include a `page` block with viewport/document size, scroll position,
292
+ remaining pixels, and scroll percentages.
293
+
294
+ Across one-shot CLI processes, active target, frame, and refs live only in the
295
+ daemon's keyed compatibility Workspace and renewable Lease. They are never
296
+ written to `state.json` or `refs.json`; after Lease expiry the Agent must
297
+ observe again. `bp disconnect` explicitly clears the compatibility Workspace.
167
298
 
168
299
  ## Output
169
300
 
170
301
  **JSON by default** when piped (for LLM/script consumption). Human-readable when run in a terminal.
171
302
 
172
303
  ```json
173
- {"ok":true, "title":"Example", "url":"https://example.com", "elements":[{"ref":1, "role":"link", "name":"More info"}]}
304
+ {"ok":true,"title":"Example","url":"https://example.com","page":{"viewportWidth":1280,"viewportHeight":720,"documentWidth":1280,"documentHeight":1800,"scrollX":0,"scrollY":0,"pixelsAbove":0,"pixelsBelow":1080,"pixelsLeft":0,"pixelsRight":0,"scrollPercentX":0,"scrollPercentY":0},"elements":[{"ref":1,"role":"link","name":"More info"}]}
174
305
  ```
175
306
 
176
307
  Errors include hints:
@@ -180,6 +311,18 @@ Errors include hints:
180
311
 
181
312
  Force human output: `bp --human open https://example.com`
182
313
 
314
+ `bp screenshot [file]`, `bp pdf [file]`, and `bp net show <id> --save <file>`
315
+ return an absolute local path. Screenshot and PDF bytes are first protected
316
+ Artifacts, explicitly exported to that path, then released from Broker storage.
317
+ `bp upload <file>` similarly imports a protected copy and releases it after the
318
+ browser receives the file; the source file is never removed.
319
+
320
+ After `bp snapshot`, `bp screenshot page.png --annotate` draws up to the first
321
+ 200 current refs on a viewport image; pass a comma-separated list such as
322
+ `--annotate 1,3,8` to limit it. Annotation does not inject elements into the
323
+ page, runs in an isolated JavaScript world, and cannot be combined with full-page
324
+ or selector capture.
325
+
183
326
  ## Eval
184
327
 
185
328
  `eval` is the escape hatch — anything JavaScript can do:
@@ -188,13 +331,16 @@ Force human output: `bp --human open https://example.com`
188
331
  bp eval "history.back()" # go back
189
332
  bp eval "history.forward()" # go forward
190
333
  bp eval "location.reload()" # reload
191
- bp eval "window.scrollBy(0, 500)" # scroll down
192
334
  bp eval "document.querySelector('h1').textContent" # extract text
193
335
  bp eval "document.querySelector('div').innerHTML" # extract HTML
194
336
  bp eval "JSON.stringify(localStorage)" # read storage
195
337
  echo 'complex js here' | bp eval # stdin for complex JS
196
338
  ```
197
339
 
340
+ Prefer `bp read`, `bp search`, `bp find`, `bp scroll`, `bp dropdown`, and
341
+ `bp select` for their bounded output, scoped state, and verification. Use
342
+ `eval` only when no dedicated command represents the operation.
343
+
198
344
  ## File Upload
199
345
 
200
346
  `bp upload` auto-detects `<input type="file">` on the page:
@@ -219,7 +365,7 @@ For canvas-based editors (Google Docs, Google Sheets, Figma), use `bp keyboard`
219
365
  bp keyboard "Hello Docs!" --click ".kix-appview-editor" # Google Docs
220
366
  bp press Meta+b # toggle bold
221
367
  bp keyboard "bold text"
222
- bp click 0 --xy 400,300 # click canvas area
368
+ bp click --xy 400,300 # click canvas area
223
369
  ```
224
370
 
225
371
  Shadow DOM elements are traversed automatically — no special commands needed. Elements inside open shadow roots (even deeply nested) appear in snapshots and can be clicked/typed normally.
@@ -253,27 +399,47 @@ bp net headers "*api*" "Authorization:Bearer test123"
253
399
 
254
400
  # Manage rules
255
401
  bp net rules # list active rules
256
- bp net remove 2 # remove rule #2
402
+ bp net remove <id-from-bp-net-rules> # rule IDs are opaque
257
403
  bp net remove --all # clear all rules
258
404
  bp net clear # clear captured request log
259
405
  ```
260
406
 
261
407
  ## Testing
262
408
 
263
- 121 tests across 4 Playwright projects, adapted from Playwright/Puppeteer test fixtures and real-world sites:
409
+ Local release tests are deterministic. Real-site checks run separately as
410
+ non-blocking canaries so a third-party outage cannot fail the release gate:
411
+
412
+ ```bash
413
+ npm test # unit + local core, compat, and network gates
414
+ npm run test:capabilities # isolated-Chrome quantitative capability gate
415
+ npm run test:distribution # packed global/local/product-bundled launch modes
416
+ npm run test:canary # real-site drift report; non-blocking
417
+ npm run test:canary:strict # fail on drift or unavailability
418
+ npm run test:integration # compatibility alias for strict canaries
419
+ npm run test:all # release gates plus non-blocking canaries
420
+ ```
421
+
422
+ Automated browser gates, including Playwright and stdio conformance, start their
423
+ own headless Chrome with a temporary profile, random debugging port, and
424
+ isolated Broker home. Teardown stops the Broker and Chrome and removes those
425
+ files. Tests fail closed if that isolation is absent; they never attach to the
426
+ user's Chrome by default. A maintainer can explicitly opt into a destructive
427
+ manual compatibility run against the user's browser by setting
428
+ `BROWSER_PILOT_TEST_USER_CHROME=1`.
429
+
430
+ Maintainers can build and verify a native artifact with an official,
431
+ SEA-capable Node 22.17.0 runtime:
264
432
 
265
433
  ```bash
266
- npm test # core + compat + network (105 tests, ~2min)
267
- npm run test:integration # real-site tests against the-internet.herokuapp.com
268
- npm run test:all # all 121 tests
434
+ BROWSER_PILOT_SEA_NODE=/absolute/path/to/node npm run build:standalone
435
+ npm run verify:standalone
436
+ npm run package:standalone
269
437
  ```
270
438
 
271
- | Project | Tests | Coverage |
272
- |---------|-------|----------|
273
- | **core** | 41 | lifecycle, nav, click, type, press, eval, screenshot, pdf, cookies, frames, upload, auth, tabs, dialogs |
274
- | **compat** | 46 | contenteditable (5 variants), Shadow DOM (3 levels), input types, scrollable, overlay, select |
275
- | **network** | 19 | request monitoring, block, mock, headers, rule management |
276
- | **integration** | 15 | checkboxes, dropdown, key presses, dynamic controls, Shadow DOM, nested frames, TinyMCE, large DOM |
439
+ The canary report is written to
440
+ `test-results/real-site-canary/report.json`. It distinguishes semantic drift,
441
+ third-party unavailability, and runner errors. Set
442
+ `BROWSER_PILOT_CANARY_REPORT` to use another report path.
277
443
 
278
444
  ## Requirements
279
445