chromex-mcp 1.4.0 → 1.6.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,538 +1,542 @@
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
- ## Features
6
-
7
- - **56 MCP tools** -- typed JSON Schema, annotations (`readOnlyHint`, `destructiveHint`), inline screenshots (base64)
8
- - **Zero dependencies** -- uses only Node.js 22+ built-in modules (WebSocket, fs, net, crypto)
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]`)
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
14
- - **Security hardened** -- domain filtering (allow/blocklist), CDP method blocklist, token-authenticated sockets, full audit log
15
- - **Multi-browser** -- auto-detects Brave, Chrome, Chrome Canary, Chromium, Edge, Vivaldi (macOS + Linux)
16
- - **Network control** -- throttle to 3G/offline, intercept & mock requests, record HAR files
17
- - **Form filling** -- fill inputs, select dropdowns, toggle checkboxes, upload files, batch fill entire forms. Works with React/Vue/Angular
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
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 73 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 Puppeteer or Playwright.
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**: 73 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
+ - Read page state through compact accessibility snapshots, filtered snapshots, DOM snapshots, HTML, screenshots, and highlighted elements.
25
+ - Act on UI through refs, CSS selectors, coordinates, keyboard input, forms, uploads, drag and drop, touch gestures, dialogs, and load-more loops.
26
+ - Debug production behavior with console history, network request details, response bodies, HAR export, request blocking, API mocking, throttling, and offline mode.
27
+ - Test browser conditions with device presets, viewport resizing, DPR, geolocation, timezone, locale, CPU throttling, incognito contexts, proxies, and custom Chrome flags.
28
+ - Diagnose performance and quality with Core Web Vitals, transfer size, DOM/memory counters, Lighthouse audits, JS/CSS coverage, Chrome traces, and heap snapshots.
29
+ - Validate modern browser flows such as passkey/WebAuthn registration and login, downloads, cookies, storage, PDF export, and isolated profiles.
30
+ - Inspect Application panel state from the terminal: origin quota, storage usage breakdown, Cache Storage entries/bodies, IndexedDB schemas/rows, and Service Worker registrations.
31
+
32
+ ## Positioning
33
+
34
+ Chromex is a direct CDP layer for coding agents. It sits between raw Chrome DevTools Protocol and heavier browser automation frameworks.
35
+
36
+ | Alternative | Trade-off | Chromex angle |
37
+ |-------------|-----------|---------------|
38
+ | Raw CDP WebSocket | Maximum browser power, but too verbose for agents. | Compact commands, refs, snapshots, and safety defaults. |
39
+ | Puppeteer or Playwright libraries | Excellent automation frameworks, but they add dependencies and framework-level abstractions. | Zero-runtime-dependency CLI/MCP that talks to your existing Chromium browser. |
40
+ | 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. |
41
+ | Manual DevTools | Great for humans, not scriptable enough for agents. | DevTools-grade inspection exposed as terminal and MCP commands. |
20
42
 
21
43
  ## Requirements
22
44
 
23
- - Node.js 22+ (for built-in WebSocket)
24
- - Any Chromium-based browser
45
+ - Node.js 22 or newer.
46
+ - macOS or Linux.
47
+ - A Chromium-based browser: Chrome, Brave, Edge, Chromium, Chrome Canary, or Vivaldi.
25
48
 
26
- ## Installation
49
+ ## Zero-Dependency Boundary
27
50
 
28
- ```bash
29
- # Add to Claude Code (global -- all projects)
30
- claude mcp add chromex -s user npx chromex-mcp@latest
51
+ The core runtime uses only Node.js built-in modules. Chromex does not install Puppeteer, Playwright, Selenium, browser drivers, telemetry SDKs, update checkers, or bundled browsers.
31
52
 
32
- # Or project-only
33
- claude mcp add chromex npx chromex-mcp@latest
34
- ```
53
+ 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.
35
54
 
36
- ### Auto-Approve (recommended)
55
+ Development dependencies are used only for tests and token benchmarks.
37
56
 
38
- Add to `~/.claude/settings.json`:
57
+ ## Browser Setup
39
58
 
40
- ```json
41
- {
42
- "permissions": {
43
- "allow": ["mcp__chromex"]
44
- }
45
- }
59
+ Chromex needs Chrome DevTools Protocol access to your browser. Choose one of the two connection modes below before using the CLI or MCP server.
60
+
61
+ ### Option A: Launch a Browser with Chromex
62
+
63
+ 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.
64
+
65
+ ```bash
66
+ chromex launch --url https://example.com
46
67
  ```
47
68
 
48
- This approves all 56 MCP tools at once. For granular control, approve individual tools:
69
+ Useful launch variants:
49
70
 
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
- }
71
+ ```bash
72
+ chromex launch --browser brave --url https://example.com
73
+ chromex launch --profile testing --url https://example.com
74
+ chromex launch --incognito --browser chrome
75
+ chromex launch --headless --url https://example.com
76
+ chromex launch --browser-path "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary"
61
77
  ```
62
78
 
