@pyrokine/mcp-chrome 2.0.2 → 2.2.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 (80) hide show
  1. package/README.md +86 -35
  2. package/README_zh.md +570 -0
  3. package/dist/cdp/launcher.d.ts.map +1 -1
  4. package/dist/cdp/launcher.js +41 -19
  5. package/dist/cdp/launcher.js.map +1 -1
  6. package/dist/core/browser-driver.d.ts +118 -1
  7. package/dist/core/browser-driver.d.ts.map +1 -1
  8. package/dist/core/browser-driver.js +11 -0
  9. package/dist/core/browser-driver.js.map +1 -1
  10. package/dist/core/error-sanitizer.js +2 -2
  11. package/dist/core/error-sanitizer.js.map +1 -1
  12. package/dist/core/errors.d.ts.map +1 -1
  13. package/dist/core/errors.js +17 -4
  14. package/dist/core/errors.js.map +1 -1
  15. package/dist/core/index.d.ts +1 -1
  16. package/dist/core/index.d.ts.map +1 -1
  17. package/dist/core/index.js +1 -1
  18. package/dist/core/index.js.map +1 -1
  19. package/dist/core/locator.d.ts.map +1 -1
  20. package/dist/core/locator.js +4 -3
  21. package/dist/core/locator.js.map +1 -1
  22. package/dist/core/session.d.ts +5 -2
  23. package/dist/core/session.d.ts.map +1 -1
  24. package/dist/core/session.js +107 -4
  25. package/dist/core/session.js.map +1 -1
  26. package/dist/core/types.d.ts +24 -1
  27. package/dist/core/types.d.ts.map +1 -1
  28. package/dist/core/types.js +77 -4
  29. package/dist/core/types.js.map +1 -1
  30. package/dist/core/unified-session.d.ts +38 -9
  31. package/dist/core/unified-session.d.ts.map +1 -1
  32. package/dist/core/unified-session.js +291 -18
  33. package/dist/core/unified-session.js.map +1 -1
  34. package/dist/core/utils.d.ts +1 -0
  35. package/dist/core/utils.d.ts.map +1 -1
  36. package/dist/core/utils.js +35 -7
  37. package/dist/core/utils.js.map +1 -1
  38. package/dist/extension/bridge.d.ts +37 -22
  39. package/dist/extension/bridge.d.ts.map +1 -1
  40. package/dist/extension/bridge.js +223 -63
  41. package/dist/extension/bridge.js.map +1 -1
  42. package/dist/extension/http-server.d.ts +6 -0
  43. package/dist/extension/http-server.d.ts.map +1 -1
  44. package/dist/extension/http-server.js +125 -14
  45. package/dist/extension/http-server.js.map +1 -1
  46. package/dist/tools/browse.d.ts.map +1 -1
  47. package/dist/tools/browse.js +153 -54
  48. package/dist/tools/browse.js.map +1 -1
  49. package/dist/tools/cookies.d.ts.map +1 -1
  50. package/dist/tools/cookies.js +2 -4
  51. package/dist/tools/cookies.js.map +1 -1
  52. package/dist/tools/evaluate.d.ts.map +1 -1
  53. package/dist/tools/evaluate.js +37 -10
  54. package/dist/tools/evaluate.js.map +1 -1
  55. package/dist/tools/extract.d.ts +1 -0
  56. package/dist/tools/extract.d.ts.map +1 -1
  57. package/dist/tools/extract.js +466 -227
  58. package/dist/tools/extract.js.map +1 -1
  59. package/dist/tools/input.d.ts.map +1 -1
  60. package/dist/tools/input.js +781 -444
  61. package/dist/tools/input.js.map +1 -1
  62. package/dist/tools/logs.d.ts.map +1 -1
  63. package/dist/tools/logs.js +75 -23
  64. package/dist/tools/logs.js.map +1 -1
  65. package/dist/tools/manage.d.ts +0 -3
  66. package/dist/tools/manage.d.ts.map +1 -1
  67. package/dist/tools/manage.js +339 -285
  68. package/dist/tools/manage.js.map +1 -1
  69. package/dist/tools/png.d.ts +16 -0
  70. package/dist/tools/png.d.ts.map +1 -0
  71. package/dist/tools/png.js +197 -0
  72. package/dist/tools/png.js.map +1 -0
  73. package/dist/tools/schema.d.ts +14 -112
  74. package/dist/tools/schema.d.ts.map +1 -1
  75. package/dist/tools/schema.js +21 -12
  76. package/dist/tools/schema.js.map +1 -1
  77. package/dist/tools/wait.d.ts.map +1 -1
  78. package/dist/tools/wait.js +73 -13
  79. package/dist/tools/wait.js.map +1 -1
  80. package/package.json +16 -13
