|
1 | 1 | --- |
2 | 2 | name: chrome-devtools |
3 | | -description: Uses Chrome DevTools via MCP for efficient debugging, troubleshooting and browser automation. Use when debugging web pages, automating browser interactions, analyzing performance, or inspecting network requests. |
| 3 | +description: Uses Chrome DevTools via MCP for debugging, browser automation, web scraping with Puppeteer, WebSocket inspection, performance analysis, and network debugging. Use when automating browsers, scraping pages, intercepting or analyzing WebSocket traffic, debugging web apps, or recording performance traces. |
4 | 4 | --- |
5 | 5 |
|
6 | | -## Core Concepts |
| 6 | +## Project overview |
| 7 | + |
| 8 | +**Chrome DevTools MCP** is an MCP server that controls a live Chrome instance via Puppeteer and Chrome DevTools Protocol (CDP). It gives AI assistants tools for navigation, interaction, snapshots, network inspection (including WebSocket), console messages, performance traces, and script evaluation. The server starts Chrome on first tool use; you can also connect to an existing Chrome with `--browser-url` or `--wsEndpoint`. |
| 9 | + |
| 10 | +- **Docs**: [Tool reference](../../docs/tool-reference.md), [Design principles](../../docs/design-principles.md), [Troubleshooting](../../docs/troubleshooting.md) |
| 11 | +- **Puppeteer**: Used under the hood for browser launch, pages, and CDP; you interact via MCP tools, not Puppeteer API directly. |
| 12 | + |
| 13 | +## Core concepts |
7 | 14 |
|
8 | 15 | **Browser lifecycle**: Browser starts automatically on first tool call using a persistent Chrome profile. Configure via CLI args in the MCP server configuration: `npx chrome-devtools-mcp@latest --help`. |
9 | 16 |
|
10 | 17 | **Page selection**: Tools operate on the currently selected page. Use `list_pages` to see available pages, then `select_page` to switch context. |
11 | 18 |
|
12 | | -**Element interaction**: Use `take_snapshot` to get page structure with element `uid`s. Each element has a unique `uid` for interaction. If an element isn't found, take a fresh snapshot - the element may have been removed or the page changed. |
| 19 | +**Element interaction**: Use `take_snapshot` to get page structure with element `uid`s. Each element has a unique `uid` for interaction. If an element isn't found, take a fresh snapshot—the element may have been removed or the page changed. |
| 20 | + |
| 21 | +## Discovering scraping opportunities (Network-first) |
| 22 | + |
| 23 | +**Best first step**: Use the **Network** tools to see *how* the page gets its data. Many sites load content via **XHR** or **fetch**; if you find that API and its response is JSON (or structured), you can often use the same API instead of parsing HTML. |
| 24 | + |
| 25 | +1. **Load and trigger**: `navigate_page` to the target URL; if needed, interact (click, search) so the data you want is loaded. |
| 26 | +2. **List API requests**: `list_network_requests` with **resourceTypes: `['xhr', 'fetch']`** to see only API-style requests. Scan for URLs that look like data endpoints (e.g. `api/`, `graphql`, query params). |
| 27 | +3. **Inspect one**: `get_network_request(reqid)` for a promising request. Check **response body**—if it’s JSON with the data you need, prefer **reusing that API** (same URL, method, headers, body) over DOM scraping. |
| 28 | +4. **Decide**: Structured response → use the API. No usable API or auth-only → use DOM: snapshot + `evaluate_script` (see “Workflow: Web scraping” below). |
| 29 | + |
| 30 | +Full step-by-step and “API vs DOM” guidance: [network-for-scraping-discovery.md](./network-for-scraping-discovery.md). |
| 31 | + |
| 32 | +## Workflow: Web scraping (Puppeteer-style) |
| 33 | + |
| 34 | +Use the MCP tools as a “Puppeteer-like” scraping pipeline: navigate, wait, snapshot, then extract data with snapshots and/or page scripts. |
| 35 | + |
| 36 | +1. **Navigate**: `navigate_page` (type=url, url=…) or `new_page` (url=…). |
| 37 | +2. **Wait**: `wait_for` (text=…) to wait for specific content, or use a short delay and then snapshot. |
| 38 | +3. **Snapshot**: `take_snapshot` to get the accessibility tree and element `uid`s. Prefer snapshot over screenshot for automation (faster, text-based). |
| 39 | +4. **Extract**: |
| 40 | + - **From tree**: Use the snapshot text and structure; click/fill by `uid` if you need to open modals or paginate. |
| 41 | + - **From page**: Use `evaluate_script` to run JavaScript in the page and return JSON-serializable data (e.g. `() => document.querySelectorAll('h2').length`, or extract table rows, meta tags, or any DOM/data). |
| 42 | +5. **Pagination or multi-page**: Use `click` on “next” (by `uid`), then wait + snapshot again, or `navigate_page` to new URLs and repeat. |
| 43 | + |
| 44 | +**Tips**: Use `filePath` on `take_snapshot` for large pages. For data not in the a11y tree (e.g. attributes, computed styles), use `evaluate_script`. Iframes are not in the snapshot—only the main frame is represented. |
13 | 45 |
|
14 | | -## Workflow Patterns |
| 46 | +## Workflow: WebSocket inspection / “interception” |
15 | 47 |
|
16 | | -### Before interacting with a page |
| 48 | +The server does not inject code into the page; it uses DevTools network data. You can **list and inspect** WebSocket (and other) requests. |
| 49 | + |
| 50 | +1. **Navigate** to the page that opens WebSockets: `navigate_page` (url=…). |
| 51 | +2. **Trigger** the WebSocket (use the app or wait for it to connect). |
| 52 | +3. **List requests**: `list_network_requests` with `resourceTypes: ['websocket']` to see only WebSocket requests. Omit `resourceTypes` to see all (document, xhr, fetch, websocket, etc.). |
| 53 | +4. **Inspect one request**: `get_network_request` with the `reqid` from the list. Use `requestFilePath` / `responseFilePath` to save bodies to files (useful for large or binary payloads). |
| 54 | + |
| 55 | +**Resource types** (for `list_network_requests`) include: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `xhr`, `fetch`, `eventsource`, **`websocket`**, `manifest`, `ping`, `preflight`, `other`, etc. Use these to filter by kind of traffic. |
| 56 | + |
| 57 | +**Note**: You see WebSocket *requests* (URL, timing, headers). Live message-by-message capture is limited to what DevTools exposes in the network list and request/response details. |
| 58 | + |
| 59 | +## General workflow (before interacting) |
17 | 60 |
|
18 | 61 | 1. Navigate: `navigate_page` or `new_page` |
19 | | -2. Wait: `wait_for` to ensure content is loaded if you know what you look for. |
20 | | -3. Snapshot: `take_snapshot` to understand page structure |
21 | | -4. Interact: Use element `uid`s from snapshot for `click`, `fill`, etc. |
| 62 | +2. Wait: `wait_for` if you know what text to wait for |
| 63 | +3. Snapshot: `take_snapshot` to get structure and `uid`s |
| 64 | +4. Interact: Use `uid`s from snapshot for `click`, `fill`, `fill_form`, `hover`, `drag`, `press_key`, `upload_file` |
| 65 | +5. Dialogs: Use `handle_dialog` (accept/dismiss, optional `promptText`) when alerts/confirms appear |
| 66 | + |
| 67 | +## Tool selection quick reference |
| 68 | + |
| 69 | +| Goal | Preferred tool(s) | |
| 70 | +|------|-------------------| |
| 71 | +| Automation / scraping | `take_snapshot`, `click`, `fill`, `evaluate_script` | |
| 72 | +| Visual check | `take_screenshot` (optionally `fullPage`, `uid` for element) | |
| 73 | +| Data not in a11y tree | `evaluate_script` (must return JSON-serializable values) | |
| 74 | +| List HTTP/WebSocket requests | `list_network_requests` (optional `resourceTypes: ['websocket']`) | |
| 75 | +| Inspect one request/response | `get_network_request` (reqid, optional file paths for bodies) | |
| 76 | +| Console errors/warnings | `list_console_messages` (optional `types`), `get_console_message` | |
| 77 | +| Performance / CWV | `performance_start_trace`, `performance_stop_trace`, `performance_analyze_insight` | |
| 78 | +| Emulation | `emulate` (viewport, userAgent, networkConditions, etc.), `resize_page` | |
22 | 79 |
|
23 | | -### Efficient data retrieval |
| 80 | +See [Tool reference](../../docs/tool-reference.md) for full parameters. |
24 | 81 |
|
25 | | -- Use `filePath` parameter for large outputs (screenshots, snapshots, traces) |
26 | | -- Use pagination (`pageIdx`, `pageSize`) and filtering (`types`) to minimize data |
27 | | -- Set `includeSnapshot: false` on input actions unless you need updated page state |
| 82 | +## Formatters (internal) |
28 | 83 |
|
29 | | -### Tool selection |
| 84 | +Tool responses are shaped by internal formatters. You don’t call them directly; they affect what the agent sees: |
30 | 85 |
|
31 | | -- **Automation/interaction**: `take_snapshot` (text-based, faster, better for automation) |
32 | | -- **Visual inspection**: `take_screenshot` (when user needs to see visual state) |
33 | | -- **Additional details**: `evaluate_script` for data not in accessibility tree |
| 86 | +- **SnapshotFormatter**: Turns the a11y tree into the text snapshot with `uid`s and optional “selected in DevTools” hint. Use `verbose: true` on `take_snapshot` for more detail. |
| 87 | +- **NetworkFormatter**: Formats request/response (URL, status, headers, body). Large bodies can be truncated or written to `requestFilePath`/`responseFilePath`. |
| 88 | +- **ConsoleFormatter**: Formats console messages (level, text, stack, resolved arguments when detailed data is requested). |
| 89 | +- **IssueFormatter**: Formats DevTools “issues” (e.g. deprecations, violations) when included in responses. |
34 | 90 |
|
35 | | -### Parallel execution |
| 91 | +A full **Network & Console breakdown** (data flow, collectors, filter options, what you see in responses) is in [network-and-console-breakdown.md](./network-and-console-breakdown.md). |
36 | 92 |
|
37 | | -You can send multiple tool calls in parallel, but maintain correct order: navigate → wait → snapshot → interact. |
| 93 | +## Telemetry |
| 94 | + |
| 95 | +Google collects usage statistics (e.g. tool invocation success, latency, environment) to improve the server. Collection is **on by default**. |
| 96 | + |
| 97 | +- **Opt-out**: Start the server with `--no-usage-statistics` (or set `CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS` or `CI`). |
| 98 | +- **Config example**: `"args": ["-y", "chrome-devtools-mcp@latest", "--no-usage-statistics"]` |
| 99 | +- Data is handled per [Google Privacy Policy](https://policies.google.com/privacy); independent of Chrome browser metrics. |
| 100 | + |
| 101 | +## Efficient usage |
| 102 | + |
| 103 | +- Use `filePath` for large outputs (screenshots, snapshots, traces, request/response bodies). |
| 104 | +- Use pagination (`pageIdx`, `pageSize`) and filters (`resourceTypes`, `types` for console) to limit data. |
| 105 | +- Set `includeSnapshot: false` on input actions (click, fill, etc.) unless you need an updated snapshot in the same response. |
| 106 | +- Run independent tool calls in parallel when order allows (e.g. multiple `get_network_request` by reqid); keep sequence for navigate → wait → snapshot → interact. |
38 | 107 |
|
39 | 108 | ## Troubleshooting |
40 | 109 |
|
41 | | -If `chrome-devtools-mcp` is insufficient, guide users to use Chrome DevTools UI: |
| 110 | +If the MCP tools are insufficient, suggest using Chrome DevTools directly: |
42 | 111 |
|
43 | 112 | - https://developer.chrome.com/docs/devtools |
44 | 113 | - https://developer.chrome.com/docs/devtools/ai-assistance |
| 114 | + |
| 115 | +For connection issues, headless vs headed, or remote debugging, see [Troubleshooting](../../docs/troubleshooting.md). |
0 commit comments