63
- ### Global install (optional)
79
+ Named profiles are stored under `~/.chromex/profiles/` and keep test sessions isolated from your daily browser profile.
80
+
81
+ 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.
82
+
83
+ ### Option B: Connect to an Already-Running Browser
84
+
85
+ Use this when you want Chromex to inspect tabs that are already open in your normal browser.
86
+
87
+ 1. Open Chrome, Brave, Edge, Chromium, or Vivaldi.
88
+ 2. Go to `chrome://inspect/#remote-debugging`.
89
+ 3. Enable the remote debugging switch.
90
+ 4. Run `chromex list` to verify that tabs are visible.
64
91
 
65
92
  ```bash
66
- npm install -g chromex-mcp
93
+ chromex list
67
94
  ```
68
95
 
69
- This installs three binaries:
96
+ Important notes:
70
97
 
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 |
98
+ - Without remote debugging enabled, Chromex cannot discover or control your open tabs.
99
+ - The browser setting is usually persistent across restarts.
100
+ - 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.
101
+
102
+ If your browser uses a custom profile or a non-standard `DevToolsActivePort` location, set:
76
103
 
77
104
  ```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
105
+ export CDP_PORT_FILE=/path/to/DevToolsActivePort
82
106
  ```
83
107
 
84
- ## Connect to Your Browser
108
+ If your Chromium executable is installed in a non-standard location, either pass `--browser-path` to `chromex launch` or set:
109
+
110
+ ```bash
111
+ export CHROMEX_BROWSER_PATH=/path/to/chrome
112
+ ```
85
113
 
86
- **Option A: Launch a new browser** (recommended -- no setup needed)
114
+ Run the local diagnostic command whenever browser discovery or CDP connection fails:
87
115
 
88
116
  ```bash
89
- chromex launch --url https://example.com
117
+ chromex doctor
90
118
  ```
91
119
 
92
- This starts Chrome/Brave/Edge with remote debugging pre-enabled. No manual configuration required.
120
+ ## Install the CLI
93
121
 
94
- **Option B: Connect to an already-running browser**
122
+ Install the package globally to get the `chromex` command.
95
123
 
96
- 1. Open your browser (Chrome, Brave, Edge, etc.)
97
- 2. Navigate to `chrome://inspect/#remote-debugging`
98
- 3. **Toggle the switch ON** to enable remote debugging
99
- 4. Run `chromex list` to verify the connection
124
+ ```bash
125
+ # npm
126
+ npm install -g chromex-mcp
100
127
 
101
- > **Important:** Without step 3, chromex cannot connect to your browser. This is a one-time setup -- the setting persists across browser restarts.
128
+ # Bun
129
+ bun add -g chromex-mcp
130
+ ```
102
131
 
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.
132
+ The package installs three binaries:
104
133
 
105
- ## Quick Start
134
+ | Binary | Purpose |
135
+ |--------|---------|
136
+ | `chromex` | Main CLI for terminal, scripts, CI, and token-sensitive agent sessions. |
137
+ | `chromex-cli` | Alias for `chromex`. |
138
+ | `chromex-mcp` | MCP server over stdio JSON-RPC. Usually launched by an MCP client. |
139
+
140
+ ## CLI Quick Start
141
+
142
+ 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.
106
143
 
107
144
  ```bash
108
- # List open tabs
109
- chromex list
110
- # Output: 6BE827FA Example Domain https://example.com
145
+ # 1. Launch or connect to a browser.
146
+ chromex launch --url https://github.com/login
111
147
 
112
- # Take a screenshot
113
- chromex shot 6BE8 /tmp/page.png
148
+ # 2. List tabs and copy a target prefix.
149
+ chromex list
150
+ # 6BE827FA Sign in to GitHub https://github.com/login
114
151
 
115
- # Get the accessibility tree with interactive refs
152
+ # 3. Read the page through the accessibility tree and assign refs.
116
153
  chromex snap 6BE8 --refs
117
- # Output:
118
- # @e1 [textbox] Email
119
- # @e2 [textbox] Password
120
- # @e3 [button] Sign in
154
+ # @e1 [textbox] Username or email address
155
+ # @e2 [textbox] Password
156
+ # @e3 [button] Sign in
121
157
 
122
- # Fill a form using refs (no CSS selectors needed!)
158
+ # 4. Interact by ref instead of fragile CSS selectors.
123
159
  chromex fill 6BE8 @e1 "user@example.com"
124
- chromex fill 6BE8 @e2 "secret123"
160
+ chromex fill 6BE8 @e2 "secret"
125
161
  chromex click 6BE8 @e3
126
162
 
127
- # Check Core Web Vitals
128
- chromex perf 6BE8
163
+ # 5. Inspect browser state.
164
+ chromex console 6BE8 list
165
+ chromex net 6BE8
166
+ chromex shot 6BE8 /tmp/page.png
167
+ chromex app 6BE8
129
168
  ```
130
169
 
