chromex-mcp 1.5.0 → 1.7.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.
Files changed (28) hide show
  1. package/README.md +472 -471
  2. package/package.json +4 -3
  3. package/plugins/chromex/skills/chromex/scripts/chromex.mjs +321 -37
  4. package/plugins/chromex/skills/chromex/scripts/lib/artifacts.mjs +55 -0
  5. package/plugins/chromex/skills/chromex/scripts/lib/browser.mjs +9 -7
  6. package/plugins/chromex/skills/chromex/scripts/lib/commands/app.mjs +558 -0
  7. package/plugins/chromex/skills/chromex/scripts/lib/commands/audit.mjs +2 -1
  8. package/plugins/chromex/skills/chromex/scripts/lib/commands/doctor.mjs +55 -0
  9. package/plugins/chromex/skills/chromex/scripts/lib/commands/download.mjs +3 -1
  10. package/plugins/chromex/skills/chromex/scripts/lib/commands/evidence.mjs +284 -0
  11. package/plugins/chromex/skills/chromex/scripts/lib/commands/har.mjs +2 -1
  12. package/plugins/chromex/skills/chromex/scripts/lib/commands/heap.mjs +2 -1
  13. package/plugins/chromex/skills/chromex/scripts/lib/commands/intercept.mjs +131 -37
  14. package/plugins/chromex/skills/chromex/scripts/lib/commands/locator.mjs +173 -0
  15. package/plugins/chromex/skills/chromex/scripts/lib/commands/pdf.mjs +2 -1
  16. package/plugins/chromex/skills/chromex/scripts/lib/commands/screenshot.mjs +5 -3
  17. package/plugins/chromex/skills/chromex/scripts/lib/commands/show.mjs +308 -0
  18. package/plugins/chromex/skills/chromex/scripts/lib/commands/snapshot.mjs +39 -3
  19. package/plugins/chromex/skills/chromex/scripts/lib/commands/state.mjs +86 -0
  20. package/plugins/chromex/skills/chromex/scripts/lib/commands/stats.mjs +4 -2
  21. package/plugins/chromex/skills/chromex/scripts/lib/commands/storage.mjs +8 -1
  22. package/plugins/chromex/skills/chromex/scripts/lib/commands/tab.mjs +6 -1
  23. package/plugins/chromex/skills/chromex/scripts/lib/commands/trace.mjs +2 -1
  24. package/plugins/chromex/skills/chromex/scripts/lib/config.mjs +6 -1
  25. package/plugins/chromex/skills/chromex/scripts/lib/daemon.mjs +106 -15
  26. package/plugins/chromex/skills/chromex/scripts/lib/launcher.mjs +14 -7
  27. package/plugins/chromex/skills/chromex/scripts/lib/sessions.mjs +92 -0
  28. package/plugins/chromex/skills/chromex/scripts/mcp-server.mjs +231 -8
package/README.md CHANGED
@@ -1,657 +1,658 @@
1
1
  # Chromex
2
2
 
