chromex-mcp 1.2.0 → 1.3.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 CHANGED
@@ -1,50 +1,87 @@
1
1
  # Chromex
2
2
 
3
- Zero-dependency Chrome DevTools Protocol CLI for AI agents. Connects directly to Chrome, Brave, Edge, or Chromium via WebSocket. No Puppeteer, no npm install, no bloat.
4
-
5
- Built as a [Claude Code](https://claude.ai/code) plugin but works standalone with any AI agent or from the terminal.
3
+ Zero-dependency Chrome DevTools Protocol toolkit for AI agents. 52 typed MCP tools + CLI. Connects directly to Chrome, Brave, Edge, or Chromium via WebSocket. No Puppeteer, no bloat.
6
4
 
7
5
  ## Features
8
6
 
9
- - **45+ commands** -- screenshots, form filling, cookies, PDF, device emulation, network interception, performance tracing, touch gestures, and more
7
+ - **52 MCP tools** -- typed JSON Schema, annotations (`readOnlyHint`, `destructiveHint`), inline screenshots (base64)
10
8
  - **Zero dependencies** -- uses only Node.js 22+ built-in modules (WebSocket, fs, net, crypto)
11
9
  - **Ref-based selection** -- `snap --refs` assigns `@e1`, `@e2`... to interactive elements, then `click @e5` or `fill @e3 "value"`. No fragile CSS selectors
10
+ - **Incremental snapshots** -- second snapshot returns only changed nodes (diff), reducing output from thousands of lines to just what changed
11
+ - **Auto-snapshot** -- interactive commands (click, fill, nav, etc.) automatically append an incremental snapshot with refs, so the agent sees the page state in a single round-trip
12
+ - **Scroll detection** -- snapshots report scrollable containers with remaining distance (`[scroll: page: down:1200px | sidebar: up:300px]`)
12
13
  - **Per-tab persistent daemons** -- each tab gets a background process connected via Unix socket. Chrome's "Allow debugging" modal fires once, not on every command
13
14
  - **Security hardened** -- domain filtering (allow/blocklist), CDP method blocklist, token-authenticated sockets, full audit log
14
15
  - **Multi-browser** -- auto-detects Brave, Chrome, Chrome Canary, Chromium, Edge, Vivaldi (macOS + Linux)
15
16
  - **Network control** -- throttle to 3G/offline, intercept & mock requests, record HAR files
16
17
  - **Form filling** -- fill inputs, select dropdowns, toggle checkboxes, upload files, batch fill entire forms. Works with React/Vue/Angular
17
18
  - **Browser launcher** -- launch browser with remote debugging pre-enabled (skips the "Allow debugging" modal entirely)
19
+ - **CLI included** -- same commands available from the terminal for scripts and CI/CD
18
20
 
19
21
  ## Requirements
20
22
 
21
23
  - Node.js 22+ (for built-in WebSocket)
22
24
  - Any Chromium-based browser
23
25
 
24
- ## Quick Start
25
-
26
- ### As a Claude Code plugin
26
+ ## Installation
27
27
 
28
28
  ```bash
29
- # Add the marketplace
30
- /plugin marketplace add github:whallysson/chromex
29
+ # Add to Claude Code (global -- all projects)
30
+ claude mcp add chromex -s user npx chromex-mcp@latest
31
31
 
32
- # Install
33
- /plugin install chromex
32
+ # Or project-only
33
+ claude mcp add chromex npx chromex-mcp@latest
34
34
  ```
35
35
 
36
- ### Standalone
36
+ ### Auto-Approve (recommended)
37
+
38
+ Add to `~/.claude/settings.json`:
39
+
40
+ ```json
41
+ {
42
+ "permissions": {
43
+ "allow": ["mcp__chromex"]
44
+ }
45
+ }
46
+ ```
47
+
48
+ This approves all 52 MCP tools at once. For granular control, approve individual tools:
49
+
50
+ ```json
51
+ {
52
+ "permissions": {
53
+ "allow": [
54
+ "mcp__chromex__chromex_list",
55
+ "mcp__chromex__chromex_snapshot",
56
+ "mcp__chromex__chromex_screenshot",
57
+ "mcp__chromex__chromex_perf"
58
+ ]
59
+ }
60
+ }
61
+ ```
62
+
63
+ ### Global install (optional)
37
64
 
38
65
  ```bash
39
- git clone https://github.com/whallysson/chromex.git
40
- cd chromex
41
- chmod +x skills/chromex/scripts/chromex.mjs
66
+ npm install -g chromex-mcp
67
+ ```
68
+
69
+ This installs three binaries:
70
+
71
+ | Binary | Purpose |
72
+ |--------|---------|
73
+ | `chromex` | CLI -- the main command for terminal usage |
74
+ | `chromex-cli` | Alias for `chromex` |
75
+ | `chromex-mcp` | MCP server (stdio JSON-RPC) -- used by `claude mcp add`, not run directly |
42
76
 
43
- # Optional: create an alias
44
- alias chromex="node $(pwd)/skills/chromex/scripts/chromex.mjs"
77
+ ```bash
78
+ chromex list # List open tabs
79
+ chromex launch --url https://example.com # Launch browser
80
+ chromex snap 6BE8 --refs # Snapshot with refs
81
+ chromex click 6BE8 @e3 # Click by ref
45
82
  ```
46
83
 
47
- ### Connect to your browser
84
+ ## Connect to Your Browser
48
85
 
49
86
  **Option A: Launch a new browser** (recommended -- no setup needed)
50
87
 
@@ -56,8 +93,6 @@ This starts Chrome/Brave/Edge with remote debugging pre-enabled. No manual confi
56
93
 
57
94
  **Option B: Connect to an already-running browser**
58
95
 
59
- You **must** enable remote debugging first:
60
-
61
96
  1. Open your browser (Chrome, Brave, Edge, etc.)
62
97
  2. Navigate to `chrome://inspect/#remote-debugging`
63
98
  3. **Toggle the switch ON** to enable remote debugging
@@ -67,11 +102,7 @@ You **must** enable remote debugging first:
67
102
 
68
103
  > **Note:** With Option B, Chrome will show an "Allow debugging" dialog the first time you access each tab. Click "Allow" once per tab -- the daemon keeps the session alive after that.
69
104
 
70
- ```bash
71
- chromex list
72
- ```
73
-
74
- ### Your first commands
105
+ ## Quick Start
75
106
 
76
107
  ```bash
77
108
  # List open tabs
@@ -118,8 +149,10 @@ chromex stop # Stop all daemons
118
149
  ### Inspect
119
150
 
120
151
  ```bash
121
- chromex snap <target> # Accessibility tree (prefer over html)
152
+ chromex snap <target> # Accessibility tree snapshot (compact)
122
153
  chromex snap <target> --refs # With interactive refs (@e1, @e2...)
154
+ chromex snap <target> --depth=3 # Limit tree depth
155
+ chromex snap <target> --full # Force full snapshot (skip diff)
123
156
  chromex html <target> "#main" # Element HTML by selector
124
157
  chromex shot <target> /tmp/page.png # Viewport screenshot
125
158
  chromex shot <target> /tmp/full.png --full # Full page screenshot
@@ -151,8 +184,10 @@ chromex wait <target> load # Wait for page load
151
184
  chromex wait <target> domready # Wait for DOMContentLoaded
152
185
  chromex wait <target> fcp # Wait for First Contentful Paint
153
186
  chromex scroll <target> down 500 # Scroll down 500px
154
- chromex scroll <target> to "#footer" # Scroll to element
187
+ chromex scroll <target> up 300 # Scroll up 300px
155
188
  chromex scroll <target> top # Scroll to top
189
+ chromex scroll <target> bottom # Scroll to bottom
190
+ chromex scroll <target> to "#footer" # Scroll to element
156
191
  ```
157
192
 
158
193
  ### Interact
@@ -207,6 +242,7 @@ chromex pdf <target> /tmp/page.pdf # Export as PDF
207
242
  ```bash
208
243
  chromex throttle <target> 3g # Throttle to 3G
209
244
  chromex throttle <target> slow-3g # Throttle to slow 3G
245
+ chromex throttle <target> 4g # Throttle to 4G
210
246
  chromex throttle <target> offline # Go offline
211
247
  chromex throttle <target> custom 200 1000 500 # Custom: latency, down, up (kbps)
212
248
  chromex throttle <target> reset # Remove throttling
@@ -224,8 +260,12 @@ chromex har <target> stop /tmp/trace.har # Save HAR file
224
260
 
225
261
  ```bash
226
262
  chromex emulate <target> iphone-14 # 390x844 @3x mobile
263
+ chromex emulate <target> iphone-15-pro # 393x852 @3x mobile
227
264
  chromex emulate <target> ipad-pro # 1024x1366 @2x tablet
228
265
  chromex emulate <target> pixel-7 # 412x915 @2.625x mobile
266
+ chromex emulate <target> galaxy-s23 # 360x780 @3x mobile
267
+ chromex emulate <target> macbook-air # 1440x900 @2x laptop
268
+ chromex emulate <target> desktop-1080p # 1920x1080 @1x
229
269
  chromex emulate <target> desktop-4k # 3840x2160 @1x
230
270
  chromex emulate <target> reset # Reset to default
231
271
  chromex geo <target> -23.55 -46.63 # Set geolocation (Sao Paulo)
@@ -236,8 +276,6 @@ chromex cpu <target> 4 # CPU 4x slower
236
276
  chromex cpu <target> reset # Reset CPU speed
237
277
  ```
238
278
 
239
- Available devices: `iphone-14`, `iphone-15-pro`, `ipad-pro`, `pixel-7`, `galaxy-s23`, `macbook-air`, `desktop-1080p`, `desktop-4k`.
240
-
241
279
  ### Advanced
242
280
 
243
281
  ```bash
@@ -278,73 +316,127 @@ chromex click <target> @e3
278
316
  chromex click <target> @e4
279
317
  ```
280
318
 
281
- Refs are assigned to all interactive elements (buttons, links, inputs, checkboxes, radios, dropdowns, tabs, switches). They persist until the next `snap --refs` call.
319
+ Refs are assigned to all interactive elements (buttons, links, inputs, checkboxes, radios, dropdowns, tabs, switches, sliders, search boxes). They persist until the next `snap --refs` call.
282
320
 
283
321
  Supported ref commands: `click @eN`, `fill @eN "value"`, `hover @eN`.
284
322
 
285
- ## MCP Server (Recommended for Claude Code)
323
+ ## Snapshot Optimizations
324
+
325
+ Chromex snapshots are designed to minimize token usage for AI agents.
286
326
 
287
- Chromex also ships as an MCP server -- typed tools, auto-approve with one line, no Bash globs.
327
+ ### Incremental Diff
288
328
 
289
- ### Setup
329
+ The first snapshot returns the full accessibility tree. Subsequent snapshots return only nodes that changed:
330
+
331
+ ```
332
+ [incremental: 2 changed, 45 unchanged]
333
+ *[textbox] Email = "user@example.com"
334
+ *[button] Submit
335
+ ```
336
+
337
+ - Changed/new nodes are marked with `*`
338
+ - Unchanged subtrees are collapsed entirely
339
+ - Use `--full` to force a full snapshot (skips diff)
340
+ - Navigation (`nav`) resets the diff baseline automatically
341
+
342
+ ### Depth Limiting
343
+
344
+ Limit tree depth for large pages:
290
345
 
291
346
  ```bash
292
- # Global (all projects)
293
- claude mcp add chromex -s user npx chromex-mcp@latest
347
+ chromex snap <target> --depth=3 # Only 3 levels deep
348
+ ```
294
349
 
295
- # Or project-only
296
- claude mcp add chromex npx chromex-mcp@latest
350
+ Nodes at the depth limit render as leaves (children are not expanded).
351
+
352
+ ### Scroll Detection
353
+
354
+ Snapshots automatically detect scrollable containers and report remaining scroll distance:
355
+
356
+ ```
357
+ [scroll: page: down:1200px | sidebar: up:300px, down:800px]
297
358
  ```
298
359
 
299
- ### Auto-Approve
360
+ ### Visibility Filtering
300
361
 
301
- Add to `~/.claude/settings.json`:
362
+ - Ignored/hidden accessibility nodes are automatically omitted
363
+ - Disabled interactive elements are shown but not assigned refs (can't be interacted with)
364
+ - Generic wrapper nodes (`div`, `span` with no semantic role) are collapsed -- their children inherit the parent's depth
365
+ - Names longer than 200 characters are truncated with `...`
302
366
 
303
- ```json
304
- {
305
- "permissions": {
306
- "allow": ["mcp__chromex"]
307
- }
308
- }
367
+ ## Auto-Snapshot
368
+
369
+ Interactive commands automatically append an incremental snapshot with refs after execution. This lets the AI agent see the updated page state without a separate `snap` call:
370
+
371
+ ```bash
372
+ chromex click <target> @e3
373
+ # Output:
374
+ # Clicked @e3 [button] "Submit"
375
+ #
376
+ # [incremental: 5 changed, 40 unchanged]
377
+ # @e1 [heading] Thank you!
378
+ # @e2 [link] Back to home
379
+ # ...
309
380
  ```
310
381
 
311
- This approves all 52 MCP tools at once. For granular control, approve individual tools:
382
+ Commands that trigger auto-snapshot: `click`, `clickxy`, `type`, `fill`, `clear`, `select`, `check`, `form`, `nav`, `dialog`, `loadall`, `drag`, `touch`, `upload`.
312
383
 
313
- ```json
314
- {
315
- "permissions": {
316
- "allow": [
317
- "mcp__chromex__chromex_list",
318
- "mcp__chromex__chromex_snapshot",
319
- "mcp__chromex__chromex_screenshot",
320
- "mcp__chromex__chromex_perf"
321
- ]
322
- }
323
- }
384
+ Suppress with `--no-snap` for scripts doing rapid sequential actions:
385
+
386
+ ```bash
387
+ chromex fill <target> @e1 "user@test.com" --no-snap
388
+ chromex fill <target> @e2 "secret123" --no-snap
389
+ chromex click <target> @e3 # Only this one triggers snapshot
324
390
  ```
325
391
 
326
- ### Why MCP over CLI?
392
+ ## MCP vs CLI
327
393
 
328
- | | CLI (Bash) | MCP Server |
394
+ Both interfaces call the same core, same daemons, same commands. The difference is how they integrate with Claude Code.
395
+
396
+ | | CLI (`chromex-cli`) | MCP Server (`chromex-mcp`) |
329
397
  |---|---|---|
330
- | Auto-approve | Fragile glob pattern | `"mcp__chromex"` -- one line |
398
+ | Token overhead | Zero schema cost | ~500 tokens per tool used (deferred loading) |
399
+ | Auto-approve | Glob pattern in settings | `"mcp__chromex"` -- one line |
331
400
  | Permissions | All-or-nothing | Per-tool granularity |
332
401
  | Parameters | Positional string args | Typed JSON Schema |
333
- | Annotations | None | `readOnlyHint`, `destructiveHint` |
334
- | Token cost | ~60-80 overhead/call | ~15-25 overhead/call |
335
- | Screenshots | Returns file path | Returns inline image (base64) |
402
+ | Screenshots | File path (needs `Read` to view) | Inline image (base64, no extra call) |
403
+ | Best for | Terminal, scripts, CI/CD, token-sensitive sessions | Plug-and-play automation, users who want zero-config |
404
+
405
+ ### Switching Between MCP and CLI
336
406
 
337
- The CLI still works and is useful for terminal, scripts, and CI/CD. The MCP server is the recommended interface for Claude Code.
407
+ You can enable and disable the MCP server at any time. The CLI always works regardless.
338
408
 
339
- ### npm
409
+ **Disable MCP** (saves ~3-5k tokens per session):
340
410
 
341
411
  ```bash
342
- npm install -g chromex-mcp # Global install
343
- chromex-mcp # Run MCP server
344
- chromex-cli list # CLI also available
412
+ claude mcp remove chromex
345
413
  ```
346
414
 
347
- ## Auto-Approve for CLI (Alternative)
415
+ The CLI (`chromex-cli`) continues working normally -- same commands, same daemons, no change.
416
+
417
+ **Re-enable MCP:**
418
+
419
+ ```bash
420
+ # Global (all projects)
421
+ claude mcp add chromex -s user npx chromex-mcp@latest
422
+
423
+ # Project-only
424
+ claude mcp add chromex npx chromex-mcp@latest
425
+ ```
426
+
427
+ **When to disable MCP:**
428
+ - Token-sensitive sessions where every token counts
429
+ - You only need occasional commands (`list`, `snap`, `shot`)
430
+ - You're already comfortable with the CLI syntax
431
+ - You're using chromex from terminal/scripts, not from Claude Code
432
+
433
+ **When to keep MCP enabled:**
434
+ - Automating multi-step browser workflows (snap -> click -> fill -> snap)
435
+ - You want per-tool auto-approve without glob patterns
436
+ - You want inline screenshots without a separate `Read` call
437
+ - First time using chromex (discovery via tool schema)
438
+
439
+ ### CLI Auto-Approve
348
440
 
349
441
  If you prefer the CLI interface, add this to `~/.claude/settings.json`:
350
442
 
@@ -352,14 +444,12 @@ If you prefer the CLI interface, add this to `~/.claude/settings.json`:
352
444
  {
353
445
  "permissions": {
354
446
  "allow": [
355
- "Bash(node *chromex/scripts/chromex.mjs *)"
447
+ "Bash(chromex-cli *)"
356
448
  ]
357
449
  }
358
450
  }
359
451
  ```
360
452
 
361
- > **Warning:** This approves all chromex commands without distinction. The security config (`~/.chromex/config.json`) still applies -- domain filtering, CDP blocklist, and audit log remain active.
362
-
363
453
  ## Security
364
454
 
365
455
  Config at `~/.chromex/config.json` (auto-created on first run):
@@ -376,11 +466,26 @@ Config at `~/.chromex/config.json` (auto-created on first run):
376
466
 
377
467
  - **Domain filtering**: block sensitive sites or restrict to a whitelist
378
468
  - **CDP blocklist**: dangerous methods blocked by default in `evalraw`
379
- - **Socket auth**: 32-byte random token per session
469
+ - **Socket auth**: 32-byte random token per session (mode 0600)
380
470
  - **Audit log**: every command logged with timestamp and status
381
471
 
382
472
  See [docs/security.md](docs/security.md) for full details.
383
473
 
474
+ ## How It Works
475
+
476
+ 1. **Browser detection** -- scans ~30 paths for `DevToolsActivePort` (or use `CDP_PORT_FILE` env var)
477
+ 2. **Daemon spawn** -- first command to a tab spawns a background Node.js process connected via CDP WebSocket
478
+ 3. **Session persistence** -- daemon holds the session open; Chrome's "Allow" modal fires once per daemon
479
+ 4. **Unix sockets** -- CLI/MCP communicates with daemon via authenticated Unix sockets
480
+ 5. **Auto-exit** -- daemons shut down after 20 minutes of inactivity (configurable)
481
+
482
+ ```
483
+ CLI Client ──Unix Socket + Auth──> Per-Tab Daemon ──CDP WebSocket──> Chrome
484
+ MCP Server ──Unix Socket + Auth──> (same) ──CDP WebSocket──> Chrome
485
+ ```
486
+
487
+ See [docs/architecture.md](docs/architecture.md) for the full deep dive.
488
+
384
489
  ## Documentation
385
490
 
386
491
  | Guide | Description |
@@ -396,16 +501,6 @@ See [docs/security.md](docs/security.md) for full details.
396
501
  | [Advanced](docs/advanced.md) | Script injection, code coverage, tracing, heap snapshots, WebAuthn |
397
502
  | [Architecture](docs/architecture.md) | How it works: daemon model, connection modes, file layout |
398
503
 
399
- ## How It Works
400
-
401
- 1. **Browser detection** -- scans ~30 paths for `DevToolsActivePort` (or use `CDP_PORT_FILE` env var)
402
- 2. **Daemon spawn** -- first command to a tab spawns a background Node.js process connected via CDP WebSocket
403
- 3. **Session persistence** -- daemon holds the session open; Chrome's "Allow" modal fires once per daemon
404
- 4. **Unix sockets** -- CLI communicates with daemon via authenticated Unix sockets
405
- 5. **Auto-exit** -- daemons shut down after 20 minutes of inactivity (configurable)
406
-
407
- See [docs/architecture.md](docs/architecture.md) for the full deep dive.
408
-
409
504
  ## License
410
505
 
411
506
  MIT
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import '../plugins/chromex/skills/chromex/scripts/chromex.mjs';
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "chromex-mcp",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Zero-dependency Chrome DevTools Protocol MCP server for AI agents. 52 typed tools, per-tab daemons, security hardened.",
5
5
  "type": "module",
6
6
  "bin": {
7
+ "chromex": "./bin/chromex.mjs",
7
8
  "chromex-mcp": "./bin/chromex-mcp.mjs",
8
9
  "chromex-cli": "./bin/chromex-cli.mjs"
9
10
  },