131
- ## Commands
170
+ `<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.
132
171
 
133
- `<target>` is a unique prefix of the targetId shown by `list` (e.g. `6BE827FA`).
172
+ ## Token-Efficient Agent Workflow
134
173
 
135
- ### Pages & Browser
174
+ Chromex is optimized for agents that need to act on browser state without wasting context.
136
175
 
137
- ```bash
138
- chromex list # List open pages
139
- chromex open "https://example.com" # Open new tab
140
- chromex close <target> # Close tab
141
- chromex focus <target> # Activate/focus tab
142
- chromex launch # Launch browser with debugging
143
- chromex launch --incognito --browser brave # Launch Brave in incognito
144
- chromex launch --headless --url https://example.com # Headless mode for CI/CD
145
- chromex launch --proxy socks5://localhost:1080 # Launch with proxy
146
- chromex launch --insecure # Ignore certificate errors
147
- chromex launch --chrome-arg --disable-web-security # Pass custom Chrome flag
148
- chromex launch --profile testing --url https://... # Isolated profile + URL
149
- chromex incognito https://example.com # Isolated context (no relaunch)
150
- chromex stop # Stop all daemons
151
- ```
176
+ 1. Start with `chromex list`.
177
+ 2. Prefer `chromex snap <target> --refs` over raw HTML.
178
+ 3. Use `@eN` refs for `click`, `fill`, `hover`, and element screenshots.
179
+ 4. On large pages, use `--query` before reading a full snapshot.
180
+ 5. Let auto-snapshot show post-action state after interactive commands.
181
+ 6. Add `--no-snap` only for fast scripted batches where you do not need immediate page state.
182
+ 7. Add `--no-hints` when another program parses output strictly.
152
183
 
153
- ### Inspect
184
+ Examples:
154
185
 
155
186
  ```bash
156
- chromex snap <target> # Accessibility tree snapshot (compact)
157
- chromex snap <target> --refs # With interactive refs (@e1, @e2...)
158
- chromex snap <target> --depth=3 # Limit tree depth
159
- chromex snap <target> --full # Force full snapshot (skip diff)
160
- chromex html <target> "#main" # Element HTML by selector
161
- chromex shot <target> /tmp/page.png # Viewport screenshot
162
- chromex shot <target> /tmp/full.png --full # Full page screenshot
163
- chromex shot <target> --format=jpeg --quality=80 # JPEG/WebP with quality control
164
- chromex shot <target> @e5 # Screenshot of specific element by ref
165
- chromex net <target> # List network requests (CDP tracked)
166
- chromex net <target> <requestId> # Request detail: headers, timing, body
167
- chromex perf <target> # Core Web Vitals + memory + DOM stats
168
- chromex console <target> 5000 # Capture console.log/error for 5s
169
- chromex console <target> list # Show stored messages since daemon start
170
- chromex console <target> detail <id> # Message detail with stack trace
171
- chromex domsnapshot <target> # Structured DOM with bounding rects
172
- chromex domsnapshot <target> --styles # Include computed styles
173
- chromex highlight <target> "h1" # Highlight element with overlay
174
- chromex highlight <target> clear # Remove highlight
187
+ chromex snap 6BE8 --query=login --refs
188
+ chromex click 6BE8 @e4
189
+ chromex wait 6BE8 networkidle
190
+ chromex snap 6BE8 --query=error
175
191
  ```
176
192
 
177
- ### Evaluate
193
+ ## MCP Server
178
194
 
179
- ```bash
180
- chromex eval <target> "document.title" # Run JS
181
- chromex eval <target> "document.querySelectorAll('a').length" # Count links
182
- chromex evalraw <target> "DOM.getDocument" # Raw CDP command
183
- chromex evalraw <target> "Page.getLayoutMetrics" # Layout info
184
- ```
195
+ 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.
196
+
197
+ ### Add to Claude Code
185
198
 
186
- ### Navigate & Wait
199
+ Global, available in all projects:
187
200
 
188
201
  ```bash
189
- chromex nav <target> "https://example.com" # Navigate + wait for load
190
- chromex nav <target> back # Go back in history
191
- chromex nav <target> forward # Go forward in history
192
- chromex nav <target> reload # Reload page
193
- chromex nav <target> reload-hard # Reload ignoring cache
194
- chromex waitfor <target> ".results" 10000 # Wait for CSS selector (10s)
195
- chromex wait <target> networkidle # Wait for network idle
196
- chromex wait <target> load # Wait for page load
197
- chromex wait <target> domready # Wait for DOMContentLoaded
198
- chromex wait <target> fcp # Wait for First Contentful Paint
199
- chromex scroll <target> down 500 # Scroll down 500px
200
- chromex scroll <target> up 300 # Scroll up 300px
201
- chromex scroll <target> top # Scroll to top
202
- chromex scroll <target> bottom # Scroll to bottom
203
- chromex scroll <target> to "#footer" # Scroll to element
202
+ # npm
203
+ claude mcp add chromex -s user npx chromex-mcp@latest
204
+
205
+ # Bun
206
+ claude mcp add chromex -s user bunx chromex-mcp@latest
204
207
  ```
205
208
 
206
- ### Interact
209
+ Project-only:
207
210
 
208
211
  ```bash