3
- Zero-dependency Chrome DevTools Protocol toolkit for AI agents. 56 typed MCP tools + CLI. Connects directly to Chrome, Brave, Edge, or Chromium via WebSocket. No Puppeteer, no bloat.
4
-
5
- Designed from the ground up for token efficiency: incremental diffs, query-filtered snapshots, ref-based selection, and a plain-text output format that consistently beats JSON and YAML-style structured alternatives by 25% to 126% in head-to-head token measurements (see [Token Efficiency](#token-efficiency) below).
6
-
7
- ## Features
8
-
9
- - **56 MCP tools** -- typed JSON Schema, annotations (`readOnlyHint`, `destructiveHint`), inline screenshots (base64)
10
- - **Zero dependencies** -- uses only Node.js 22+ built-in modules (WebSocket, fs, net, crypto)
11
- - **Ref-based selection** -- `snap --refs` assigns `@e1`, `@e2`... to interactive elements, then `click @e5` or `fill @e3 "value"`. No fragile CSS selectors
12
- - **Incremental snapshots** -- second snapshot returns only changed nodes (diff), reducing output from thousands of lines to just what changed
13
- - **Query-filtered snapshots** -- `snap --query=login` returns only matching nodes and their ancestors, cutting output by 95% to 99% on large pages like GitHub, Jira, or Gmail
14
- - **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
15
- - **Contextual hints** -- after each action, chromex appends up to 3 `help[]` next-step suggestions picked from the current ref map, eliminating the "what do I do next" turn. Opt-out with `--no-hints`
16
- - **Pre-computed aggregates** -- `net` and `console` outputs embed counters (`network[47] errors:3 pending:0 ok:44`, `console[12] errors:2 warnings:4 info:6`) so the agent never needs a follow-up count
17
- - **Scroll detection** -- snapshots report scrollable containers with remaining distance (`[scroll: page: down:1200px | sidebar: up:300px]`)
18
- - **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
19
- - **Security hardened** -- domain filtering (allow/blocklist), CDP method blocklist, token-authenticated sockets, full audit log
20
- - **Multi-browser** -- auto-detects Brave, Chrome, Chrome Canary, Chromium, Edge, Vivaldi (macOS + Linux)
21
- - **Network control** -- throttle to 3G/offline, intercept & mock requests, record HAR files
22
- - **Form filling** -- fill inputs, select dropdowns, toggle checkboxes, upload files, batch fill entire forms. Works with React/Vue/Angular
23
- - **Browser launcher** -- launch browser with remote debugging pre-enabled (skips the "Allow debugging" modal entirely)
24
- - **CLI included** -- same commands available from the terminal for scripts and CI/CD
3
+ [![npm version](https://img.shields.io/npm/v/chromex-mcp.svg)](https://www.npmjs.com/package/chromex-mcp)
4
+ [![Node.js 22+](https://img.shields.io/badge/node-%3E%3D22.0.0-brightgreen.svg)](https://nodejs.org/)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
+
7
+ Chromex is a zero-dependency Chrome DevTools Protocol toolkit for AI agents. It connects directly to Chrome, Brave, Edge, Chromium, and Vivaldi through CDP, exposing a token-efficient CLI and an optional MCP server with 78 typed tools.
8
+
9
+ Use Chromex when an agent needs to inspect pages, take screenshots, navigate, click, fill forms, read console/network activity, emulate devices, throttle network/CPU, export PDFs, or run browser diagnostics without pulling in heavy browser automation runtimes.
10
+
11
+ ## Why Chromex
12
+
13
+ - **CLI-first for lower token usage**: terminal commands return compact plain text and avoid MCP tool-schema overhead.
14
+ - **Optional MCP server**: 78 typed tools for Claude Code and other MCP clients when tool discovery, typed parameters, and inline screenshots matter more than token budget.
15
+ - **No runtime dependencies**: Node.js 22+ built-ins only, including native WebSocket support.
16
+ - **Agent-friendly page model**: accessibility snapshots, `@eN` refs, incremental diffs, query filters, auto-snapshots, and contextual hints.
17
+ - **Persistent per-tab daemons**: one CDP session per tab, held open through an authenticated Unix socket.
18
+ - **Security controls**: domain allow/block lists, CDP method blocklist, socket auth, command timeouts, and audit logs.
19
+ - **Local by default**: no hosted service, no telemetry client, no bundled browser download, and session stats stay on your machine.
20
+
21
+ ## What You Can Do Today
22
+
23
+ - Inspect and automate real logged-in browser sessions, not only fresh headless test contexts.
24
+ - Use `--raw` and `--json` for stable pipes, CI, MCP wrappers, and agent-to-agent integrations.
25
+ - Create named sessions with isolated browser contexts, reusable targets, and local session dashboards.
26
+ - Read page state through compact accessibility snapshots, filtered snapshots, DOM snapshots, HTML, screenshots, and highlighted elements.
27
+ - Act on UI through refs, CSS selectors, coordinates, keyboard input, forms, uploads, drag and drop, touch gestures, dialogs, and load-more loops.
28
+ - Debug production behavior with console history, network request details, response bodies, HAR export, request blocking, API mocking, throttling, and offline mode.
29
+ - Test browser conditions with device presets, viewport resizing, DPR, geolocation, timezone, locale, CPU throttling, incognito contexts, proxies, and custom Chrome flags.
30
+ - Diagnose performance and quality with Core Web Vitals, transfer size, DOM/memory counters, Lighthouse audits, JS/CSS coverage, Chrome traces, and heap snapshots.
31
+ - Build evidence packs with screenshots, snapshots, HTML, console, network timeline, action timeline, and replay HTML.
32
+ - Validate modern browser flows such as passkey/WebAuthn registration and login, downloads, cookies, portable storage state, PDF export, and isolated profiles.
33
+ - Inspect Application panel state from the terminal: origin quota, storage usage breakdown, Cache Storage entries/bodies, IndexedDB schemas/rows, and Service Worker registrations.
34
+ - Turn `@eN` refs into locators and optional `chromex-test` action code.
35
+
36
+ ## Positioning
37
+
38
+ Chromex is a direct CDP layer for coding agents. It sits between raw Chrome DevTools Protocol and heavier browser automation frameworks.
39
+
40
+ | Alternative | Trade-off | Chromex angle |
41
+ |-------------|-----------|---------------|
42
+ | Raw CDP WebSocket | Maximum browser power, but too verbose for agents. | Compact commands, refs, snapshots, and safety defaults. |
43
+ | Heavy browser automation libraries | Excellent automation frameworks, but they add dependencies and framework-level abstractions. | Zero-runtime-dependency CLI/MCP that talks to your existing Chromium browser. |
44
+ | Browser MCP only | Easy tool discovery, but tool schemas and structured responses add token cost. | CLI-first for cheap agent loops, MCP when typed tools are worth the overhead. |
45
+ | Manual DevTools | Great for humans, not scriptable enough for agents. | DevTools-grade inspection exposed as terminal and MCP commands. |
25
46
 
26
47
  ## Requirements
27
48
 
28
- - Node.js 22+ (for built-in WebSocket)
29
- - Any Chromium-based browser
49
+ - Node.js 22 or newer.
50
+ - macOS or Linux.
51
+ - A Chromium-based browser: Chrome, Brave, Edge, Chromium, Chrome Canary, or Vivaldi.
30
52
 
31
- ## Installation
53
+ ## Zero-Dependency Boundary
32
54
 
33
- ```bash
34
- # Add to Claude Code (global -- all projects)
35
- claude mcp add chromex -s user npx chromex-mcp@latest
55
+ The core runtime uses only Node.js built-in modules. Chromex does not install heavy browser automation runtimes, Selenium, browser drivers, telemetry SDKs, update checkers, or bundled browsers.
36
56
 
37
- # Or project-only
38
- claude mcp add chromex npx chromex-mcp@latest
39
- ```
57
+ The only exception is the optional `audit` command: it shells out to Lighthouse with `npx --yes lighthouse` when you explicitly run an audit. All other CLI and MCP commands run through Chromex's own CDP client.
40
58
 
41
- ### Auto-Approve (recommended)
59
+ Development dependencies are used only for tests and token benchmarks.
42
60
 
43
- Add to `~/.claude/settings.json`:
61
+ ## Browser Setup
44
62
 
45
- ```json
46
- {
47
- "permissions": {
48
- "allow": ["mcp__chromex"]
49
- }
50
- }
63
+ Chromex needs Chrome DevTools Protocol access to your browser. Choose one of the two connection modes below before using the CLI or MCP server.
64
+
65
+ ### Option A: Launch a Browser with Chromex
66
+
67
+ This is the recommended first-time setup. Chromex starts a new browser process with remote debugging already enabled, so there is no manual browser configuration and no "Allow debugging" prompt.
68
+
69
+ ```bash
70
+ chromex launch --url https://example.com
51
71
  ```
52
72
 
53
- This approves all 56 MCP tools at once. For granular control, approve individual tools:
73
+ Useful launch variants:
54
74
 
55
- ```json
56
- {
57
- "permissions": {
58
- "allow": [
59
- "mcp__chromex__chromex_list",
60
- "mcp__chromex__chromex_snapshot",
61
- "mcp__chromex__chromex_screenshot",
62
- "mcp__chromex__chromex_perf"
63
- ]
64
- }
65
- }
75
+ ```bash
76
+ chromex launch --browser brave --url https://example.com
77
+ chromex launch --profile testing --url https://example.com
78
+ chromex launch --incognito --browser chrome
79
+ chromex launch --headless --url https://example.com
80
+ chromex launch --browser-path "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary"
66
81
  ```
67
82
 
68
- ### Global install (optional)
83
+ Named profiles are stored under `~/.chromex/profiles/` and keep test sessions isolated from your daily browser profile.
84
+
85
+ Chrome for Testing also works well with Chromex. Download it manually from Google's official Chrome for Testing channel, then point Chromex at the executable with `--browser-path` or `CHROMEX_BROWSER_PATH`. Chromex does not download or bundle a browser.
86
+
87
+ ### Option B: Connect to an Already-Running Browser
88
+
89
+ Use this when you want Chromex to inspect tabs that are already open in your normal browser.
90
+
91
+ 1. Open Chrome, Brave, Edge, Chromium, or Vivaldi.
92
+ 2. Go to `chrome://inspect/#remote-debugging`.
93
+ 3. Enable the remote debugging switch.
94
+ 4. Run `chromex list` to verify that tabs are visible.
69
95
 
70
96
  ```bash
71
- npm install -g chromex-mcp
97
+ chromex list
72
98
  ```
73
99
 
74
- This installs three binaries:
100
+ Important notes:
75
101
 
76
- | Binary | Purpose |
77
- |--------|---------|
78
- | `chromex` | CLI -- the main command for terminal usage |
79
- | `chromex-cli` | Alias for `chromex` |
80
- | `chromex-mcp` | MCP server (stdio JSON-RPC) -- used by `claude mcp add`, not run directly |
102
+ - Without remote debugging enabled, Chromex cannot discover or control your open tabs.
103
+ - The browser setting is usually persistent across restarts.
104
+ - The first command that attaches to a tab may show an "Allow debugging" prompt. Accept it once for that tab; Chromex keeps the daemon session alive after that.
105
+
106
+ If your browser uses a custom profile or a non-standard `DevToolsActivePort` location, set:
81
107
 
82
108
  ```bash
83
- chromex list # List open tabs
84
- chromex launch --url https://example.com # Launch browser
85
- chromex snap 6BE8 --refs # Snapshot with refs
86
- chromex click 6BE8 @e3 # Click by ref
109
+ export CDP_PORT_FILE=/path/to/DevToolsActivePort
87
110
  ```
88
111
 
89
- ## Connect to Your Browser
112
+ If your Chromium executable is installed in a non-standard location, either pass `--browser-path` to `chromex launch` or set:
90
113
 
91
- **Option A: Launch a new browser** (recommended -- no setup needed)
114
+ ```bash
115
+ export CHROMEX_BROWSER_PATH=/path/to/chrome
116
+ ```
117
+
118
+ Run the local diagnostic command whenever browser discovery or CDP connection fails:
92
119
 
93
120
  ```bash
94
- chromex launch --url https://example.com
121
+ chromex doctor
95
122
  ```
96
123
 
97
- This starts Chrome/Brave/Edge with remote debugging pre-enabled. No manual configuration required.
124
+ ## Install the CLI
98
125
 
99
- **Option B: Connect to an already-running browser**
126
+ Install the package globally to get the `chromex` command.
100
127
 
101
- 1. Open your browser (Chrome, Brave, Edge, etc.)
102
- 2. Navigate to `chrome://inspect/#remote-debugging`
103
- 3. **Toggle the switch ON** to enable remote debugging
104
- 4. Run `chromex list` to verify the connection
128
+ ```bash
129
+ # npm
130
+ npm install -g chromex-mcp
105
131
 
106
- > **Important:** Without step 3, chromex cannot connect to your browser. This is a one-time setup -- the setting persists across browser restarts.
132
+ # Bun
133
+ bun add -g chromex-mcp
134
+ ```
107
135
 
108
- > **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.
136
+ The package installs three binaries:
109
137
 
110
- ## Quick Start
138
+ | Binary | Purpose |
139
+ |--------|---------|
140
+ | `chromex` | Main CLI for terminal, scripts, CI, and token-sensitive agent sessions. |
141
+ | `chromex-cli` | Alias for `chromex`. |
142
+ | `chromex-mcp` | MCP server over stdio JSON-RPC. Usually launched by an MCP client. |
143
+
144
+ ## CLI Quick Start
145
+
146
+ The CLI is the recommended interface when token budget matters. It has no MCP schema overhead, works well in scripts, and returns compact plain-text output designed for LLM agents.
111
147
 
112
148
  ```bash
113
- # List open tabs
114
- chromex list
115
- # Output: 6BE827FA Example Domain https://example.com
149
+ # 1. Launch or connect to a browser.
150
+ chromex launch --url https://github.com/login
116
151
 
117
- # Take a screenshot
118
- chromex shot 6BE8 /tmp/page.png
152
+ # 2. List tabs and copy a target prefix.
153
+ chromex list
154
+ # 6BE827FA Sign in to GitHub https://github.com/login
119
155
 
120
- # Get the accessibility tree with interactive refs
156
+ # 3. Read the page through the accessibility tree and assign refs.
121
157
  chromex snap 6BE8 --refs
122
- # Output:
123
- # @e1 [textbox] Email
124
- # @e2 [textbox] Password
125
- # @e3 [button] Sign in
158
+ # @e1 [textbox] Username or email address
159
+ # @e2 [textbox] Password
160
+ # @e3 [button] Sign in
126
161
 
127
- # Fill a form using refs (no CSS selectors needed!)
162
+ # 4. Interact by ref instead of fragile CSS selectors.
128
163
  chromex fill 6BE8 @e1 "user@example.com"
129
- chromex fill 6BE8 @e2 "secret123"
164
+ chromex fill 6BE8 @e2 "secret"
130
165
  chromex click 6BE8 @e3
131
166
 
132
- # Check Core Web Vitals
133
- chromex perf 6BE8
167
+ # 5. Inspect browser state.
168
+ chromex console 6BE8 list
169
+ chromex net 6BE8
170
+ chromex shot 6BE8
171
+ chromex app 6BE8
134
172
  ```
135
173
 
136
- ## Commands
137
-
138
- `<target>` is a unique prefix of the targetId shown by `list` (e.g. `6BE827FA`).
174
+ `<target>` is a unique prefix of the tab target ID returned by `chromex list`. If a prefix is ambiguous, Chromex rejects it and asks for more characters.
139
175
 
140
- ### Pages & Browser
176
+ For repeatable agent workflows, use named sessions instead of carrying target IDs manually:
141
177
 
142
178
  ```bash
143
- chromex list # List open pages
144
- chromex open "https://example.com" # Open new tab
145
- chromex close <target> # Close tab
146
- chromex focus <target> # Activate/focus tab
147
- chromex launch # Launch browser with debugging
148
- chromex launch --incognito --browser brave # Launch Brave in incognito
149
- chromex launch --headless --url https://example.com # Headless mode for CI/CD
150
- chromex launch --proxy socks5://localhost:1080 # Launch with proxy
151
- chromex launch --insecure # Ignore certificate errors
152
- chromex launch --chrome-arg --disable-web-security # Pass custom Chrome flag
153
- chromex launch --profile testing --url https://... # Isolated profile + URL
154
- chromex incognito https://example.com # Isolated context (no relaunch)
155
- chromex stop # Stop all daemons
179
+ chromex -s auth open https://github.com/login
180
+ chromex -s auth snap --refs
181
+ chromex -s auth fill @e1 "user@example.com"
182
+ chromex -s auth state save ~/.chromex/storage/auth.json
183
+ chromex sessions
156
184
  ```
157
185
 
158
- ### Inspect
186
+ ## Token-Efficient Agent Workflow
159
187
 
160
- ```bash
161
- chromex snap <target> # Accessibility tree snapshot (compact)
162
- chromex snap <target> --refs # With interactive refs (@e1, @e2...)
163
- chromex snap <target> --depth=3 # Limit tree depth
164
- chromex snap <target> --full # Force full snapshot (skip diff)
165
- chromex snap <target> --query=login # Filter to matching nodes + ancestors (hierarchy preserved)
166
- chromex html <target> "#main" # Element HTML by selector
167
- chromex shot <target> /tmp/page.png # Viewport screenshot
168
- chromex shot <target> /tmp/full.png --full # Full page screenshot
169
- chromex shot <target> --format=jpeg --quality=80 # JPEG/WebP with quality control
170
- chromex shot <target> @e5 # Screenshot of specific element by ref
171
- chromex net <target> # List network requests (CDP tracked)
172
- chromex net <target> <requestId> # Request detail: headers, timing, body
173
- chromex perf <target> # Core Web Vitals + memory + DOM stats
174
- chromex console <target> 5000 # Capture console.log/error for 5s
175
- chromex console <target> list # Show stored messages since daemon start
176
- chromex console <target> detail <id> # Message detail with stack trace
177
- chromex domsnapshot <target> # Structured DOM with bounding rects
178
- chromex domsnapshot <target> --styles # Include computed styles
179
- chromex highlight <target> "h1" # Highlight element with overlay
180
- chromex highlight <target> clear # Remove highlight
181
- ```
182
-
183
- ### Evaluate
184
-
185
- ```bash
186
- chromex eval <target> "document.title" # Run JS
187
- chromex eval <target> "document.querySelectorAll('a').length" # Count links
188
- chromex evalraw <target> "DOM.getDocument" # Raw CDP command
189
- chromex evalraw <target> "Page.getLayoutMetrics" # Layout info
190
- ```
191
-
192
- ### Navigate & Wait
193
-
194
- ```bash
195
- chromex nav <target> "https://example.com" # Navigate + wait for load
196
- chromex nav <target> back # Go back in history
197
- chromex nav <target> forward # Go forward in history
198
- chromex nav <target> reload # Reload page
199
- chromex nav <target> reload-hard # Reload ignoring cache
200
- chromex waitfor <target> ".results" 10000 # Wait for CSS selector (10s)
201
- chromex wait <target> networkidle # Wait for network idle
202
- chromex wait <target> load # Wait for page load
203
- chromex wait <target> domready # Wait for DOMContentLoaded
204
- chromex wait <target> fcp # Wait for First Contentful Paint
205
- chromex scroll <target> down 500 # Scroll down 500px
206
- chromex scroll <target> up 300 # Scroll up 300px
207
- chromex scroll <target> top # Scroll to top
208
- chromex scroll <target> bottom # Scroll to bottom
209
- chromex scroll <target> to "#footer" # Scroll to element
210
- ```
188
+ Chromex is optimized for agents that need to act on browser state without wasting context.
211
189
 
212
- ### Interact
190
+ 1. Start with `chromex list`.
191
+ 2. Prefer `chromex snap <target> --refs` over raw HTML.
192
+ 3. Use `@eN` refs for `click`, `fill`, `hover`, and element screenshots.
193
+ 4. On large pages, use `--query` before reading a full snapshot.
194
+ 5. Let auto-snapshot show post-action state after interactive commands.
195
+ 6. Add `--no-snap` only for fast scripted batches where you do not need immediate page state.
196
+ 7. Add `--no-hints` when another program parses output strictly.
197
+ 8. Use `--raw` for pipes and `--json` when another tool needs the stable envelope.
198
+ 9. Save large snapshots with `--filename` when they are better as artifacts than inline text.
199
+
200
+ Examples:
213
201
 
214
202
  ```bash
215
- chromex click <target> "button.submit" # Click by CSS selector
216
- chromex click <target> @e5 # Click by ref (from snap --refs)
217
- chromex click <target> @e5 --dbl # Double-click
218
- chromex clickxy <target> 100 200 # Click at CSS pixel coords
219
- chromex clickxy <target> 100 200 --dbl # Double-click at coords
220
- chromex key <target> Enter # Press key
221
- chromex key <target> "Control+A" # Key combination
222
- chromex key <target> "Control+Shift+R" # Multi-modifier combo
223
- chromex type <target> "hello world" # Type text (works cross-origin)
224
- chromex hover <target> @e12 # Hover element by ref
225
- chromex drag <target> "#source" "#dest" # Drag & drop by selector
226
- chromex drag <target> 100,200 400,500 # Drag & drop by coordinates
227
- chromex touch <target> tap 200 300 # Touch tap
228
- chromex touch <target> swipe 200,400 200,100 # Swipe gesture
229
- chromex touch <target> pinch 200 300 2.0 # Pinch zoom in
230
- chromex touch <target> longpress 200 300 1000 # Long press (1s)
231
- chromex dialog <target> accept # Accept alert/confirm
232
- chromex dialog <target> dismiss # Dismiss dialog
233
- chromex dialog <target> auto # Auto-accept all dialogs
234
- chromex loadall <target> ".load-more" 500 # Click until element disappears
203
+ chromex snap 6BE8 --query=login --refs
204
+ chromex click 6BE8 @e4
205
+ chromex wait 6BE8 networkidle
206
+ chromex snap 6BE8 --query=error
207
+ chromex --raw eval 6BE8 "document.title"
208
+ chromex list --json
209
+ chromex snap 6BE8 --filename=~/.chromex/snapshots/login.yml --boxes
210
+ chromex locator 6BE8 @e4 --format=chromex-test
211
+ chromex click 6BE8 @e4 --code=chromex-test
235
212
  ```
236
213
 
237
- ### Forms
214
+ ## MCP Server
238
215
 
239
- ```bash
240
- chromex fill <target> "#email" "user@test.com" # Fill input/textarea
241
- chromex fill <target> @e1 "user@test.com" # Fill by ref
242
- chromex clear <target> "#search" # Clear field
243
- chromex select <target> "#country" "BR" # Select dropdown option
244
- chromex check <target> "#terms" # Check checkbox
245
- chromex check <target> "#newsletter" false # Uncheck checkbox
246
- chromex upload <target> "#avatar" /tmp/photo.png # Upload file
216
+ Use MCP when you want Claude Code or another MCP client to discover typed browser tools directly. MCP is convenient, but it costs more tokens than CLI usage because tool schemas, JSON-RPC framing, and structured tool results add overhead.
247
217
 
248
- # Batch fill entire form
249
- chromex form <target> '{"#name":"John","#email":"john@test.com","#terms":true}'
250
- ```
218
+ ### Add to Claude Code
251
219
 
252
- ### Data
220
+ Global, available in all projects:
253
221
 
254
222
  ```bash
255
- chromex cookies <target> # List cookies
256
- chromex cookies <target> set '{"name":"x","value":"y"}' # Set cookie
257
- chromex cookies <target> clear # Clear all cookies
258
- chromex storage <target> local # Dump localStorage
259
- chromex storage <target> session # Dump sessionStorage
260
- chromex storage <target> clear # Clear both
261
- chromex pdf <target> /tmp/page.pdf # Export as PDF
223
+ # npm
224
+ claude mcp add chromex -s user npx chromex-mcp@latest
225
+
226
+ # Bun
227
+ claude mcp add chromex -s user bunx chromex-mcp@latest
262
228
  ```
263
229
 
264
- ### Network
230
+ Project-only:
265
231
 
266
232
  ```bash
267
- chromex throttle <target> 3g # Throttle to 3G
268
- chromex throttle <target> slow-3g # Throttle to slow 3G
269
- chromex throttle <target> 4g # Throttle to 4G
270
- chromex throttle <target> offline # Go offline
271
- chromex throttle <target> custom 200 1000 500 # Custom: latency, down, up (kbps)
272
- chromex throttle <target> reset # Remove throttling
273
-
274
- chromex intercept <target> block "*.analytics.*" # Block matching requests
275
- chromex intercept <target> mock "/api/user" '{"name":"test"}' # Mock response
276
- chromex intercept <target> rules # List active rules
277
- chromex intercept <target> off # Disable interception
233
+ # npm
234
+ claude mcp add chromex npx chromex-mcp@latest
278
235
 
279
- chromex har <target> start # Start recording
280
- chromex har <target> stop /tmp/trace.har # Save HAR file
236
+ # Bun
237
+ claude mcp add chromex bunx chromex-mcp@latest
281
238
  ```
282
239
 
283
- ### Emulate
240
+ After setup, the MCP client can call tools such as `chromex_list`, `chromex_snapshot`, `chromex_click`, `chromex_fill`, `chromex_screenshot`, `chromex_console`, `chromex_network`, `chromex_app_summary`, `chromex_cache_entries`, `chromex_indexeddb_rows`, `chromex_sessions`, `chromex_show`, `chromex_locator`, `chromex_state`, and `chromex_evidence`.
284
241
 
285
- ```bash
286
- chromex emulate <target> iphone-14 # 390x844 @3x mobile
287
- chromex emulate <target> iphone-15-pro # 393x852 @3x mobile
288
- chromex emulate <target> ipad-pro # 1024x1366 @2x tablet
289
- chromex emulate <target> pixel-7 # 412x915 @2.625x mobile
290
- chromex emulate <target> galaxy-s23 # 360x780 @3x mobile
291
- chromex emulate <target> macbook-air # 1440x900 @2x laptop
292
- chromex emulate <target> desktop-1080p # 1920x1080 @1x
293
- chromex emulate <target> desktop-4k # 3840x2160 @1x
294
- chromex emulate <target> reset # Reset to default
295
- chromex resize <target> 1280 720 # Custom viewport dimensions
296
- chromex resize <target> 1440 900 2 # Custom with DPR (retina)
297
- chromex geo <target> -23.55 -46.63 # Set geolocation (Sao Paulo)
298
- chromex geo <target> reset # Clear geolocation
299
- chromex timezone <target> "America/Sao_Paulo" # Set timezone
300
- chromex locale <target> "pt-BR" # Set locale
301
- chromex cpu <target> 4 # CPU 4x slower
302
- chromex cpu <target> reset # Reset CPU speed
303
- ```
242
+ Tools that produce machine-readable data or artifacts also include MCP `structuredContent`, so agents can read paths and metadata without parsing the human text block.
304
243
 
305
- ### Advanced
244
+ ### Claude Code Auto-Approve
306
245
 
307
- ```bash
308
- chromex inject <target> "window.DEBUG=true" # Inject JS on every page load
309
- chromex inject <target> --file /tmp/preload.js # Inject from file
310
- chromex inject <target> --list # List injected scripts
311
- chromex inject <target> --remove <id> # Remove injected script
312
- chromex download <target> allow /tmp/downloads # Auto-accept downloads
313
- chromex download <target> deny # Block downloads
314
- chromex coverage <target> start # Start code coverage
315
- chromex coverage <target> stop # Coverage report (JS + CSS %)
316
- chromex trace <target> start # Start performance trace
317
- chromex trace <target> stop /tmp/trace.json # Save trace (chrome://tracing)
318
- chromex heap <target> snapshot /tmp/heap.hs # Heap snapshot (memory analysis)
319
- chromex webauthn <target> enable # Virtual authenticator (passkeys)
320
- chromex webauthn <target> creds # List stored credentials
321
- chromex webauthn <target> disable # Remove authenticator
246
+ To approve all Chromex MCP tools at once, add this to `~/.claude/settings.json`:
247
+
248
+ ```json
249
+ {
250
+ "permissions": {
251
+ "allow": ["mcp__chromex"]
252
+ }
253
+ }
322
254
  ```
323
255
 
324
- ### Audit & Analytics
256
+ For CLI usage inside Claude Code, approve the shell command instead:
325
257
 
326
- ```bash
327
- chromex audit <target> # Full Lighthouse audit (all categories)
328
- chromex audit <target> performance,seo # Specific categories
329
- chromex audit <target> accessibility desktop # Accessibility on desktop
330
- chromex stats <target> # Session analytics (command counts, timing)
331
- chromex stats <target> --full # Full action timeline
332
- chromex stats <target> --reset # Reset counters
333
- chromex stats <target> --export=/tmp/stats.json # Export as JSON
258
+ ```json
259
+ {
260
+ "permissions": {
261
+ "allow": [
262
+ "Bash(chromex *)",
263
+ "Bash(chromex-cli *)"
264
+ ]
265
+ }
266
+ }
334
267
  ```
335
268
 
336
- ## Ref-Based Selection
269
+ Review these permissions before enabling them. Chromex security settings still apply, and every command is audit-logged when `auditLog` is enabled.
270
+
271
+ ## CLI vs MCP
272
+
273
+ Both interfaces use the same CDP core and the same per-tab daemons. Choose based on the workflow.
337
274
 
338
- The killer feature for AI agents. Instead of fragile CSS selectors, use numbered refs:
275
+ | Use case | Prefer CLI | Prefer MCP |
276
+ |----------|------------|------------|
277
+ | Token-sensitive agent sessions | Yes | No |
278
+ | Terminal scripts and CI | Yes | No |
279
+ | Quick one-off browser inspection | Yes | Optional |
280
+ | Typed tool discovery in Claude Code | No | Yes |
281
+ | Inline screenshots returned to the client | No, screenshots are files | Yes |
282
+ | Granular per-tool permissions | Shell pattern only | Yes |
283
+ | Lowest setup friction for MCP users | Optional | Yes |
284
+
285
+ You can remove MCP at any time and keep using the CLI:
339
286
 
340
287
  ```bash
341
- # 1. Get interactive elements with refs
342
- chromex snap <target> --refs
343
- # Output:
344
- # @e1 [textbox] Username
345
- # @e2 [textbox] Password
346
- # @e3 [checkbox] Remember me
347
- # @e4 [button] Sign in
348
- # @e5 [link] Forgot password?
349
-
350
- # 2. Interact using refs
351
- chromex fill <target> @e1 "admin"
352
- chromex fill <target> @e2 "secret123"
353
- chromex click <target> @e3
354
- chromex click <target> @e4
288
+ claude mcp remove chromex
355
289
  ```
356
290
 
357
- 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.
358
-
359
- Supported ref commands: `click @eN`, `fill @eN "value"`, `hover @eN`.
291
+ ## Command Overview
360
292
 
361
- ## Snapshot Optimizations
293
+ ### Pages and Browser
362
294
 
363
- Chromex snapshots are designed to minimize token usage for AI agents.
295
+ ```bash
296
+ chromex list
297
+ chromex open "https://example.com"
298
+ chromex -s auth open "https://example.com/login"
299
+ chromex -s auth snap --refs
300
+ chromex sessions
301
+ chromex show --annotate
302
+ chromex close <target>
303
+ chromex focus <target>
304
+ chromex launch --url https://example.com
305
+ chromex launch --browser brave --incognito
306
+ chromex launch --headless --url https://example.com
307
+ chromex launch --browser-path /path/to/chrome --url https://example.com
308
+ chromex doctor
309
+ chromex incognito https://example.com
310
+ chromex stop
311
+ ```
364
312
 
365
- ### Incremental Diff
313
+ ### Inspect
366
314
 
367
- The first snapshot returns the full accessibility tree. Subsequent snapshots return only nodes that changed:
315
+ ```bash
316
+ chromex snap <target> --refs
317
+ chromex snap <target> --query=login
318
+ chromex snap <target> --filename=~/.chromex/snapshots/login.yml --boxes
319
+ chromex html <target> "#main"
320
+ chromex shot <target>
321
+ chromex shot <target> ~/.chromex/screenshots/full.png --full
322
+ chromex shot <target> @e5
323
+ chromex console <target> list
324
+ chromex net <target>
325
+ chromex perf <target>
326
+ chromex domsnapshot <target> --styles
327
+ chromex evidence <target> start checkout-flow
328
+ chromex evidence <target> mark "after login"
329
+ chromex evidence <target> stop
330
+ chromex evidence <target> replay
331
+ ```
332
+
333
+ ### Navigate and Wait
368
334
 
369
- ```
370
- [incremental: 2 changed, 45 unchanged]
371
- *[textbox] Email = "user@example.com"
372
- *[button] Submit
335
+ ```bash
336
+ chromex nav <target> "https://example.com"
337
+ chromex nav <target> back
338
+ chromex nav <target> reload-hard
339
+ chromex waitfor <target> ".results" 10000
340
+ chromex wait <target> networkidle
341
+ chromex scroll <target> bottom
373
342
  ```
374
343
 
375
- - Changed/new nodes are marked with `*`
376
- - Unchanged subtrees are collapsed entirely
377
- - Use `--full` to force a full snapshot (skips diff)
378
- - Navigation (`nav`) resets the diff baseline automatically
344
+ ### Interact
379
345
 
380
- ### Depth Limiting
346
+ ```bash
347
+ chromex click <target> @e5
348
+ chromex clickxy <target> 100 200
349
+ chromex key <target> Enter
350
+ chromex type <target> "hello world"
351
+ chromex hover <target> @e12
352
+ chromex locator <target> @e12 --format=chromex-test
353
+ chromex click <target> @e12 --code=chromex-test
354
+ chromex drag <target> "#source" "#dest"
355
+ chromex dialog <target> accept
356
+ ```
381
357
 
382
- Limit tree depth for large pages:
358
+ ### Forms
383
359
 
384
360
  ```bash
385
- chromex snap <target> --depth=3 # Only 3 levels deep
361
+ chromex fill <target> @e1 "user@example.com"
362
+ chromex clear <target> "#search"
363
+ chromex select <target> "#country" "BR"
364
+ chromex check <target> "#terms" true
365
+ chromex upload <target> "#avatar" /tmp/photo.png
366
+ chromex form <target> '{"#name":"John","#email":"john@example.com","#terms":true}'
386
367
  ```
387
368
 
388
- Nodes at the depth limit render as leaves (children are not expanded).
389
-
390
- ### Query Filter
369
+ ### Data
391
370
 
392
- On large pages, a full accessibility tree can be tens of kilobytes. Use `--query` to keep only the nodes you care about, with their ancestors preserved so the hierarchy stays intact:
371
+ ```bash
372
+ chromex cookies <target>
373
+ chromex cookies <target> set '{"name":"token","value":"abc"}'
374
+ chromex storage <target> local
375
+ chromex storage <target> session
376
+ chromex storage <target> usage
377
+ chromex state <target> save ~/.chromex/storage/auth.json
378
+ chromex state <target> load ~/.chromex/storage/auth.json
379
+ chromex app <target> summary
380
+ chromex sw <target>
381
+ chromex cache <target> list
382
+ chromex cache <target> entries <cacheId> --query=/api
383
+ chromex idb <target> list
384
+ chromex idb <target> schema <databaseName>
385
+ chromex idb <target> rows <databaseName> <objectStoreName> --limit=20
386
+ chromex pdf <target>
387
+ ```
388
+
389
+ ### Network, Emulation, and Diagnostics
393
390
 
394
391
  ```bash
395
- chromex snap <target> --query=login # Substring match (case-insensitive)
396
- chromex snap <target> --query=issues # role/name/value all searched
392
+ chromex throttle <target> 3g
393
+ chromex intercept <target> block "*.analytics.*"
394
+ chromex intercept <target> mock "/api/user" --status=200 --content-type=application/json --body='{"ok":true}'
395
+ chromex intercept <target> mock "/api/slow" --delay=750 --status=503 --body='unavailable'
396
+ chromex intercept <target> block "*.tracker.*" --abort=blockedbyclient
397
+ chromex intercept <target> on --remove-header=authorization
398
+ chromex har <target> start
399
+ chromex har <target> stop ~/.chromex/har/trace.har
400
+ chromex emulate <target> iphone-15-pro
401
+ chromex resize <target> 1280 720
402
+ chromex geo <target> -23.55 -46.63
403
+ chromex timezone <target> "America/Sao_Paulo"
404
+ chromex cpu <target> 4
405
+ chromex audit <target> performance,accessibility desktop
406
+ chromex stats <target> --full
397
407
  ```
398
408
 
399
- Matched nodes are prefixed with `>` in the output, so the agent can spot them at a glance. Ancestor chains are included from the match up to the root, so the agent still understands the surrounding structure.
409
+ ### Advanced
400
410
 
401
- `@eN` refs stay stable across filtered and unfiltered calls because the ref map is always computed against the full tree. A filtered `snap --query=login` followed by a plain `snap --refs` returns the same ref numbering. Fingerprints for incremental diff are also computed on the full tree, so the next non-query snapshot still produces a correct diff against the previous state.
411
+ ```bash
412
+ chromex eval <target> "document.title"
413
+ chromex evalraw <target> "Page.getLayoutMetrics"
414
+ chromex inject <target> "window.DEBUG=true"
415
+ chromex download <target> allow ~/.chromex/downloads
416
+ chromex coverage <target> start
417
+ chromex trace <target> start
418
+ chromex heap <target> snapshot ~/.chromex/heap/heap.heapsnapshot
419
+ chromex webauthn <target> enable
420
+ ```
402
421
 
403
- Measured reduction on a real 65 KB GitHub repo page snapshot:
422
+ Run `chromex --help` for the full command reference.
404
423
 
405
- | Query | Output bytes | Reduction |
406
- |-------|-------------:|----------:|
407
- | `snap --full` (baseline) | 65,455 | -- |
408
- | `snap --query=issues` | 317 | **-99.5%** |
409
- | `snap --query=star` | 1,490 | **-97.7%** |
410
- | `snap --query=readme` | 936 | **-98.6%** |
424
+ ## Agent-Focused Features
411
425
 
412
- When no node matches, chromex returns the explicit empty state `snap: no matches for query "X"` so the agent never confuses an empty filter with a silent failure.
426
+ ### Ref-Based Selection
413
427
 
414
- ### Scroll Detection
428
+ `chromex snap --refs` assigns stable refs to interactive elements:
415
429
 
416
- Snapshots automatically detect scrollable containers and report remaining scroll distance:
430
+ ```bash
431
+ chromex snap <target> --refs
432
+ # @e1 [textbox] Email
433
+ # @e2 [textbox] Password
434
+ # @e3 [button] Sign in
417
435
 
436
+ chromex fill <target> @e1 "user@example.com"
437
+ chromex click <target> @e3
418
438
  ```
419
- [scroll: page: down:1200px | sidebar: up:300px, down:800px]
420
- ```
421
-
422
- ### Visibility Filtering
423
439
 
424
- - Ignored/hidden accessibility nodes are automatically omitted
425
- - Disabled interactive elements are shown but not assigned refs (can't be interacted with)
426
- - Generic wrapper nodes (`div`, `span` with no semantic role) are collapsed -- their children inherit the parent's depth
427
- - Names longer than 200 characters are truncated with `...`
440
+ Refs are shorter and more robust than CSS selectors for most agent workflows.
428
441
 
429
- ## Auto-Snapshot
442
+ ### Incremental Snapshots
430
443
 
431
- 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:
444
+ The first snapshot returns the page tree. Later snapshots return only changed nodes unless you pass `--full`.
432
445
 
433
446
  ```bash
447
+ chromex snap <target> --refs
434
448
  chromex click <target> @e3
435
- # Output:
436
- # Clicked @e3 [button] "Submit"
437
- #
438
- # [incremental: 5 changed, 40 unchanged]
439
- # @e1 [heading] Thank you!
440
- # @e2 [link] Back to home
441
- # ...
449
+ # The click response includes a fresh incremental snapshot with refs.
442
450
  ```
443
451
 
444
- Commands that trigger auto-snapshot: `click`, `clickxy`, `type`, `key`, `fill`, `clear`, `select`, `check`, `form`, `nav`, `dialog`, `loadall`, `drag`, `touch`, `upload`.
452
+ ### Query-Filtered Snapshots
445
453
 
446
- Suppress with `--no-snap` for scripts doing rapid sequential actions:
454
+ Use `--query` to keep output small on large pages:
447
455
 
448
456
  ```bash
449
- chromex fill <target> @e1 "user@test.com" --no-snap
450
- chromex fill <target> @e2 "secret123" --no-snap
451
- chromex click <target> @e3 # Only this one triggers snapshot
457
+ chromex snap <target> --query=issues --refs
458
+ chromex snap <target> --query="sign in" --refs
452
459
  ```
453
460
 
454
- ## Contextual Hints
455
-
456
- After any action that produces a fresh ref map (auto-snap on interactive commands, or an explicit `snap --refs`), chromex appends a `help[N]:` block with up to 3 next-step suggestions picked heuristically from the current elements and the last command:
461
+ Chromex preserves ancestor nodes so the filtered output still has usable context.
457
462
 
458
- ```
459
- Navigated to https://github.com/login
463
+ ### Contextual Hints
460
464
 
461
- RootWebArea "Sign in to GitHub"
462
- @e1 [textbox] Username or email address
463
- @e2 [textbox] Password
464
- @e3 [button] Sign in
465
- @e4 [link] Forgot password?
465
+ After actions that refresh refs, Chromex can append a `help[N]:` block with likely next commands:
466
466
 
467
+ ```text
467
468
  help[3]:
468
- chromex fill <t> @e1 "<value>" # textbox "Username or email address"
469
+ chromex fill <t> @e1 "<value>" # textbox "Email"
469
470
  chromex click <t> @e3 # button "Sign in"
470
471
  chromex click <t> @e4 # link "Forgot password?"
471
472
  ```
472
473
 
473
- The agent gets the most probable next commands inline, eliminating the "decide what to click" turn. Heuristic rules:
474
-
475
- - **After `fill`** -- priority is a matching submit button (label matches `login`, `submit`, `send`, `search`, `go`, `continue`, ...) or `key Enter` fallback, then the next unfilled input.
476
- - **After `nav`** -- first input (highest priority), then first submit button, then first link.
477
- - **After `snap --refs`** (or any default) -- top interactive elements with non-empty names.
478
- - **Maximum 3 hints per response.**
479
-
480
- ### Staleness Guard
481
-
482
- Hints are only emitted when chromex can guarantee the ref map matches the DOM that was just rendered. This prevents the agent from clicking `@eN` coordinates that no longer exist on screen:
483
-
484
- | Command | Hints? | Why |
485
- |---------|--------|-----|
486
- | `click`, `fill`, `nav`, `type`, ... (default) | Yes | auto-snap just ran with refs |
487
- | `click @e1 --no-snap`, `fill ... --no-snap` | **No** | ref map may be stale |
488
- | `snap --refs` | Yes | ref map populated by this call |
489
- | `snap --refs` on a page with zero interactive elements | **No** | nothing to suggest, avoids a `snap --refs` loop |
490
- | Bare `snap` (no `--refs`) | **No** | ref map was not refreshed |
474
+ Disable hints with `--no-hints`.
491
475
 
492
- Navigation (URL, back, forward, reload) always clears the ref map before dispatching, so post-nav hints always reflect the new page.
476
+ ### Stable Output and Artifacts
493
477
 
494
- Opt out explicitly with `--no-hints` (CLI) or `noHints: true` (MCP) for scripts that parse output strictly.
478
+ Chromex keeps plain text as the default output, but also supports stable modes for scripts:
495
479
 
496
- ## Token Efficiency
497
-
498
- Chromex outputs are designed to be read by LLM agents, not humans. Every format decision -- plain text, refs over CSS selectors, incremental diffs, query filters -- was made to minimize tokens while preserving the information the agent actually needs to act.
499
-
500
- ### Measured against common alternatives
501
-
502
- We measured the current plain-text output against three structured format candidates often proposed for agent interfaces: minified JSON, pretty-printed JSON, and a TOON-style compact encoder (a zero-dependency 60-line implementation of the YAML-inline compact style). Five representative chromex outputs were encoded in each format and tokenized with `tiktoken` (`cl100k_base`). Lower token counts are better.
480
+ ```bash
481
+ chromex --raw eval <target> "document.title"
482
+ chromex list --json
483
+ chromex snap <target> --filename=~/.chromex/snapshots/home.yml --boxes
484
+ ```
503
485
 
504
- #### Case by case
486
+ `--raw` prints only the primary command output and suppresses hints and auto-snapshot noise. `--json` returns a stable envelope with `ok`, `command`, `target`, `text`, `data`, `artifacts`, and `error`.
505
487
 
506
- | Case | text-free | json-min | json-pretty | toon-compact |
507
- |--------------------------------|-----------:|---------------:|----------------:|----------------:|
508
- | `snap-login-small` | **130** | 178 (+37%) | 301 (+132%) | 212 (+63%) |
509
- | `snap-repo-large` (65 KB real) | **19,702** | 34,315 (+74%) | 63,232 (+221%) | 44,613 (+126%) |
510
- | `net-list-50` | **454** | 574 (+26%) | 921 (+103%) | 706 (+56%) |
511
- | `console-list-12` | **273** | 363 (+33%) | 576 (+111%) | 453 (+66%) |
512
- | `fill-action-small` | **99** | 127 (+28%) | 221 (+123%) | 146 (+48%) |
488
+ Generated artifacts are written under `~/.chromex/artifacts/<workspace>/` by default. Paths in the Chromex namespace, such as `.chromex/storage/auth.json` or `~/.chromex/storage/auth.json`, resolve to `~/.chromex/...`. Other explicit absolute or relative file paths are respected as provided. Set `CHROMEX_ARTIFACT_ROOT` to override the default artifact root for CI or tests.
513
489
 
514
- The five cases cover the most common outputs an agent sees during a real session: a small accessibility snapshot with refs (a login form), a large accessibility snapshot of a real GitHub repository page, a network list with 50 tracked requests, a console list with a mix of `log`, `warn` and `error` entries, and a post-action result (fill + incremental diff + hints).
490
+ ### Named Sessions
515
491
 
516
- #### Aggregate (5 cases combined)
492
+ Named sessions let agents reuse isolated browser contexts without carrying target IDs:
517
493
 
518
- | Format | tokens | vs text-free |
519
- |------------------------|----------:|-------------:|
520
- | **text-free (current)**| **20,658**| -- |
521
- | json-min | 35,557 | +72.1% |
522
- | json-pretty | 65,251 | +215.9% |
523
- | toon-compact (custom) | 46,130 | +123.3% |
494
+ ```bash
495
+ chromex -s auth open https://example.com/login
496
+ chromex -s auth snap --refs
497
+ chromex -s auth click @e3
498
+ chromex sessions
499
+ chromex show --annotate
500
+ chromex close-all
501
+ chromex delete-data
502
+ ```
524
503
 
525
- The current plain-text output is the most token-efficient in every single case. Every structured alternative costs more tokens, not less, because JSON and YAML-style encodings add syntactic overhead (`{`, `}`, `"`, `:`, `,`, indentation) that the chromex plain-text format omits entirely. The chromex format is already dense: short refs (`@e5`), unquoted labels, no wrapping, no redundancy. Structured formats have nothing to optimize away.
504
+ `CHROMEX_SESSION=auth` can replace `-s auth` for shell scripts.
505
+ `chromex show` opens the generated dashboard in the default browser during normal CLI usage; set `CHROMEX_NO_OPEN=1` or use `--json`/`--raw` to only write the artifact.
526
506
 
527
- ### Why this matters
507
+ Named sessions keep a private storage-state file under `~/.chromex/session-data/<name>/storage-state.json`. Chromex restores it when the named session is reopened and refreshes it after state-changing session commands.
528
508
 
529
- - **No structured-output refactor is planned.** Chromex keeps the current plain-text format because the data shows it wins.
530
- - **`@eN` refs beat CSS selectors** not just for reliability (accessibility tree is stable across SPA re-renders) but also for token count -- `@e5` is one token, `document.querySelector('#login-form > div.field input[name="email"]')` is around fifteen.
531
- - **`--query` and incremental diff** are where the real token savings live. A filtered snapshot on a large page drops output by 95% to 99%, and an incremental diff after an action drops it by 90% or more. These are multiplicative with the already-dense base format.
509
+ `chromex show --annotate` generates a local dashboard with screenshot previews, region/point marking, per-mark notes, and JSON export. Browsers with File System Access support can save the exported pack directly; other browsers download the JSON file.
532
510
 
533
- ### Reproducing the benchmark
511
+ ### Storage State and Locators
534
512
 
535
- The comparison script is checked into the repo and runs standalone:
513
+ Storage state captures cookies plus localStorage for the current origin:
536
514
 
537
515
  ```bash
538
- node tests/benchmarks/token-format-comparison.mjs
516
+ chromex state <target> save ~/.chromex/storage/auth.json
517
+ chromex state <target> load ~/.chromex/storage/auth.json
539
518
  ```
540
519
 
541
- It uses `js-tiktoken` (devDependency) with `cl100k_base`, the GPT-4 tokenizer. Claude uses its own BPE tokenizer with a different vocabulary, so absolute numbers would shift by a few percent -- but both are byte-pair encoders over similar corpora, and the direction of the comparison (which format wins) is consistent across BPE tokenizers. Nothing in the results is a rounding error: the gaps are 25% to 220%.
542
-
543
- ## MCP vs CLI
544
-
545
- Both interfaces call the same core, same daemons, same commands. The difference is how they integrate with Claude Code.
546
-
547
- | | CLI (`chromex-cli`) | MCP Server (`chromex-mcp`) |
548
- |---|---|---|
549
- | Token overhead | Zero schema cost | ~500 tokens per tool used (deferred loading) |
550
- | Auto-approve | Glob pattern in settings | `"mcp__chromex"` -- one line |
551
- | Permissions | All-or-nothing | Per-tool granularity |
552
- | Parameters | Positional string args | Typed JSON Schema |
553
- | Screenshots | File path (needs `Read` to view) | Inline image (base64, no extra call) |
554
- | Best for | Terminal, scripts, CI/CD, token-sensitive sessions | Plug-and-play automation, users who want zero-config |
520
+ Refs can also be converted into reusable locator output or starter action code:
555
521
 
556
- ### Switching Between MCP and CLI
522
+ ```bash
523
+ chromex locator <target> @e5 --format=chromex-test
524
+ chromex locator <target> @e5 --format=css
525
+ chromex locator <target> @e5 --format=testing-library
526
+ chromex fill <target> @e1 "user@example.com" --code=chromex-test
527
+ ```
557
528
 
558
- You can enable and disable the MCP server at any time. The CLI always works regardless.
529
+ ### Evidence Packs
559
530
 
560
- **Disable MCP** (saves ~3-5k tokens per session):
531
+ Evidence packs collect browser evidence without recording video:
561
532
 
562
533
  ```bash
563
- claude mcp remove chromex
534
+ chromex evidence <target> start checkout-flow
535
+ chromex click <target> @e3
536
+ chromex fill <target> @e5 "user@example.com"
537
+ chromex evidence <target> mark "after login"
538
+ chromex evidence <target> stop
539
+ chromex evidence <target> replay
564
540
  ```
565
541
 
566
- The CLI (`chromex-cli`) continues working normally -- same commands, same daemons, no change.
542
+ Each pack is written under `~/.chromex/artifacts/<workspace>/evidence/` and includes screenshots, accessibility snapshots with boxes, HTML captures, console JSON, network JSON, action timeline, `evidence.json`, and `index.html` for local replay. Values passed to `fill`, `type`, and `form` are redacted from the action timeline.
543
+
544
+ ## Application State Suite
567
545
 
568
- **Re-enable MCP:**
546
+ Chromex exposes browser Application panel state without heavy browser automation runtimes or extra packages. This is useful for debugging PWAs, offline behavior, stale caches, local database migrations, authentication state, and quota issues from the same logged-in browser session an agent is already using.
569
547
 
570
548
  ```bash
571
- # Global (all projects)
572
- claude mcp add chromex -s user npx chromex-mcp@latest
549
+ # One-line overview for the current origin
550
+ chromex app <target> summary
573
551
 
574
- # Project-only
575
- claude mcp add chromex npx chromex-mcp@latest
576
- ```
552
+ # Origin quota and per-storage-type usage
553
+ chromex storage <target> usage
577
554
 
578
- **When to disable MCP:**
579
- - Token-sensitive sessions where every token counts
580
- - You only need occasional commands (`list`, `snap`, `shot`)
581
- - You're already comfortable with the CLI syntax
582
- - You're using chromex from terminal/scripts, not from Claude Code
555
+ # Service Worker registrations and versions
556
+ chromex sw <target>
557
+ chromex sw <target> update https://example.com/
558
+ chromex sw <target> skip-waiting https://example.com/
583
559
 
584
- **When to keep MCP enabled:**
585
- - Automating multi-step browser workflows (snap -> click -> fill -> snap)
586
- - You want per-tool auto-approve without glob patterns
587
- - You want inline screenshots without a separate `Read` call
588
- - First time using chromex (discovery via tool schema)
560
+ # Cache Storage
561
+ chromex cache <target> list
562
+ chromex cache <target> entries <cacheId> --query=/api
563
+ chromex cache <target> body <cacheId> https://example.com/app.js
589
564
 
590
- ### CLI Auto-Approve
565
+ # IndexedDB
566
+ chromex idb <target> list
567
+ chromex idb <target> schema app-db
568
+ chromex idb <target> rows app-db users --limit=20
569
+ ```
591
570
 
592
- If you prefer the CLI interface, add this to `~/.claude/settings.json`:
571
+ `chromex app <target> summary` includes origin, quota, localStorage key count, sessionStorage key count, cookie count, Cache Storage cache/entry counts, IndexedDB database count, active/waiting Service Worker counts, storage bucket count, and manifest status.
593
572
 
594
- ```json
595
- {
596
- "permissions": {
597
- "allow": [
598
- "Bash(chromex-cli *)"
599
- ]
600
- }
601
- }
602
- ```
573
+ Destructive Application commands are explicit: `storage clear-site-data`, `sw unregister`, `cache delete-entry`, `cache delete`, and `idb clear`.
603
574
 
604
575
  ## Security
605
576
 
606
- Config at `~/.chromex/config.json` (auto-created on first run):
577
+ Chromex creates `~/.chromex/config.json` on first run:
607
578
 
608
579
  ```json
609
580
  {
610
- "blockedDomains": ["mail.google.com", "bank.example.com"],
581
+ "commandTimeout": 15000,
582
+ "navigationTimeout": 30000,
583
+ "idleTimeout": 1200000,
611
584
  "allowedDomains": [],
612
- "blockedCdpMethods": ["Browser.close", "Storage.getCookies", "..."],
613
- "socketAuth": true,
614
- "auditLog": true
585
+ "blockedDomains": [],
586
+ "blockedCdpMethods": ["Browser.close", "Storage.getCookies"],
587
+ "auditLog": true,
588
+ "socketAuth": true
615
589
  }
616
590
  ```
617
591
 
618
- - **Domain filtering**: block sensitive sites or restrict to a whitelist
619
- - **CDP blocklist**: dangerous methods blocked by default in `evalraw`
620
- - **Socket auth**: 32-byte random token per session (mode 0600)
621
- - **Audit log**: every command logged with timestamp and status
592
+ Recommended security practices:
622
593
 
623
- See [docs/security.md](docs/security.md) for full details.
594
+ - Add sensitive sites to `blockedDomains`, such as email, banking, password managers, and admin panels.
595
+ - Use `allowedDomains` in restricted environments where the agent should access only specific hosts.
596
+ - Keep `socketAuth` enabled.
597
+ - Keep `auditLog` enabled and review `~/.chromex/audit.log` when needed.
598
+ - Prefer `chromex launch --profile testing` for isolated browser state.
624
599
 
625
- ## How It Works
600
+ See [docs/security.md](docs/security.md) for the full security model.
626
601
 
627
- 1. **Browser detection** -- scans ~30 paths for `DevToolsActivePort` (or use `CDP_PORT_FILE` env var)
628
- 2. **Daemon spawn** -- first command to a tab spawns a background Node.js process connected via CDP WebSocket
629
- 3. **Session persistence** -- daemon holds the session open; Chrome's "Allow" modal fires once per daemon
630
- 4. **Unix sockets** -- CLI/MCP communicates with daemon via authenticated Unix sockets
631
- 5. **Auto-exit** -- daemons shut down after 20 minutes of inactivity (configurable)
602
+ ## How It Works
632
603
 
604
+ ```text
605
+ CLI or MCP client -> authenticated Unix socket -> per-tab daemon -> CDP WebSocket -> browser
633
606
  ```
634
- CLI Client ──Unix Socket + Auth──> Per-Tab Daemon ──CDP WebSocket──> Chrome
635
- MCP Server ──Unix Socket + Auth──> (same) ──CDP WebSocket──> Chrome
636
- ```
637
607
 
638
- See [docs/architecture.md](docs/architecture.md) for the full deep dive.
608
+ 1. Chromex finds the browser DevTools endpoint from `DevToolsActivePort` or `CDP_PORT_FILE`.
609
+ 2. The first tab command starts a detached daemon for that tab.
610
+ 3. The daemon attaches once through CDP and keeps the session open.
611
+ 4. CLI and MCP commands talk to the daemon through an authenticated Unix socket.
612
+ 5. Daemons exit after the configured idle timeout.
613
+
614
+ See [docs/architecture.md](docs/architecture.md) for implementation details.
639
615
 
640
616
  ## Documentation
641
617
 
642
618
  | Guide | Description |
643
619
  |-------|-------------|
644
- | [Getting Started](docs/getting-started.md) | Installation, connection methods, first commands |
645
- | [Inspect & Debug](docs/inspect.md) | Screenshots, accessibility tree, refs, HTML, eval, network, performance, console |
646
- | [Navigate & Interact](docs/navigate.md) | Navigation, clicking, typing, scrolling, drag & drop, touch, dialogs |
647
- | [Form Filling](docs/forms.md) | Fill, clear, select, check, upload, batch fill with examples |
648
- | [Data Access](docs/data.md) | Cookies, localStorage, sessionStorage, PDF export |
649
- | [Network Control](docs/network.md) | Throttling, interception, mocking, HAR recording |
650
- | [Device Emulation](docs/emulation.md) | Responsive testing, geolocation, timezone, CPU throttling |
651
- | [Security](docs/security.md) | Domain filtering, CDP blocklist, audit log, best practices |
652
- | [Advanced](docs/advanced.md) | Script injection, code coverage, tracing, heap snapshots, WebAuthn |
653
- | [Architecture](docs/architecture.md) | How it works: daemon model, connection modes, file layout |
620
+ | [Getting Started](docs/getting-started.md) | Installation, browser setup, first commands. |
621
+ | [Inspect and Debug](docs/inspect.md) | Screenshots, accessibility tree, refs, HTML, eval, network, performance, console. |
622
+ | [Navigate and Interact](docs/navigate.md) | Navigation, clicking, typing, scrolling, drag and drop, touch, dialogs. |
623
+ | [Form Filling](docs/forms.md) | Fill, clear, select, check, upload, batch form examples. |
624
+ | [Data Access](docs/data.md) | Cookies, localStorage, sessionStorage, Application state, Cache Storage, IndexedDB, Service Workers, PDF export. |
625
+ | [Network Control](docs/network.md) | Throttling, interception, mocking, HAR recording. |
626
+ | [Device Emulation](docs/emulation.md) | Responsive testing, geolocation, timezone, CPU throttling. |
627
+ | [Security](docs/security.md) | Domain filtering, CDP blocklist, audit log, best practices. |
628
+ | [Advanced](docs/advanced.md) | Script injection, code coverage, tracing, heap snapshots, WebAuthn. |
629
+ | [Architecture](docs/architecture.md) | Daemon model, connection modes, and file layout. |
630
+
631
+ ## Development
632
+
633
+ ```bash
634
+ git clone https://github.com/whallysson/chromex.git
635
+ cd chromex
636
+ bun install
637
+ bun run test
638
+ ```
639
+
640
+ The runtime package has no dependencies. Development dependencies are used only for tests and token benchmarks.
641
+
642
+ Run the browser-backed smoke flow explicitly when validating a release candidate:
643
+
644
+ ```bash
645
+ bun run test:smoke
646
+ ```
647
+
648
+ The smoke script launches a temporary headless Chromium profile through `CDP_PORT_FILE`, exercises named sessions, snapshots, locators, storage state, annotation dashboard artifacts, and then stops the launched process.
649
+
650
+ To reproduce the token-format comparison:
651
+
652
+ ```bash
653
+ bun tests/benchmarks/token-format-comparison.mjs
654
+ ```
654
655
 
655
656
  ## License
656
657
 
657
- MIT
658
+ MIT. See [LICENSE](LICENSE).