package/README.md CHANGED
@@ -69,8 +69,9 @@ Extension mode controls your existing Chrome — shares login sessions, cookies,
69
69
  claude mcp add chrome -- node /path/to/mcp-chrome/dist/index.js
70
70
  ```
71
71
 
72
+ Claude Desktop / Other Clients:
73
+
72
74
  ```json
73
- // Claude Desktop / Other Clients
74
75
  {
75
76
  "mcpServers": {
76
77
  "chrome": {
@@ -94,6 +95,15 @@ browse(action="open", url="https://example.com")
94
95
  extract(type="screenshot")
95
96
  ```
96
97
 
98
+ **Optional pairing token**
99
+
100
+ By default, local Extension mode does not require a token. To restrict the Extension connection, start the MCP server
101
+ with `MCP_CHROME_PAIRING_TOKEN`, then enter the same token in the Extension popup:
102
+
103
+ ```bash
104
+ MCP_CHROME_PAIRING_TOKEN="your-token" node /path/to/mcp-chrome/dist/index.js
105
+ ```
106
+
97
107
  ### Mode 2: CDP Mode (Fallback)
98
108
 
99
109
  CDP mode launches or connects to a dedicated Chrome instance. Used when the Extension is not installed, or for
@@ -128,10 +138,14 @@ browse(action="open", url="https://example.com")
128
138
  | `refresh` | Reload page |
129
139
  | `close` | Close browser connection |
130
140
 
131
- Extension-specific: `list` returns additional fields: `managed` (whether tab is in MCP Chrome group), `isActive`
132
- (whether it's the current operation target), `windowId`, `index`, `pinned`, `incognito`, `status` (`loading`/
133
- `complete`).
134
- `open` auto-creates tab group (cyan color).
141
+ Extension-specific: `list` returns the flat `targets` array plus a `windows` tree. Each target includes `managed`
142
+ (whether tab is controlled by MCP Chrome), `isActive` (whether it's the current operation target), `windowId`, `index`,
143
+ `pinned`, `incognito`, and `status` (`loading`/`complete`). The tree includes `windowCount`, `focusedWindowId`,
144
+ `activeTargetId`, and each window's ordered `tabs` list, so callers can distinguish the active tab inside each window
145
+ from the page currently visible in the focused window.
146
+ `open` auto-creates tab group (cyan color). `open`, `back`, `forward`, and `refresh` accept `diagnostics=true` to return
147
+ new console warnings/errors and failed network requests observed during the action, including the first `open` that
148
+ creates a page automatically.
135
149
 
136
150
  ### input - Keyboard & Mouse Input
137
151
 
@@ -150,6 +164,9 @@ Event sequence model supporting arbitrary combinations:
150
164
  | `select` | Select text by content (mouse sim) |
151
165
  | `replace` | Find and replace text |
152
166
  | `drag` | HTML5 drag-and-drop (DragEvent in MAIN world, with `target` source + `to` target) |
167
+ | `editorContext` | Read focused editor and selection context |
168
+ | `editorInsert` | Insert text at the current editor selection |
169
+ | `editorCommand` | Execute browser editing commands such as `bold` or `insertOrderedList` |
153
170
 
154
171
  Special-case parameters:
155
172
 
@@ -158,12 +175,17 @@ Special-case parameters:
158
175
  CDP commands API has no JS-event equivalent.
159
176
  - `keydown` on a key already held emits `rawKeyDown` with `autoRepeat: true` (Puppeteer-compatible long-press).
160
177
 
161
- Parameters: `humanize` enables Bézier curve movement and random delays. `tabId` targets a specific tab. `frame` targets
162
- an iframe (CSS selector or index). Both Extension mode only.
178
+ Parameters: `humanize` enables Bézier curve movement and random delays. `diagnostics=true` returns new console
179
+ warnings/errors and failed network requests after the action. `tabId` targets a specific tab. `frame` targets an
180
+ iframe (CSS selector or index). Both Extension mode only.
163
181
 
164
- **`click`-specific**: `force: true` skips actionability checks (useful for testing or hidden elements).
165
- **`type`-specific**: `dispatch: true` sets `.value` directly and fires `input`/`change` events use for React/Vue
166
- controlled inputs where keyboard events don't update state. Requires a non-coordinate `target`. Extension mode only.
182
+ **`click`-specific**: `force: true` skips actionability checks (useful for testing or hidden elements). Actionability
183
+ failures return `ACTIONABILITY_FAILED` with `rect`, `clickPoint`, covering element details, candidate blockers, and
184
+ suggestions.
185
+ **`type`-specific**: `mode="controlled"` or `dispatch: true` sets `.value` directly and fires `input`/`change` events —
186
+ use for React/Vue controlled inputs where keyboard events don't update state. Requires a non-coordinate `target`.
187
+ Extension mode only. Controlled input and target lookup failures return structured context with `target`, `matchCount`,
188
+ `nth`, `activeElement`, `selection`, and candidate controls.
167
189
 
168
190
  ### extract - Content Extraction
169
191
 
@@ -171,13 +193,20 @@ controlled inputs where keyboard events don't update state. Requires a non-coord
171
193
  |--------------|---------------------------------------------------|
172
194
  | `text` | Extract text content |
173
195
  | `html` | Extract HTML source |
196
+ | `frameHtml` | Extract HTML from the selected iframe |
174
197
  | `attribute` | Extract element attribute |
175
198
  | `screenshot` | Take screenshot (supports `target` element crop) |
176
199
  | `state` | Get page state (URL, title, interactive elements) |
177
200
  | `metadata` | Extract page metadata (title, OG, JSON-LD, etc.) |
178
201
 
179
202
  Parameters: `output` saves result to file (or directory for `images=data`). `images` (`info`/`data`) extracts image
180
- metadata or data alongside HTML. `tabId` targets a specific tab. `frame` targets an iframe. Both Extension mode only.
203
+ metadata or data alongside HTML. `frameHtml` extracts the current iframe document after `frame` routing. Screenshot
204
+ accepts `clip` for coordinate-region capture, `compareWith` for PNG baseline comparison, and `diffOutput` for a PNG diff
205
+ image. Screenshot responses include `metadata.format`, `width`, `height`, `dimensionSource`, `byteSize`, `fullPage`,
206
+ `scale`, `clip`, and `capabilities`. PNG comparison is capped before decode at 25 MiB per PNG and 12,000,000 pixels; use
207
+ `clip` or `scale` for larger captures. Hidden Extension tabs return `HIDDEN_TAB_SCREENSHOT` instead of auto-focusing the
208
+ browser. `state` returns `interactiveElements`; `metadata` returns `frames` in both Extension and CDP modes. `tabId`
209
+ targets a specific tab. `frame` targets an iframe. Both Extension mode only.
181
210
 
182
211
  **`attribute` special prefix**: `computed:<property>` returns the computed CSS style value (e.g. `computed:color`,
183
212
  `computed:font-size`). Use `computed:*` to return all computed style properties as JSON (returns 300+ properties — use
@@ -206,37 +235,55 @@ the DOM settled, `domStable: false` if still mutating when the budget ran out.
206
235
 
207
236
  Execute JavaScript in page context.
208
237
 
209
- | Parameter | Description |
210
- |--------------|----------------------------------------------------------------------------|
211
- | `script` | JavaScript code. Bare `return` statements auto-wrapped in IIFE |
212
- | `scriptFile` | Read script from a local file (alternative to `script`, relative paths default to controlled temp dir, use `cwd:` for repo files) |
213
- | `args` | Arguments passed to script (script must be a function expression) |
214
- | `mode` | `precise` (default, debugger API) or `stealth` (JS injection) |
215
- | `output` | Save result to file (relative paths default to controlled temp dir, use `cwd:` to persist in repo) |
216
- | `tabId` | Target a specific tab (Extension mode) |
217
- | `frame` | Target an iframe by CSS selector or index (Extension mode) |
218
- | `timeout` | End-to-end budget (ms) |
238
+ | Parameter | Description |
239
+ |---------------|-----------------------------------------------------------------------------------------------------------------------------------|
240
+ | `script` | JavaScript code. Bare `return` statements auto-wrapped in IIFE |
241
+ | `scriptFile` | Read script from a local file (alternative to `script`, relative paths default to controlled temp dir, use `cwd:` for repo files) |
242
+ | `args` | Arguments passed to script (script must be a function expression) |
243
+ | `mode` | `precise` (default, debugger API) or `stealth` (JS injection) |
244
+ | `output` | Save result to file (relative paths default to controlled temp dir, use `cwd:` to persist in repo) |
245
+ | `tabId` | Target a specific tab (Extension mode) |
246
+ | `frame` | Target an iframe by CSS selector or index (Extension mode) |
247
+ | `timeout` | End-to-end budget (ms) |
248
+ | `diagnostics` | Return new console warnings/errors and failed network requests after execution |
219
249
 
220
250
  `script` and `scriptFile` are mutually exclusive; at least one must be provided. Relative `scriptFile` and `output`
221
251
  paths default to the OS temp directory managed by `mcp-chrome`. Use `cwd:relative/path` when the file must live in the
222
252
  current working directory. Relative paths reject `..`, and on Windows they also reject `:` to avoid NTFS alternate data
223
253
  streams.
224
254
 
225
- Results >100KB are auto-saved to the controlled OS temp directory with a structured hint returned.
255
+ Results >100KB are auto-saved to the controlled OS temp directory with a structured hint returned. DOM nodes,
256
+ `NodeList`, and `HTMLCollection` results return `NON_SERIALIZABLE_EVALUATE_RESULT` with a hint to return simple fields
257
+ such as `textContent` or `outerHTML`.
226
258
 
227
259
  ### manage - Page & Environment Management
228
260
 
229
- | Action | Description |
230
- |--------------|-----------------------------------------------------------|
231
- | `newPage` | Create new page/tab |
232
- | `closePage` | Close page |
233
- | `clearCache` | Clear cache/storage (use `cookies` tool to clear cookies) |
234
- | `viewport` | Set viewport size |
235
- | `userAgent` | Set User-Agent |
236
- | `emulate` | Device emulation (iPhone, iPad, etc.) |
237
- | `inputMode` | Query or set input mode (`precise` / `stealth`) |
238
- | `stealth` | Inject anti-detection scripts |
239
- | `cdp` | Send raw CDP command (advanced, e.g. `Runtime.evaluate`) |
261
+ | Action | Description |
262
+ |----------------|------------------------------------------------------------|
263
+ | `newPage` | Create new controlled page/tab |
264
+ | `closePage` | Close controlled page and return `affected.before/after` |
265
+ | `adoptPage` | Mark an existing tab as controlled without focusing it |
266
+ | `releasePage` | Remove a controlled tab from management without closing it |
267
+ | `movePage` | Move a controlled tab to another window or index |
268
+ | `reorderPage` | Reorder a controlled tab inside its window |
269
+ | `pinPage` | Pin a controlled tab |
270
+ | `unpinPage` | Unpin a controlled tab |
271
+ | `activatePage` | Activate a controlled tab and focus its window |
272
+ | `focusWindow` | Focus an explicit window |
273
+ | `resizeWindow` | Resize or change state for an explicit window |
274
+ | `newWindow` | Create a new controlled window |
275
+ | `closeWindow` | Close a window only when all tabs are managed |
276
+ | `clearCache` | Clear cache/storage (use `cookies` tool to clear cookies) |
277
+ | `viewport` | Set viewport size |
278
+ | `userAgent` | Set User-Agent |
279
+ | `emulate` | Device emulation (iPhone, iPad, etc.) |
280
+ | `inputMode` | Query or set input mode (`precise` / `stealth`) |
281
+ | `stealth` | Inject anti-detection scripts |
282
+ | `cdp` | Send raw CDP command (advanced, e.g. `Runtime.evaluate`) |
283
+
284
+ Tab/window management actions are Extension-mode only. Actions that change visible browser state require explicit
285
+ `targetId` or `windowId` and return `affected.before/after`. `closeWindow` refuses mixed windows with unmanaged tabs and
286
+ returns `WINDOW_HAS_UNMANAGED_TABS`.
240
287
 
241
288
  **Stealth mode levels** (CDP launch parameter, set via `browse action=launch stealth=...`):
242
289
 
@@ -251,8 +298,9 @@ Results >100KB are auto-saved to the controlled OS temp directory with a structu
251
298
  | `console` | Console logs (with level filter) |
252
299
  | `network` | Network request logs (with URL filter) |
253
300
 
254
- Parameters: `output` saves result to file. `tabId` targets a specific tab (Extension mode). `frame` is not applicable
255
- for logs.
301
+ Parameters: `output` saves result to file. Network logs include completed requests, HTTP 4xx/5xx responses, and failed
302
+ loads with `errorText`, `method`, `url`, `status`, `timestamp`, and `duration` when available. `tabId` targets a
303
+ specific tab (Extension mode). `frame` is not applicable for logs.
256
304
 
257
305
  ### cookies - Cookie Management
258
306
 
@@ -274,6 +322,9 @@ All tools use a unified `Target` type for element location:
274
322
  // By accessibility (recommended - most stable)
275
323
  { role: "button", name: "Submit" }
276
324
 
325
+ // By accessibility with exact accessible name
326
+ { role: "button", name: "Submit", exact: true }
327
+
277
328
  // By text content
278
329
  { text: "Click here", exact: true }
279
330