209
- chromex click <target> "button.submit" # Click by CSS selector
210
- chromex click <target> @e5 # Click by ref (from snap --refs)
211
- chromex click <target> @e5 --dbl # Double-click
212
- chromex clickxy <target> 100 200 # Click at CSS pixel coords
213
- chromex clickxy <target> 100 200 --dbl # Double-click at coords
214
- chromex key <target> Enter # Press key
215
- chromex key <target> "Control+A" # Key combination
216
- chromex key <target> "Control+Shift+R" # Multi-modifier combo
217
- chromex type <target> "hello world" # Type text (works cross-origin)
218
- chromex hover <target> @e12 # Hover element by ref
219
- chromex drag <target> "#source" "#dest" # Drag & drop by selector
220
- chromex drag <target> 100,200 400,500 # Drag & drop by coordinates
221
- chromex touch <target> tap 200 300 # Touch tap
222
- chromex touch <target> swipe 200,400 200,100 # Swipe gesture
223
- chromex touch <target> pinch 200 300 2.0 # Pinch zoom in
224
- chromex touch <target> longpress 200 300 1000 # Long press (1s)
225
- chromex dialog <target> accept # Accept alert/confirm
226
- chromex dialog <target> dismiss # Dismiss dialog
227
- chromex dialog <target> auto # Auto-accept all dialogs
228
- chromex loadall <target> ".load-more" 500 # Click until element disappears
212
+ # npm
213
+ claude mcp add chromex npx chromex-mcp@latest
214
+
215
+ # Bun
216
+ claude mcp add chromex bunx chromex-mcp@latest
229
217
  ```
230
218
 
231
- ### Forms
219
+ 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`, and `chromex_indexeddb_rows`.
232
220
 
233
- ```bash
234
- chromex fill <target> "#email" "user@test.com" # Fill input/textarea
235
- chromex fill <target> @e1 "user@test.com" # Fill by ref
236
- chromex clear <target> "#search" # Clear field
237
- chromex select <target> "#country" "BR" # Select dropdown option
238
- chromex check <target> "#terms" # Check checkbox
239
- chromex check <target> "#newsletter" false # Uncheck checkbox
240
- chromex upload <target> "#avatar" /tmp/photo.png # Upload file
241
-
242
- # Batch fill entire form
243
- chromex form <target> '{"#name":"John","#email":"john@test.com","#terms":true}'
244
- ```
221
+ ### Claude Code Auto-Approve
245
222
 
246
- ### Data
223
+ To approve all Chromex MCP tools at once, add this to `~/.claude/settings.json`:
247
224
 
248
- ```bash
249
- chromex cookies <target> # List cookies
250
- chromex cookies <target> set '{"name":"x","value":"y"}' # Set cookie
251
- chromex cookies <target> clear # Clear all cookies
252
- chromex storage <target> local # Dump localStorage
253
- chromex storage <target> session # Dump sessionStorage
254
- chromex storage <target> clear # Clear both
255
- chromex pdf <target> /tmp/page.pdf # Export as PDF
225
+ ```json
226
+ {
227
+ "permissions": {
228
+ "allow": ["mcp__chromex"]
229
+ }
230
+ }
256
231
  ```
257
232
 
258
- ### Network
233
+ For CLI usage inside Claude Code, approve the shell command instead:
259
234
 
260
- ```bash
261
- chromex throttle <target> 3g # Throttle to 3G
262
- chromex throttle <target> slow-3g # Throttle to slow 3G
263
- chromex throttle <target> 4g # Throttle to 4G
264
- chromex throttle <target> offline # Go offline
265
- chromex throttle <target> custom 200 1000 500 # Custom: latency, down, up (kbps)
266
- chromex throttle <target> reset # Remove throttling
267
-
268
- chromex intercept <target> block "*.analytics.*" # Block matching requests
269
- chromex intercept <target> mock "/api/user" '{"name":"test"}' # Mock response
270
- chromex intercept <target> rules # List active rules
271
- chromex intercept <target> off # Disable interception
272
-
273
- chromex har <target> start # Start recording
274
- chromex har <target> stop /tmp/trace.har # Save HAR file
235
+ ```json
236
+ {
237
+ "permissions": {
238
+ "allow": [
239
+ "Bash(chromex *)",
240
+ "Bash(chromex-cli *)"
241
+ ]
242
+ }
243
+ }
275
244
  ```
276
245
 
277
- ### Emulate
246
+ Review these permissions before enabling them. Chromex security settings still apply, and every command is audit-logged when `auditLog` is enabled.
278
247
 
279
- ```bash
280
- chromex emulate <target> iphone-14 # 390x844 @3x mobile
281
- chromex emulate <target> iphone-15-pro # 393x852 @3x mobile
282
- chromex emulate <target> ipad-pro # 1024x1366 @2x tablet
283
- chromex emulate <target> pixel-7 # 412x915 @2.625x mobile
284
- chromex emulate <target> galaxy-s23 # 360x780 @3x mobile
285
- chromex emulate <target> macbook-air # 1440x900 @2x laptop
286
- chromex emulate <target> desktop-1080p # 1920x1080 @1x
287
- chromex emulate <target> desktop-4k # 3840x2160 @1x
288
- chromex emulate <target> reset # Reset to default
289
- chromex resize <target> 1280 720 # Custom viewport dimensions
290
- chromex resize <target> 1440 900 2 # Custom with DPR (retina)
291
- chromex geo <target> -23.55 -46.63 # Set geolocation (Sao Paulo)
292
- chromex geo <target> reset # Clear geolocation
293
- chromex timezone <target> "America/Sao_Paulo" # Set timezone
294
- chromex locale <target> "pt-BR" # Set locale
295
- chromex cpu <target> 4 # CPU 4x slower
296
- chromex cpu <target> reset # Reset CPU speed
297
- ```
248
+ ## CLI vs MCP
298
249
 
