browsirai 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/LICENSE ADDED
@@ -0,0 +1,78 @@
1
+ Business Source License 1.1
2
+
3
+ Parameters
4
+
5
+ Licensor: Mert Köseoğlu
6
+ Licensed Work: browserd
7
+ The Licensed Work is (c) 2026 Mert Köseoğlu.
8
+ Additional Use Grant: You may make use of the Licensed Work, provided that
9
+ you do not use the Licensed Work for a Commercial
10
+ Purpose.
11
+
12
+ A "Commercial Purpose" means any use of the Licensed
13
+ Work that is primarily intended for or directed toward
14
+ commercial advantage or monetary compensation. This
15
+ includes, without limitation:
16
+
17
+ (a) offering the Licensed Work as a hosted or managed
18
+ service (SaaS);
19
+ (b) embedding or bundling the Licensed Work in a
20
+ commercial product;
21
+ (c) using the Licensed Work to provide paid services
22
+ to third parties.
23
+
24
+ Use for internal business purposes (e.g., an
25
+ engineering team using the Licensed Work for their
26
+ own development workflow) is permitted.
27
+
28
+ Change Date: March 14, 2030
29
+ Change License: Apache License, Version 2.0
30
+
31
+ For information about alternative licensing arrangements for the Licensed
32
+ Work, please contact: bm.ksglu@gmail.com
33
+
34
+ Notice
35
+
36
+ Business Source License 1.1
37
+
38
+ Terms
39
+
40
+ The Licensor hereby grants you the right to copy, modify, create derivative
41
+ works, redistribute, and make non-production use of the Licensed Work. The
42
+ Licensor may make an Additional Use Grant, above, permitting limited
43
+ production use.
44
+
45
+ Effective on the Change Date, or the fourth anniversary of the first publicly
46
+ available distribution of a specific version of the Licensed Work under this
47
+ License, whichever comes first, the Licensor hereby grants you rights under
48
+ the terms of the Change License, and the rights granted in the paragraph
49
+ above terminate.
50
+
51
+ If your use of the Licensed Work does not comply with the requirements
52
+ currently in effect as described in this License, you must purchase a
53
+ commercial license from the Licensor, its affiliated entities, or authorized
54
+ resellers, or you must refrain from using the Licensed Work.
55
+
56
+ All copies of the original and modified Licensed Work, and derivative works
57
+ of the Licensed Work, are subject to this License. This License applies
58
+ separately for each version of the Licensed Work and the Change Date may
59
+ vary for each version of the Licensed Work released by Licensor.
60
+
61
+ You must conspicuously display this License on each original or modified copy
62
+ of the Licensed Work. If you receive the Licensed Work in original or
63
+ modified form from a third party, the terms and conditions set forth in this
64
+ License apply to your use of that work.
65
+
66
+ Any use of the Licensed Work in violation of this License will automatically
67
+ terminate your rights under this License for the current and all other
68
+ versions of the Licensed Work.
69
+
70
+ This License does not grant you any right in any trademark or logo of
71
+ Licensor or its affiliates (provided that you may use a trademark or logo of
72
+ Licensor as expressly required by this License).
73
+
74
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
75
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
76
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
77
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
78
+ TITLE.
package/README.md ADDED
@@ -0,0 +1,454 @@
1
+ # browsirai
2
+
3
+ [![npm version](https://img.shields.io/npm/v/browsirai.svg?style=flat-square)](https://www.npmjs.com/package/browsirai)
4
+ [![License: BSL-1.1](https://img.shields.io/badge/license-BSL--1.1-blue?style=flat-square)](LICENSE)
5
+
6
+ **Your browser. Your sessions. Your agent.**
7
+
8
+ An MCP server that connects AI coding agents to your real Chrome via CDP. Like `httpd` or `sshd`, browsirai runs as a daemon — it survives Chrome crashes, maintains state, and is always ready.
9
+
10
+ ## Why browsirai?
11
+
12
+ - **Your sessions, zero config** — Connects to your real Chrome binary. Same binary = same Keychain encryption key = all your sessions work instantly. GitHub, Vercel, AWS, Jira — logged in from the start.
13
+
14
+ - **Credentials never reach the LLM** — Cookie values are copied between local SQLite databases at the filesystem level. They never enter the MCP message stream, never reach the model context, never leave your machine.
15
+
16
+ - **Invisible to websites** — Real Chrome, real user agent, real extensions fingerprint, real TLS stack. No `navigator.webdriver`, no headless indicators, no automation flags.
17
+
18
+ - **No extra browser to install** — Other tools download a separate Chromium (100-300 MB). browsirai uses the Chrome you already have.
19
+
20
+ - **20x cheaper than screenshot-default tools** — Server-side snapshot redirection returns ~500 tokens instead of ~10K per interaction. 50 interactions/day: 25K tokens vs 500K.
21
+
22
+ - **Always up to date** — Auto-upgrade checks npm registry on every server start. Next session launches with the latest version. Zero manual intervention.
23
+
24
+ ## Quick Start
25
+
26
+ ```bash
27
+ npm install -g browsirai
28
+ browsirai install
29
+ ```
30
+
31
+ The installer auto-detects your AI platform and configures the MCP server.
32
+
33
+ <details>
34
+ <summary><strong>Claude Code</strong></summary>
35
+
36
+ ```json
37
+ // .mcp.json
38
+ {
39
+ "mcpServers": {
40
+ "browsirai": {
41
+ "command": "npx",
42
+ "args": ["-y", "browsirai"]
43
+ }
44
+ }
45
+ }
46
+ ```
47
+ </details>
48
+
49
+ <details>
50
+ <summary><strong>Cursor</strong></summary>
51
+
52
+ ```json
53
+ // .cursor/mcp.json
54
+ {
55
+ "mcpServers": {
56
+ "browsirai": {
57
+ "command": "npx",
58
+ "args": ["-y", "browsirai"]
59
+ }
60
+ }
61
+ }
62
+ ```
63
+ </details>
64
+
65
+ <details>
66
+ <summary><strong>VS Code Copilot</strong></summary>
67
+
68
+ ```json
69
+ // .vscode/mcp.json
70
+ {
71
+ "servers": {
72
+ "browsirai": {
73
+ "command": "npx",
74
+ "args": ["-y", "browsirai"]
75
+ }
76
+ }
77
+ }
78
+ ```
79
+ </details>
80
+
81
+ <details>
82
+ <summary><strong>Gemini CLI</strong></summary>
83
+
84
+ ```json
85
+ // ~/.gemini/settings.json
86
+ {
87
+ "mcpServers": {
88
+ "browsirai": {
89
+ "command": "npx",
90
+ "args": ["-y", "browsirai"]
91
+ }
92
+ }
93
+ }
94
+ ```
95
+ </details>
96
+
97
+ <details>
98
+ <summary><strong>Windsurf</strong></summary>
99
+
100
+ ```json
101
+ // ~/.codeium/windsurf/mcp_config.json
102
+ {
103
+ "mcpServers": {
104
+ "browsirai": {
105
+ "command": "npx",
106
+ "args": ["-y", "browsirai"]
107
+ }
108
+ }
109
+ }
110
+ ```
111
+ </details>
112
+
113
+ <details>
114
+ <summary><strong>Cline</strong></summary>
115
+
116
+ ```json
117
+ // Cline MCP settings (Settings > MCP Servers)
118
+ {
119
+ "mcpServers": {
120
+ "browsirai": {
121
+ "command": "npx",
122
+ "args": ["-y", "browsirai"]
123
+ }
124
+ }
125
+ }
126
+ ```
127
+ </details>
128
+
129
+ <details>
130
+ <summary><strong>Zed</strong></summary>
131
+
132
+ ```json
133
+ // ~/.config/zed/settings.json
134
+ {
135
+ "context_servers": {
136
+ "browsirai": {
137
+ "command": "npx",
138
+ "args": ["-y", "browsirai"]
139
+ }
140
+ }
141
+ }
142
+ ```
143
+ </details>
144
+
145
+ <details>
146
+ <summary><strong>Continue</strong></summary>
147
+
148
+ ```yaml
149
+ # ~/.continue/config.yaml
150
+ mcpServers:
151
+ browsirai:
152
+ command: npx
153
+ args: ["-y", "browsirai"]
154
+ ```
155
+ </details>
156
+
157
+ <details>
158
+ <summary><strong>OpenCode</strong></summary>
159
+
160
+ ```json
161
+ // opencode.json
162
+ {
163
+ "mcpServers": {
164
+ "browsirai": {
165
+ "command": "npx",
166
+ "args": ["-y", "browsirai"]
167
+ }
168
+ }
169
+ }
170
+ ```
171
+ </details>
172
+
173
+ ## Features
174
+
175
+ | Feature | Description |
176
+ |---------|-------------|
177
+ | **Cookie Sync** | Filesystem-level SQLite copy. Same Chrome binary = same encryption key. Sessions work instantly. |
178
+ | **Daemon Architecture** | MCP server survives Chrome crashes. Auto-reconnects on next `browser_connect`. |
179
+ | **Skill Injection** | On every connect, injects workflow hints, cost hierarchy, and identity resolution rules into agent context. |
180
+ | **EventBuffer Capture** | Server-side CDP event listeners (not browser-side JS). Network requests and console messages survive page navigations. |
181
+ | **Source Inspection** | Maps DOM elements to source code: React (Fiber tree + jsxDEV), Vue (`__file`), Svelte (`__svelte_meta`). |
182
+ | **Network Intercept** | Route, abort, and mock HTTP requests with glob pattern matching. |
183
+ | **Element Refs** | Accessibility tree nodes get `@eN` refs. Click, fill, hover, drag — all by ref. |
184
+ | **Pixel Diff** | Compare two screenshots pixel-by-pixel. Returns diff percentage and visual overlay. |
185
+ | **Session Persistence** | Save/load cookies, localStorage, sessionStorage across agent sessions. |
186
+ | **Auto-Upgrade** | Checks npm registry on server start. Background upgrade applies on next restart. |
187
+ | **Cost Optimization** | `browser_screenshot` auto-returns text snapshot (~500 tokens) unless `visual: true` (~10K tokens). |
188
+ | **Navigate-Hook Resync** | Detects Chrome profile switches and cookie changes. Re-syncs automatically before navigation. |
189
+
190
+ ## Tools (33)
191
+
192
+ ### Connection & Lifecycle
193
+
194
+ | Tool | What it does | ~Tokens |
195
+ |------|-------------|---------|
196
+ | `browser_connect` | Connect to Chrome via CDP. Auto-launches if needed. Injects agent skill hints. | — |
197
+ | `browser_tabs` | List open tabs, filter by title/URL glob. | ~10 |
198
+ | `browser_list` | List available browser instances on default ports. | ~10 |
199
+ | `browser_close` | Close tab(s) or detach. `force: true` to actually close. | — |
200
+ | `browser_resize` | Set viewport dimensions or preset (`mobile`, `tablet`, `desktop`, `reset`). | ~10 |
201
+
202
+ ### Navigation
203
+
204
+ | Tool | What it does | ~Tokens |
205
+ |------|-------------|---------|
206
+ | `browser_navigate` | Navigate to URL. `waitUntil`: `load`, `domcontentloaded`, `networkidle`. | ~500 |
207
+ | `browser_navigate_back` | Go back or forward in history. | ~500 |
208
+ | `browser_scroll` | Scroll page/element by direction and pixels, or scroll element into view. | ~10 |
209
+ | `browser_wait_for` | Wait for text, selector, URL glob, JS condition, or timeout. | ~10 |
210
+
211
+ ### Observation
212
+
213
+ | Tool | What it does | ~Tokens |
214
+ |------|-------------|---------|
215
+ | `browser_snapshot` | Accessibility tree with `@eN` refs. `compact`, `interactive`, `cursor`, `depth` modes. | ~500 |
216
+ | `browser_screenshot` | Returns text snapshot by default. `visual: true` for base64 image. | ~500 / ~10K |
217
+ | `browser_annotated_screenshot` | Screenshot with numbered labels on interactive elements. | ~12K |
218
+ | `browser_html` | Raw HTML of page or element by selector. | ~500 |
219
+ | `browser_find` | Find elements by ARIA role, name, or text. Returns `@eN` ref. | ~100 |
220
+ | `browser_inspect_source` | Source file, line, component name. React/Vue/Svelte. | ~100 |
221
+ | `browser_evaluate` | Run JavaScript in page context. Async supported. | ~10 |
222
+
223
+ ### Interaction
224
+
225
+ | Tool | What it does | ~Tokens |
226
+ |------|-------------|---------|
227
+ | `browser_click` | Click by `@eN` ref, CSS selector, or x/y coordinates. `newTab` support. | ~10 |
228
+ | `browser_fill_form` | Clear + type into a field. Handles textbox, checkbox, radio, combobox, slider. | ~10 |
229
+ | `browser_type` | Type text (appends, doesn't clear). `slowly` mode for key-event listeners. | ~10 |
230
+ | `browser_press_key` | Press key or combination (`Control+c`, `Meta+a`, `Enter`, `Escape`). | ~10 |
231
+ | `browser_hover` | Hover over element by ref. | ~10 |
232
+ | `browser_drag` | Drag from one ref to another with synthesized mouse events. | ~10 |
233
+ | `browser_select_option` | Select dropdown options by value or label text. | ~10 |
234
+ | `browser_file_upload` | Upload files to a file input by ref. | ~10 |
235
+ | `browser_handle_dialog` | Accept/dismiss alert, confirm, prompt. With optional prompt text. | ~10 |
236
+
237
+ ### Network & Debugging
238
+
239
+ | Tool | What it does | ~Tokens |
240
+ |------|-------------|---------|
241
+ | `browser_network_requests` | List captured requests. Filter by URL glob, exclude static resources, include headers. | ~100 |
242
+ | `browser_console_messages` | Retrieve console log/warn/error/info messages. Filter by level. | ~100 |
243
+ | `browser_route` | Intercept requests matching URL glob. Respond with custom body/status/headers. | ~10 |
244
+ | `browser_abort` | Block requests matching URL glob. | ~10 |
245
+ | `browser_unroute` | Remove intercept rules. `all: true` to clear everything. | ~10 |
246
+
247
+ ### State & Persistence
248
+
249
+ | Tool | What it does | ~Tokens |
250
+ |------|-------------|---------|
251
+ | `browser_save_state` | Save cookies, localStorage, sessionStorage to named file. | ~10 |
252
+ | `browser_load_state` | Restore saved state. Optionally navigate to URL after loading. | ~10 |
253
+ | `browser_diff` | Pixel-by-pixel comparison. Returns diff %, pixel counts, visual overlay. | ~11K |
254
+
255
+ > **~Tokens** = approximate tokens returned to the LLM per call.
256
+
257
+ ## Architecture
258
+
259
+ ### Cookie Sync
260
+
261
+ ```
262
+ ┌──────────────────┐ filesystem copy ┌──────────────────┐
263
+ │ Your Chrome │ ──────────────────→ │ browsirai Chrome │
264
+ │ Profile/Cookies │ (SQLite → SQLite) │ Temp/Cookies │
265
+ │ (encrypted) │ │ (same key) │
266
+ └──────────────────┘ └────────┬─────────┘
267
+
268
+ │ CDP
269
+
270
+ ┌────────────────┐
271
+ │ Page Content │
272
+ │ (DOM, JS, │
273
+ │ snapshots) │ ──→ LLM
274
+ └────────────────┘
275
+
276
+ Cookie values NEVER reach the LLM.
277
+ Only page content is returned.
278
+ ```
279
+
280
+ Chrome encrypts cookies with a key tied to the **specific browser binary**:
281
+
282
+ | Platform | Encryption | Key bound to |
283
+ |----------|-----------|--------------|
284
+ | macOS | Keychain | Application binary |
285
+ | Linux | GNOME Keyring / KWallet | Service name |
286
+ | Windows | DPAPI | User account + browser prefix |
287
+
288
+ A different binary (Chromium, Chrome for Testing, Electron) gets a different key and **cannot decrypt** your cookies. browsirai uses your real Chrome binary — same key, all sessions preserved.
289
+
290
+ ### Cost Optimization
291
+
292
+ ```
293
+ ┌─────────────────────────────────────────────────────┐
294
+ │ Cost Hierarchy │
295
+ │ │
296
+ │ browser_evaluate ~10 tokens JS expression │
297
+ │ browser_snapshot ~500 tokens Accessibility tree│
298
+ │ browser_screenshot ~10K tokens Visual (opt-in) │
299
+ │ │
300
+ │ 20x cost reduction vs screenshot-default tools │
301
+ └─────────────────────────────────────────────────────┘
302
+ ```
303
+
304
+ `browser_screenshot` without `visual: true` auto-returns a text snapshot. The LLM gets the same information at 1/20th the cost.
305
+
306
+ | Scenario | Screenshot-default tool | browsirai |
307
+ |----------|----------------------|----------|
308
+ | 50 interactions/day | 500K tokens/day | 25K tokens/day |
309
+ | 20 devs × 22 working days | 220M tokens/month | 11M tokens/month |
310
+
311
+ ### EventBuffer
312
+
313
+ Network requests and console messages are captured via **server-side CDP event listeners** — not browser-side JavaScript injection. This means:
314
+
315
+ - Captures survive page navigations (no re-injection needed)
316
+ - Bounded ring buffer (500 events) prevents memory leaks
317
+ - URL secrets are automatically redacted (JWT, Bearer tokens, auth headers)
318
+ - Static resources (images, fonts, stylesheets) can be filtered out
319
+
320
+ ### Auto-Upgrade
321
+
322
+ ```
323
+ Session 1: server starts → checks npm registry → background upgrade
324
+ Session 2: starts with latest version
325
+ ```
326
+
327
+ - 1-hour rate limit between checks
328
+ - npx: clears npm cache (next invocation fetches latest)
329
+ - global: `npm install -g browsirai@latest` in background
330
+ - dev mode: skipped
331
+ - Upgrade notice shown on `browser_connect` if newer version available
332
+ - All errors silently caught — never crashes the server
333
+
334
+ ### Skill Injection
335
+
336
+ On every `browser_connect`, browsirai injects a structured skill document into the agent context:
337
+
338
+ - **Cost hierarchy** — guides the agent to prefer `evaluate` > `snapshot` > `screenshot`
339
+ - **Workflow patterns** — snapshot-ref interaction model, when to re-snapshot
340
+ - **Identity resolution** — use browser session cookies, never guess usernames
341
+ - **Per-tool hints** — appended to each tool response (ref staling warnings, cross-origin limitations)
342
+
343
+ ## Diagnostics
344
+
345
+ ```bash
346
+ browsirai doctor
347
+ ```
348
+
349
+ ```
350
+ [PASS] browsirai version
351
+ v0.1.0 (npx)
352
+ [PASS] Install path
353
+ /Users/you/.npm/_npx/.../node_modules/browsirai
354
+ [PASS] Latest version
355
+ v0.1.0 (up to date)
356
+ [PASS] Chrome/Chromium installed
357
+ Found at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
358
+ [PASS] Node.js version
359
+ v20.19.2 (>= 18 required)
360
+ [PASS] CDP connection
361
+ Connected (port 9222, --remote-debugging-port)
362
+ [PASS] Platform config
363
+ browsirai found in .mcp.json (platform: claude-code)
364
+ ```
365
+
366
+ Checks: version + install method, install path, latest version availability, Chrome installation, Node.js version, CDP connectivity, platform configuration.
367
+
368
+ ## Security
369
+
370
+ ### What browsirai does
371
+
372
+ - Copies cookies between **local SQLite databases** (filesystem-level, never in MCP messages)
373
+ - Launches a **separate Chrome instance** (never touches your open tabs)
374
+ - Disables extensions in the temporary profile (`--disable-extensions`)
375
+ - Returns only **page content** to the agent (DOM text, evaluate results, snapshots)
376
+ - **Redacts secrets** in network output (Authorization, Cookie, Set-Cookie, Bearer tokens, JWTs)
377
+ - Resets state gracefully when Chrome closes (MCP server stays alive)
378
+
379
+ ### What browsirai does NOT do
380
+
381
+ - Send cookie values to the LLM provider
382
+ - Store credentials in any config file
383
+ - Use a cloud relay or proxy
384
+ - Require you to enter passwords into the agent
385
+ - Modify your Chrome profile or existing sessions
386
+ - Quit your running Chrome
387
+
388
+ ## Supported Browsers
389
+
390
+ | Browser | macOS | Linux | Windows |
391
+ |---------|-------|-------|---------|
392
+ | Google Chrome | ✓ | ✓ | ✓ |
393
+ | Chrome Canary | ✓ | — | — |
394
+ | Microsoft Edge | ✓ | — | ✓ |
395
+ | Brave | ✓ | — | ✓ |
396
+ | Chromium | — | ✓ | — |
397
+
398
+ Any browser built on Chromium supports CDP — and browsirai supports it.
399
+
400
+ ## Supported Platforms
401
+
402
+ | Platform | Status |
403
+ |----------|--------|
404
+ | Claude Code | ✓ |
405
+ | Cursor | ✓ |
406
+ | Gemini CLI | ✓ |
407
+ | VS Code Copilot | ✓ |
408
+ | Windsurf | ✓ |
409
+ | Cline | ✓ |
410
+ | Zed | ✓ |
411
+ | Continue | ✓ |
412
+ | OpenCode | ✓ |
413
+
414
+ ## FAQ
415
+
416
+ <details>
417
+ <summary><strong>Does the LLM see my passwords or cookies?</strong></summary>
418
+
419
+ No. Cookie values are copied between local SQLite databases at the filesystem level. The LLM only sees page content — text, DOM elements, JavaScript evaluation results.
420
+ </details>
421
+
422
+ <details>
423
+ <summary><strong>Why not Playwright?</strong></summary>
424
+
425
+ Playwright uses a separate Chromium binary. Every platform ties the cookie encryption key to the specific browser binary. Chromium's key is different from Chrome's — so Playwright **cannot decrypt** your Chrome cookies. This is an architectural limitation, not a missing feature.
426
+ </details>
427
+
428
+ <details>
429
+ <summary><strong>What happens when I close Chrome?</strong></summary>
430
+
431
+ That's the `d` in browsirai — the daemon stays alive. On the next `browser_connect`, it launches a fresh Chrome instance with re-synced cookies.
432
+ </details>
433
+
434
+ <details>
435
+ <summary><strong>Does it work headless?</strong></summary>
436
+
437
+ Yes. `browser_connect { headless: true }`. Note: some services block headless Chrome sessions.
438
+ </details>
439
+
440
+ <details>
441
+ <summary><strong>Does it work with Chrome profiles?</strong></summary>
442
+
443
+ Yes. browsirai reads `Local State` to find your active Chrome profile and syncs cookies from it. If you switch profiles, the navigate-hook detects the change and re-syncs automatically.
444
+ </details>
445
+
446
+ <details>
447
+ <summary><strong>Can the LLM see sensitive page content?</strong></summary>
448
+
449
+ Yes — the LLM sees the same content you'd see in the browser. This is inherent to any browser automation tool. The key difference is that **authentication credentials** (cookies, tokens, session IDs) are never in the LLM context.
450
+ </details>
451
+
452
+ ## License
453
+
454
+ BSL-1.1 (Business Source License 1.1) — free for non-commercial use. Converts to Apache-2.0 on March 14, 2030.