browser-pilot-cli 0.1.0

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 ADDED
@@ -0,0 +1,231 @@
1
+ # browser-pilot
2
+
3
+ CLI tool that gives LLM agents control of your real browser — with your logins, cookies, and extensions intact.
4
+
5
+ ```bash
6
+ bp open https://github.com # navigate — returns interactive elements
7
+ bp click 3 # click [3] — returns updated page
8
+ bp type 5 "hello" --submit # type + Enter — returns updated page
9
+ bp eval "document.title" # run any JavaScript
10
+ ```
11
+
12
+ ## Comparison
13
+
14
+ | | browser-pilot | Playwright MCP | Chrome DevTools MCP | browser-use |
15
+ |---|---|---|---|---|
16
+ | **Interface** | CLI (bash) | MCP protocol | MCP protocol | Python SDK |
17
+ | **Login session reuse** | Yes | No | Depends | Yes |
18
+ | **Element refs** | Numbered (accessibility tree) | Named refs (ARIA) | CSS selectors | Numbered (DOM) |
19
+ | **Auto-snapshot after action** | Yes | Yes | No | Yes |
20
+ | **Network interception** | Yes (block/mock/headers) | Yes | Yes | No |
21
+ | **Drag and drop** | No | Yes | Yes | No |
22
+ | **Mobile emulation** | No | Yes | Yes | Yes |
23
+ | **Multi-browser** | Chromium-only | Chromium + Firefox + WebKit | Chromium-only | Chromium-only |
24
+ | **Connection model** | Daemon (one-time Allow) | MCP server | MCP server | Python process |
25
+ | **Dialog auto-handling** | Yes | Yes | No | Yes |
26
+ | **JSON output** | Default | MCP structured | MCP structured | Python objects |
27
+ | **Visual indicator** | Pulsing glow | None | None | None |
28
+ | **File upload** | Auto-detect input | Yes | No | Yes |
29
+ | **Autonomous agent** | No (tool, not agent) | No (tool) | No (tool) | Yes (plans + executes) |
30
+
31
+ **browser-pilot is best when:**
32
+ - You need your existing login sessions (paywalled content, internal tools)
33
+ - Your LLM has bash access but no MCP support
34
+ - You want every action to return page state automatically
35
+
36
+ **Use Playwright MCP when:**
37
+ - You need multi-browser or mobile emulation
38
+ - Your LLM supports MCP natively
39
+ - You don't need existing login sessions
40
+
41
+ **Use browser-use when:**
42
+ - You want an autonomous agent that plans and executes multi-step tasks
43
+ - You're building in Python
44
+
45
+ ## Quick Start
46
+
47
+ ```bash
48
+ # Install
49
+ npm install -g browser-pilot
50
+
51
+ # Enable debugging in Chrome (one-time)
52
+ # Open chrome://inspect/#remote-debugging → toggle ON
53
+
54
+ # Connect (click Allow in Chrome's dialog)
55
+ bp connect
56
+
57
+ # Use
58
+ bp open https://github.com
59
+ bp click 3
60
+ bp type 5 "hello" --submit
61
+ bp eval "document.title"
62
+ bp screenshot page.png
63
+ bp disconnect
64
+ ```
65
+
66
+ ## How It Works
67
+
68
+ ```
69
+ LLM (bash tool)
70
+ │ bp open / bp click / bp eval ...
71
+
72
+ CLI Process ──── HTTP/Unix Socket ──── Daemon Process (persistent)
73
+
74
+ │ WebSocket (CDP, one-time Allow)
75
+
76
+ Chrome (your browser, your profile)
77
+ ├── Your windows (untouched)
78
+ └── Pilot window (bp operates here)
79
+ ```
80
+
81
+ The daemon maintains a single CDP WebSocket connection. Chrome's "Allow" dialog appears once per session. A pulsing blue glow around the Pilot window indicates the agent is active.
82
+
83
+ ## Commands
84
+
85
+ Run `bp --help` for full details including workflow, refs, and eval examples.
86
+
87
+ ### Core Loop
88
+
89
+ | Command | Returns | Description |
90
+ |---------|---------|-------------|
91
+ | `bp open <url>` | snapshot | Navigate to URL |
92
+ | `bp snapshot` | snapshot | Get interactive elements |
93
+ | `bp click <ref>` | snapshot | Click element by ref number |
94
+ | `bp type <ref> <text>` | snapshot | Type into element (`--clear`, `--submit`) |
95
+ | `bp press <key>` | snapshot | Press key (Enter, Escape, Control+a, Meta+c) |
96
+ | `bp eval [js]` | value | Run JavaScript (escape hatch for anything) |
97
+
98
+ ### Utilities
99
+
100
+ | Command | Description |
101
+ |---------|-------------|
102
+ | `bp screenshot [file]` | Capture screenshot (`--full`, `--selector`) |
103
+ | `bp pdf [file]` | Save page as PDF (`--landscape`) |
104
+ | `bp cookies [domain]` | View cookies (includes HttpOnly) |
105
+
106
+ ### Edge Cases
107
+
108
+ | Command | Description |
109
+ |---------|-------------|
110
+ | `bp upload <filepath>` | Upload file (auto-finds `<input type="file">`) |
111
+ | `bp auth <user> <pass>` | Set HTTP Basic Auth credentials (`--clear`) |
112
+ | `bp frame [index]` | List or switch iframe context (0 = top) |
113
+
114
+ Dialogs (`alert`/`confirm`/`prompt`) are auto-handled by the daemon.
115
+
116
+ Popup windows (target="_blank", window.open) are auto-detected. Run `bp tabs` to see and switch to them.
117
+
118
+ ### Network
119
+
120
+ | Command | Description |
121
+ |---------|-------------|
122
+ | `bp net` | List recent requests (`--url`, `--method`, `--status`, `--type`) |
123
+ | `bp net show <id>` | Full request/response details (`--save <file>`) |
124
+ | `bp net block <pattern>` | Block requests matching URL pattern |
125
+ | `bp net mock <pattern>` | Mock responses (`--body`, `--file`, `--status`) |
126
+ | `bp net headers <pattern> <header...>` | Add/override request headers |
127
+ | `bp net rules` | List active interception rules |
128
+ | `bp net remove [id]` | Remove rule(s) (`--all`) |
129
+ | `bp net clear` | Clear captured request log |
130
+
131
+ ### Session
132
+
133
+ | Command | Description |
134
+ |---------|-------------|
135
+ | `bp connect` | Connect to Chrome, create pilot window |
136
+ | `bp disconnect` | Close pilot window, stop daemon |
137
+ | `bp tabs` | List pilot tabs (auto-adopts popups) |
138
+ | `bp tab <n>` | Switch tab |
139
+ | `bp close` | Close current tab (`--all`) |
140
+
141
+ ## Refs
142
+
143
+ Action commands return a snapshot of interactive elements, each with a `[ref]` number:
144
+
145
+ ```
146
+ [1] link "Home"
147
+ [2] textbox "Search"
148
+ [3] button "Submit"
149
+ ```
150
+
151
+ Use the number in subsequent commands: `bp click 1`, `bp type 2 "hello"`.
152
+
153
+ Refs are scoped to the current page — they refresh automatically after every action.
154
+
155
+ ## Output
156
+
157
+ **JSON by default** when piped (for LLM/script consumption). Human-readable when run in a terminal.
158
+
159
+ ```json
160
+ {"ok":true, "title":"Example", "url":"https://example.com", "elements":[{"ref":1, "role":"link", "name":"More info"}]}
161
+ ```
162
+
163
+ Errors include hints:
164
+ ```json
165
+ {"ok":false, "error":"Ref [99] not found.", "hint":"Run 'bp snapshot' to refresh element refs."}
166
+ ```
167
+
168
+ Force human output: `bp --human open https://example.com`
169
+
170
+ ## Eval
171
+
172
+ `eval` is the escape hatch — anything JavaScript can do:
173
+
174
+ ```bash
175
+ bp eval "history.back()" # go back
176
+ bp eval "history.forward()" # go forward
177
+ bp eval "location.reload()" # reload
178
+ bp eval "window.scrollBy(0, 500)" # scroll down
179
+ bp eval "document.querySelector('h1').textContent" # extract text
180
+ bp eval "document.querySelector('div').innerHTML" # extract HTML
181
+ bp eval "JSON.stringify(localStorage)" # read storage
182
+ echo 'complex js here' | bp eval # stdin for complex JS
183
+ ```
184
+
185
+ ## File Upload
186
+
187
+ `bp upload` auto-detects `<input type="file">` on the page:
188
+
189
+ ```bash
190
+ bp open https://images.google.com
191
+ bp click 5 # click "Search by image"
192
+ bp upload ~/Downloads/photo.jpg # auto-finds file input, triggers upload
193
+ ```
194
+
195
+ ## Network Interception
196
+
197
+ Monitor, block, and mock HTTP requests:
198
+
199
+ ```bash
200
+ # Monitor traffic
201
+ bp net # list recent requests
202
+ bp net --url "*api*" --method POST # filter by URL and method
203
+ bp net show 3 # full details + response body
204
+
205
+ # Block requests
206
+ bp net block "*tracking*" # block analytics/tracking
207
+ bp net block "*ads*"
208
+
209
+ # Mock API responses
210
+ bp net mock "*api/data*" --body '{"ok":true}'
211
+ bp net mock "*api/users*" --file mock.json --status 200
212
+
213
+ # Override request headers
214
+ bp net headers "*api*" "Authorization:Bearer test123"
215
+
216
+ # Manage rules
217
+ bp net rules # list active rules
218
+ bp net remove 2 # remove rule #2
219
+ bp net remove --all # clear all rules
220
+ bp net clear # clear captured request log
221
+ ```
222
+
223
+ ## Requirements
224
+
225
+ - Chrome / Chromium / Edge / Brave (any Chromium-based browser)
226
+ - Node.js >= 18
227
+ - Chrome remote debugging enabled (`chrome://inspect/#remote-debugging`)
228
+
229
+ ## License
230
+
231
+ MIT
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/paths.ts
4
+ import { join } from "path";
5
+ import { homedir } from "os";
6
+ var STATE_DIR = join(homedir(), ".browser-pilot");
7
+ var STATE_FILE = join(STATE_DIR, "state.json");
8
+ var SOCKET_PATH = join(STATE_DIR, "daemon.sock");
9
+ var PID_FILE = join(STATE_DIR, "daemon.pid");
10
+ var REFS_FILE = join(STATE_DIR, "refs.json");
11
+
12
+ export {
13
+ STATE_DIR,
14
+ STATE_FILE,
15
+ SOCKET_PATH,
16
+ PID_FILE,
17
+ REFS_FILE
18
+ };