299
- ### Advanced
250
+ Both interfaces use the same CDP core and the same per-tab daemons. Choose based on the workflow.
251
+
252
+ | Use case | Prefer CLI | Prefer MCP |
253
+ |----------|------------|------------|
254
+ | Token-sensitive agent sessions | Yes | No |
255
+ | Terminal scripts and CI | Yes | No |
256
+ | Quick one-off browser inspection | Yes | Optional |
257
+ | Typed tool discovery in Claude Code | No | Yes |
258
+ | Inline screenshots returned to the client | No, screenshots are files | Yes |
259
+ | Granular per-tool permissions | Shell pattern only | Yes |
260
+ | Lowest setup friction for MCP users | Optional | Yes |
261
+
262
+ You can remove MCP at any time and keep using the CLI:
300
263
 
301
264
  ```bash
302
- chromex inject <target> "window.DEBUG=true" # Inject JS on every page load
303
- chromex inject <target> --file /tmp/preload.js # Inject from file
304
- chromex inject <target> --list # List injected scripts
305
- chromex inject <target> --remove <id> # Remove injected script
306
- chromex download <target> allow /tmp/downloads # Auto-accept downloads
307
- chromex download <target> deny # Block downloads
308
- chromex coverage <target> start # Start code coverage
309
- chromex coverage <target> stop # Coverage report (JS + CSS %)
310
- chromex trace <target> start # Start performance trace
311
- chromex trace <target> stop /tmp/trace.json # Save trace (chrome://tracing)
312
- chromex heap <target> snapshot /tmp/heap.hs # Heap snapshot (memory analysis)
313
- chromex webauthn <target> enable # Virtual authenticator (passkeys)
314
- chromex webauthn <target> creds # List stored credentials
315
- chromex webauthn <target> disable # Remove authenticator
265
+ claude mcp remove chromex
316
266
  ```
317
267
 
318
- ### Audit & Analytics
268
+ ## Command Overview
269
+
270
+ ### Pages and Browser
319
271
 
320
272
  ```bash
321
- chromex audit <target> # Full Lighthouse audit (all categories)
322
- chromex audit <target> performance,seo # Specific categories
323
- chromex audit <target> accessibility desktop # Accessibility on desktop
324
- chromex stats <target> # Session analytics (command counts, timing)
325
- chromex stats <target> --full # Full action timeline
326
- chromex stats <target> --reset # Reset counters
327
- chromex stats <target> --export=/tmp/stats.json # Export as JSON
273
+ chromex list
274
+ chromex open "https://example.com"
275
+ chromex close <target>
276
+ chromex focus <target>
277
+ chromex launch --url https://example.com
278
+ chromex launch --browser brave --incognito
279
+ chromex launch --headless --url https://example.com
280
+ chromex launch --browser-path /path/to/chrome --url https://example.com
281
+ chromex doctor
282
+ chromex incognito https://example.com
283
+ chromex stop
328
284
  ```
329
285
 
330
- ## Ref-Based Selection
331
-
332
- The killer feature for AI agents. Instead of fragile CSS selectors, use numbered refs:
286
+ ### Inspect
333
287
 
334
288
  ```bash
335
- # 1. Get interactive elements with refs
336
289
  chromex snap <target> --refs
337
- # Output:
338
- # @e1 [textbox] Username
339
- # @e2 [textbox] Password
340
- # @e3 [checkbox] Remember me
341
- # @e4 [button] Sign in
342
- # @e5 [link] Forgot password?
343
-
344
- # 2. Interact using refs
345
- chromex fill <target> @e1 "admin"
346
- chromex fill <target> @e2 "secret123"
347
- chromex click <target> @e3
348
- chromex click <target> @e4
290
+ chromex snap <target> --query=login
291
+ chromex html <target> "#main"
292
+ chromex shot <target> /tmp/page.png
293
+ chromex shot <target> /tmp/full.png --full
294
+ chromex shot <target> @e5
295
+ chromex console <target> list
296
+ chromex net <target>
297
+ chromex perf <target>
298
+ chromex domsnapshot <target> --styles
349
299
  ```
350
300
 
351
- 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.
352
-
353
- Supported ref commands: `click @eN`, `fill @eN "value"`, `hover @eN`.
301
+ ### Navigate and Wait
354
302
 
355
- ## Snapshot Optimizations
303
+ ```bash
304
+ chromex nav <target> "https://example.com"
305
+ chromex nav <target> back
306
+ chromex nav <target> reload-hard
307
+ chromex waitfor <target> ".results" 10000
308
+ chromex wait <target> networkidle
309
+ chromex scroll <target> bottom
310
+ ```
356
311
 
357
- Chromex snapshots are designed to minimize token usage for AI agents.
312
+ ### Interact
358
313
 
359
- ### Incremental Diff
314
+ ```bash
315
+ chromex click <target> @e5
316
+ chromex clickxy <target> 100 200
317
+ chromex key <target> Enter
318
+ chromex type <target> "hello world"
319
+ chromex hover <target> @e12
320
+ chromex drag <target> "#source" "#dest"
321
+ chromex dialog <target> accept
322
+ ```
360
323
 
361
- The first snapshot returns the full accessibility tree. Subsequent snapshots return only nodes that changed:
324
+ ### Forms
362
325
 
363
- ```
364
- [incremental: 2 changed, 45 unchanged]
365
- *[textbox] Email = "user@example.com"
366
- *[button] Submit
326
+ ```bash
327
+ chromex fill <target> @e1 "user@example.com"
328
+ chromex clear <target> "#search"
329
+ chromex select <target> "#country" "BR"
330
+ chromex check <target> "#terms" true
331
+ chromex upload <target> "#avatar" /tmp/photo.png
332
+ chromex form <target> '{"#name":"John","#email":"john@example.com","#terms":true}'
367
333
  ```
368
334
 
369
- - Changed/new nodes are marked with `*`
370
- - Unchanged subtrees are collapsed entirely
371
- - Use `--full` to force a full snapshot (skips diff)
372
- - Navigation (`nav`) resets the diff baseline automatically
373
-
374
- ### Depth Limiting
335
+ ### Data
375
336
 
376
- Limit tree depth for large pages:
337
+ ```bash
338
+ chromex cookies <target>
339
+ chromex cookies <target> set '{"name":"token","value":"abc"}'
340
+ chromex storage <target> local
341
+ chromex storage <target> session
342
+ chromex storage <target> usage
343
+ chromex app <target> summary
344
+ chromex sw <target>
345
+ chromex cache <target> list
346
+ chromex cache <target> entries <cacheId> --query=/api
347
+ chromex idb <target> list
348
+ chromex idb <target> schema <databaseName>
349
+ chromex idb <target> rows <databaseName> <objectStoreName> --limit=20
350
+ chromex pdf <target> /tmp/page.pdf
351
+ ```
352
+
353
+ ### Network, Emulation, and Diagnostics
377
354
 
378
355
  ```bash
379
- chromex snap <target> --depth=3 # Only 3 levels deep
356
+ chromex throttle <target> 3g
357
+ chromex intercept <target> block "*.analytics.*"
358
+ chromex har <target> start
359
+ chromex har <target> stop /tmp/trace.har
360
+ chromex emulate <target> iphone-15-pro
361
+ chromex resize <target> 1280 720
362
+ chromex geo <target> -23.55 -46.63
363
+ chromex timezone <target> "America/Sao_Paulo"
364
+ chromex cpu <target> 4
365
+ chromex audit <target> performance,accessibility desktop
366
+ chromex stats <target> --full
380
367
  ```
381
368
 
382
- Nodes at the depth limit render as leaves (children are not expanded).
383
-
384
- ### Scroll Detection
385
-
386
- Snapshots automatically detect scrollable containers and report remaining scroll distance:
369
+ ### Advanced
387
370
 
388
- ```
389
- [scroll: page: down:1200px | sidebar: up:300px, down:800px]
371
+ ```bash
372
+ chromex eval <target> "document.title"
373
+ chromex evalraw <target> "Page.getLayoutMetrics"
374
+ chromex inject <target> "window.DEBUG=true"
375
+ chromex download <target> allow /tmp/downloads
376
+ chromex coverage <target> start
377
+ chromex trace <target> start
378
+ chromex heap <target> snapshot /tmp/heap.heapsnapshot
379
+ chromex webauthn <target> enable
390
380
  ```
391
381
 
392
- ### Visibility Filtering
382
+ Run `chromex --help` for the full command reference.
393
383
 
394
- - Ignored/hidden accessibility nodes are automatically omitted
395
- - Disabled interactive elements are shown but not assigned refs (can't be interacted with)
396
- - Generic wrapper nodes (`div`, `span` with no semantic role) are collapsed -- their children inherit the parent's depth
397
- - Names longer than 200 characters are truncated with `...`
384
+ ## Agent-Focused Features
398
385
 
399
- ## Auto-Snapshot
386
+ ### Ref-Based Selection
400
387
 
401
- 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:
388
+ `chromex snap --refs` assigns stable refs to interactive elements:
402
389
 
403
390
  ```bash
391
+ chromex snap <target> --refs
392
+ # @e1 [textbox] Email
393
+ # @e2 [textbox] Password
394
+ # @e3 [button] Sign in
395
+
396
+ chromex fill <target> @e1 "user@example.com"
404
397
  chromex click <target> @e3
405
- # Output:
406
- # Clicked @e3 [button] "Submit"
407
- #
408
- # [incremental: 5 changed, 40 unchanged]
409
- # @e1 [heading] Thank you!
410
- # @e2 [link] Back to home
411
- # ...
412
398
  ```
413
399
 
414
- Commands that trigger auto-snapshot: `click`, `clickxy`, `type`, `key`, `fill`, `clear`, `select`, `check`, `form`, `nav`, `dialog`, `loadall`, `drag`, `touch`, `upload`.
400
+ Refs are shorter and more robust than CSS selectors for most agent workflows.
401
+
402
+ ### Incremental Snapshots
415
403
 
416
- Suppress with `--no-snap` for scripts doing rapid sequential actions:
404
+ The first snapshot returns the page tree. Later snapshots return only changed nodes unless you pass `--full`.
417
405
 
418
406
  ```bash
419
- chromex fill <target> @e1 "user@test.com" --no-snap
420
- chromex fill <target> @e2 "secret123" --no-snap
421
- chromex click <target> @e3 # Only this one triggers snapshot
407
+ chromex snap <target> --refs
408
+ chromex click <target> @e3
409
+ # The click response includes a fresh incremental snapshot with refs.
422
410
  ```
423
411
 
424
- ## MCP vs CLI
412
+ ### Query-Filtered Snapshots
425
413
 
426
- Both interfaces call the same core, same daemons, same commands. The difference is how they integrate with Claude Code.
414
+ Use `--query` to keep output small on large pages:
427
415
 
428
- | | CLI (`chromex-cli`) | MCP Server (`chromex-mcp`) |
429
- |---|---|---|
430
- | Token overhead | Zero schema cost | ~500 tokens per tool used (deferred loading) |
431
- | Auto-approve | Glob pattern in settings | `"mcp__chromex"` -- one line |
432
- | Permissions | All-or-nothing | Per-tool granularity |
433
- | Parameters | Positional string args | Typed JSON Schema |
434
- | Screenshots | File path (needs `Read` to view) | Inline image (base64, no extra call) |
435
- | Best for | Terminal, scripts, CI/CD, token-sensitive sessions | Plug-and-play automation, users who want zero-config |
416
+ ```bash
417
+ chromex snap <target> --query=issues --refs
418
+ chromex snap <target> --query="sign in" --refs
419
+ ```
436
420
 
437
- ### Switching Between MCP and CLI
421
+ Chromex preserves ancestor nodes so the filtered output still has usable context.
438
422
 
439
- You can enable and disable the MCP server at any time. The CLI always works regardless.
423
+ ### Contextual Hints
440
424
 
441
- **Disable MCP** (saves ~3-5k tokens per session):
425
+ After actions that refresh refs, Chromex can append a `help[N]:` block with likely next commands:
442
426
 
443
- ```bash
444
- claude mcp remove chromex
427
+ ```text
428
+ help[3]:
429
+ chromex fill <t> @e1 "<value>" # textbox "Email"
430
+ chromex click <t> @e3 # button "Sign in"
431
+ chromex click <t> @e4 # link "Forgot password?"
445
432
  ```
446
433
 
447
- The CLI (`chromex-cli`) continues working normally -- same commands, same daemons, no change.
434
+ Disable hints with `--no-hints`.
435
+
436
+ ## Application State Suite
448
437
 
449
- **Re-enable MCP:**
438
+ Chromex exposes browser Application panel state without Puppeteer, Playwright, 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.
450
439
 
451
440
  ```bash
452
- # Global (all projects)
453
- claude mcp add chromex -s user npx chromex-mcp@latest
441
+ # One-line overview for the current origin
442
+ chromex app <target> summary
454
443
 
455
- # Project-only
456
- claude mcp add chromex npx chromex-mcp@latest
457
- ```
444
+ # Origin quota and per-storage-type usage
445
+ chromex storage <target> usage
458
446
 
459
- **When to disable MCP:**
460
- - Token-sensitive sessions where every token counts
461
- - You only need occasional commands (`list`, `snap`, `shot`)
462
- - You're already comfortable with the CLI syntax
463
- - You're using chromex from terminal/scripts, not from Claude Code
447
+ # Service Worker registrations and versions
448
+ chromex sw <target>
449
+ chromex sw <target> update https://example.com/
450
+ chromex sw <target> skip-waiting https://example.com/
464
451
 
465
- **When to keep MCP enabled:**
466
- - Automating multi-step browser workflows (snap -> click -> fill -> snap)
467
- - You want per-tool auto-approve without glob patterns
468
- - You want inline screenshots without a separate `Read` call
469
- - First time using chromex (discovery via tool schema)
452
+ # Cache Storage
453
+ chromex cache <target> list
454
+ chromex cache <target> entries <cacheId> --query=/api
455
+ chromex cache <target> body <cacheId> https://example.com/app.js
470
456
 
471
- ### CLI Auto-Approve
457
+ # IndexedDB
458
+ chromex idb <target> list
459
+ chromex idb <target> schema app-db
460
+ chromex idb <target> rows app-db users --limit=20
461
+ ```
472
462
 
473
- If you prefer the CLI interface, add this to `~/.claude/settings.json`:
463
+ `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.
474
464
 
475
- ```json
476
- {
477
- "permissions": {
478
- "allow": [
479
- "Bash(chromex-cli *)"
480
- ]
481
- }
482
- }
483
- ```
465
+ Destructive Application commands are explicit: `storage clear-site-data`, `sw unregister`, `cache delete-entry`, `cache delete`, and `idb clear`.
484
466
 
485
467
  ## Security
486
468
 
487
- Config at `~/.chromex/config.json` (auto-created on first run):
469
+ Chromex creates `~/.chromex/config.json` on first run:
488
470
 
489
471
  ```json
490
472
  {
491
- "blockedDomains": ["mail.google.com", "bank.example.com"],
473
+ "commandTimeout": 15000,
474
+ "navigationTimeout": 30000,
475
+ "idleTimeout": 1200000,
492
476
  "allowedDomains": [],
493
- "blockedCdpMethods": ["Browser.close", "Storage.getCookies", "..."],
494
- "socketAuth": true,
495
- "auditLog": true
477
+ "blockedDomains": [],
478
+ "blockedCdpMethods": ["Browser.close", "Storage.getCookies"],
479
+ "auditLog": true,
480
+ "socketAuth": true
496
481
  }
497
482
  ```
498
483
 
499
- - **Domain filtering**: block sensitive sites or restrict to a whitelist
500
- - **CDP blocklist**: dangerous methods blocked by default in `evalraw`
501
- - **Socket auth**: 32-byte random token per session (mode 0600)
502
- - **Audit log**: every command logged with timestamp and status
484
+ Recommended security practices:
503
485
 
504
- See [docs/security.md](docs/security.md) for full details.
486
+ - Add sensitive sites to `blockedDomains`, such as email, banking, password managers, and admin panels.
487
+ - Use `allowedDomains` in restricted environments where the agent should access only specific hosts.
488
+ - Keep `socketAuth` enabled.
489
+ - Keep `auditLog` enabled and review `~/.chromex/audit.log` when needed.
490
+ - Prefer `chromex launch --profile testing` for isolated browser state.
505
491
 
506
- ## How It Works
492
+ See [docs/security.md](docs/security.md) for the full security model.
507
493
 
508
- 1. **Browser detection** -- scans ~30 paths for `DevToolsActivePort` (or use `CDP_PORT_FILE` env var)
509
- 2. **Daemon spawn** -- first command to a tab spawns a background Node.js process connected via CDP WebSocket
510
- 3. **Session persistence** -- daemon holds the session open; Chrome's "Allow" modal fires once per daemon
511
- 4. **Unix sockets** -- CLI/MCP communicates with daemon via authenticated Unix sockets
512
- 5. **Auto-exit** -- daemons shut down after 20 minutes of inactivity (configurable)
494
+ ## How It Works
513
495
 
514
- ```
515
- CLI Client ──Unix Socket + Auth──> Per-Tab Daemon ──CDP WebSocket──> Chrome
516
- MCP Server ──Unix Socket + Auth──> (same) ──CDP WebSocket──> Chrome
496
+ ```text
497
+ CLI or MCP client -> authenticated Unix socket -> per-tab daemon -> CDP WebSocket -> browser
517
498
  ```
518
499
 
519
- See [docs/architecture.md](docs/architecture.md) for the full deep dive.
500
+ 1. Chromex finds the browser DevTools endpoint from `DevToolsActivePort` or `CDP_PORT_FILE`.
501
+ 2. The first tab command starts a detached daemon for that tab.
502
+ 3. The daemon attaches once through CDP and keeps the session open.
503
+ 4. CLI and MCP commands talk to the daemon through an authenticated Unix socket.
504
+ 5. Daemons exit after the configured idle timeout.
505
+
506
+ See [docs/architecture.md](docs/architecture.md) for implementation details.
520
507
 
521
508
  ## Documentation
522
509
 
523
510
  | Guide | Description |
524
511
  |-------|-------------|
525
- | [Getting Started](docs/getting-started.md) | Installation, connection methods, first commands |
526
- | [Inspect & Debug](docs/inspect.md) | Screenshots, accessibility tree, refs, HTML, eval, network, performance, console |
527
- | [Navigate & Interact](docs/navigate.md) | Navigation, clicking, typing, scrolling, drag & drop, touch, dialogs |
528
- | [Form Filling](docs/forms.md) | Fill, clear, select, check, upload, batch fill with examples |
529
- | [Data Access](docs/data.md) | Cookies, localStorage, sessionStorage, PDF export |
530
- | [Network Control](docs/network.md) | Throttling, interception, mocking, HAR recording |
531
- | [Device Emulation](docs/emulation.md) | Responsive testing, geolocation, timezone, CPU throttling |
532
- | [Security](docs/security.md) | Domain filtering, CDP blocklist, audit log, best practices |
533
- | [Advanced](docs/advanced.md) | Script injection, code coverage, tracing, heap snapshots, WebAuthn |
534
- | [Architecture](docs/architecture.md) | How it works: daemon model, connection modes, file layout |
512
+ | [Getting Started](docs/getting-started.md) | Installation, browser setup, first commands. |
513
+ | [Inspect and Debug](docs/inspect.md) | Screenshots, accessibility tree, refs, HTML, eval, network, performance, console. |
514
+ | [Navigate and Interact](docs/navigate.md) | Navigation, clicking, typing, scrolling, drag and drop, touch, dialogs. |
515
+ | [Form Filling](docs/forms.md) | Fill, clear, select, check, upload, batch form examples. |
516
+ | [Data Access](docs/data.md) | Cookies, localStorage, sessionStorage, Application state, Cache Storage, IndexedDB, Service Workers, PDF export. |
517
+ | [Network Control](docs/network.md) | Throttling, interception, mocking, HAR recording. |
518
+ | [Device Emulation](docs/emulation.md) | Responsive testing, geolocation, timezone, CPU throttling. |
519
+ | [Security](docs/security.md) | Domain filtering, CDP blocklist, audit log, best practices. |
520
+ | [Advanced](docs/advanced.md) | Script injection, code coverage, tracing, heap snapshots, WebAuthn. |
521
+ | [Architecture](docs/architecture.md) | Daemon model, connection modes, and file layout. |
522
+
523
+ ## Development
524
+
525
+ ```bash
526
+ git clone https://github.com/whallysson/chromex.git
527
+ cd chromex
528
+ bun install
529
+ bun run test
530
+ ```
531
+
532
+ The runtime package has no dependencies. Development dependencies are used only for tests and token benchmarks.
533
+
534
+ To reproduce the token-format comparison:
535
+
536
+ ```bash
537
+ bun tests/benchmarks/token-format-comparison.mjs
538
+ ```
535
539
 
536
540
  ## License
537
541
 
538
- MIT
542
+ MIT. See [LICENSE](LICENSE).