chrome-devtools-mcp 1.3.0 → 1.4.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 +37 -2
- package/build/src/bin/check-latest-version.js +1 -0
- package/build/src/bin/chrome-devtools-mcp-cli-options.js +2 -2
- package/build/src/formatters/NetworkFormatter.js +3 -1
- package/build/src/third_party/THIRD_PARTY_NOTICES +3 -3
- package/build/src/third_party/bundled-packages.json +3 -3
- package/build/src/third_party/devtools-heap-snapshot-worker.js +13 -0
- package/build/src/third_party/index.js +1522 -230
- package/build/src/utils/check-for-updates.js +1 -0
- package/build/src/version.js +1 -1
- package/package.json +7 -6
- package/skills/a11y-debugging/SKILL.md +89 -0
- package/skills/a11y-debugging/references/a11y-snippets.md +92 -0
- package/skills/chrome-devtools/SKILL.md +72 -0
- package/skills/chrome-devtools-cli/SKILL.md +153 -0
- package/skills/chrome-devtools-cli/references/installation.md +14 -0
- package/skills/debug-optimize-lcp/SKILL.md +121 -0
- package/skills/debug-optimize-lcp/references/elements-and-size.md +27 -0
- package/skills/debug-optimize-lcp/references/lcp-breakdown.md +23 -0
- package/skills/debug-optimize-lcp/references/lcp-snippets.md +79 -0
- package/skills/debug-optimize-lcp/references/optimization-strategies.md +38 -0
- package/skills/memory-leak-debugging/SKILL.md +50 -0
- package/skills/memory-leak-debugging/references/common-leaks.md +33 -0
- package/skills/memory-leak-debugging/references/compare_snapshots.js +109 -0
- package/skills/memory-leak-debugging/references/memlab.md +29 -0
- package/skills/troubleshooting/SKILL.md +98 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# LCP Debugging Snippets
|
|
2
|
+
|
|
3
|
+
Use these JavaScript snippets with the `evaluate_script` tool to extract deep insights from the page.
|
|
4
|
+
|
|
5
|
+
## 1. Identify LCP Element
|
|
6
|
+
|
|
7
|
+
Use this snippet to identify the LCP element and get raw timing data from the Performance API.
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
async () => {
|
|
11
|
+
return await new Promise(resolve => {
|
|
12
|
+
new PerformanceObserver(list => {
|
|
13
|
+
const entries = list.getEntries();
|
|
14
|
+
const last = entries[entries.length - 1];
|
|
15
|
+
resolve({
|
|
16
|
+
element: last.element?.tagName,
|
|
17
|
+
id: last.element?.id,
|
|
18
|
+
className: last.element?.className,
|
|
19
|
+
url: last.url,
|
|
20
|
+
startTime: last.startTime,
|
|
21
|
+
renderTime: last.renderTime,
|
|
22
|
+
loadTime: last.loadTime,
|
|
23
|
+
size: last.size,
|
|
24
|
+
});
|
|
25
|
+
}).observe({type: 'largest-contentful-paint', buffered: true});
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 2. Audit Common Issues
|
|
31
|
+
|
|
32
|
+
Use this snippet to check for common DOM-based LCP issues (lazy loading, priority).
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
() => {
|
|
36
|
+
const issues = [];
|
|
37
|
+
|
|
38
|
+
// Check for lazy-loaded images in viewport
|
|
39
|
+
document.querySelectorAll('img[loading="lazy"]').forEach(img => {
|
|
40
|
+
const rect = img.getBoundingClientRect();
|
|
41
|
+
if (rect.top < window.innerHeight) {
|
|
42
|
+
issues.push({
|
|
43
|
+
issue: 'lazy-loaded image in viewport',
|
|
44
|
+
element: img.outerHTML.substring(0, 200),
|
|
45
|
+
fix: 'Remove loading="lazy" from this image — it is in the initial viewport and may be the LCP element',
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Check for LCP-candidate images missing fetchpriority
|
|
51
|
+
document.querySelectorAll('img:not([fetchpriority])').forEach(img => {
|
|
52
|
+
const rect = img.getBoundingClientRect();
|
|
53
|
+
if (rect.top < window.innerHeight && rect.width * rect.height > 50000) {
|
|
54
|
+
issues.push({
|
|
55
|
+
issue: 'large viewport image without fetchpriority',
|
|
56
|
+
element: img.outerHTML.substring(0, 200),
|
|
57
|
+
fix: 'Add fetchpriority="high" to this image — it is large and visible in the initial viewport',
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Check for render-blocking scripts in head
|
|
63
|
+
document
|
|
64
|
+
.querySelectorAll(
|
|
65
|
+
'head script:not([async]):not([defer]):not([type="module"])',
|
|
66
|
+
)
|
|
67
|
+
.forEach(script => {
|
|
68
|
+
if (script.src) {
|
|
69
|
+
issues.push({
|
|
70
|
+
issue: 'render-blocking script in head',
|
|
71
|
+
element: script.outerHTML.substring(0, 200),
|
|
72
|
+
fix: 'Add async or defer attribute, or move to end of body',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return {issueCount: issues.length, issues};
|
|
78
|
+
};
|
|
79
|
+
```
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# LCP Optimization Strategies
|
|
2
|
+
|
|
3
|
+
## 1. Eliminate Resource Load Delay
|
|
4
|
+
|
|
5
|
+
**Goal**: Ensure the LCP resource starts loading as early as possible.
|
|
6
|
+
|
|
7
|
+
- **Early Discovery**: Ensure the LCP resource is discoverable in the initial HTML document response (not dynamically added by JS or hidden in `data-src`).
|
|
8
|
+
- **Preload**: Use `<link rel="preload">` with `fetchpriority="high"` for critical images or fonts.
|
|
9
|
+
- **Avoid Lazy Loading**: Never set `loading="lazy"` on the LCP image.
|
|
10
|
+
- **Fetch Priority**: Use `fetchpriority="high"` on the `<img>` tag.
|
|
11
|
+
- **Same Origin**: Host critical resources on the same origin or use `<link rel="preconnect">`.
|
|
12
|
+
|
|
13
|
+
## 2. Eliminate Element Render Delay
|
|
14
|
+
|
|
15
|
+
**Goal**: Ensure the LCP element can render immediately after its resource has finished loading.
|
|
16
|
+
|
|
17
|
+
- **Minimize Render-Blocking CSS**: Inline critical CSS and defer non-critical CSS. Ensure the stylesheet is smaller than the LCP resource.
|
|
18
|
+
- **Minimize Render-Blocking JS**: Avoid synchronous scripts in the `<head>`. Inline very small scripts.
|
|
19
|
+
- **Server-Side Rendering (SSR)**: Deliver the full HTML markup from the server so image resources are discoverable immediately.
|
|
20
|
+
- **Break Up Long Tasks**: Prevent large JavaScript tasks from blocking the main thread during rendering.
|
|
21
|
+
|
|
22
|
+
## 3. Reduce Resource Load Duration
|
|
23
|
+
|
|
24
|
+
**Goal**: Reduce the time spent transferring the bytes of the resource.
|
|
25
|
+
|
|
26
|
+
- **Optimize Resource Size**: Serve optimal image sizes, use modern formats (AVIF, WebP), and compress images/fonts.
|
|
27
|
+
- **Geographic Proximity (CDN)**: Use a Content Delivery Network to get servers closer to users.
|
|
28
|
+
- **Reduce Contention**: Use `fetchpriority="high"` to prevent lower-priority resources from competing for bandwidth.
|
|
29
|
+
- **Caching**: Use efficient `Cache-Control` policies.
|
|
30
|
+
|
|
31
|
+
## 4. Reduce Time to First Byte (TTFB)
|
|
32
|
+
|
|
33
|
+
**Goal**: Deliver the initial HTML as quickly as possible.
|
|
34
|
+
|
|
35
|
+
- **Minimize Redirects**: Avoid multiple redirects from advertisements or shortened links.
|
|
36
|
+
- **CDN Caching**: Cache static HTML documents at the edge.
|
|
37
|
+
- **Edge Computing**: Move dynamic logic to the edge to avoid trips to the origin server.
|
|
38
|
+
- **Back/Forward Cache**: Ensure pages are eligible for bfcache.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: memory-leak-debugging
|
|
3
|
+
description: Diagnoses and resolves memory leaks in JavaScript/Node.js applications. Use when a user reports high memory usage, OOM errors, or wants to analyze heapsnapshots or run memory leak detection tools like memlab.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Memory Leak Debugging
|
|
7
|
+
|
|
8
|
+
This skill provides expert guidance and workflows for finding, diagnosing, and fixing memory leaks in JavaScript and Node.js applications.
|
|
9
|
+
|
|
10
|
+
## Core Principles
|
|
11
|
+
|
|
12
|
+
- **Prefer `memlab`:** Do NOT attempt to read raw `.heapsnapshot` files directly, as they are extremely large and will consume too many tokens. Always recommend and use `memlab` to process snapshots and identify leak traces.
|
|
13
|
+
- **Isolate the Leak:** Determine if the leak is in the browser (client-side) or Node.js (server-side).
|
|
14
|
+
- **Common Culprits:** Look for detached DOM nodes, unhandled closures, global variables, event listeners not being removed, and caches growing unbounded. _Note: Detached DOM nodes are sometimes intentional caches; always ask the user before nulling them._
|
|
15
|
+
|
|
16
|
+
## Workflows
|
|
17
|
+
|
|
18
|
+
### 1. Capturing Snapshots
|
|
19
|
+
|
|
20
|
+
When investigating a frontend web application memory leak, utilize the `chrome-devtools-mcp` tools to interact with the application and take snapshots.
|
|
21
|
+
|
|
22
|
+
- Use tools like `click`, `navigate_page`, `fill`, etc., to manipulate the page into the desired state.
|
|
23
|
+
- Revert the page back to the original state after interactions to see if memory is released.
|
|
24
|
+
- Repeat the same user interactions 10 times to amplify the leak.
|
|
25
|
+
- Use `take_heapsnapshot` to save `.heapsnapshot` files to disk at baseline, target (after actions), and final (after reverting actions) states.
|
|
26
|
+
|
|
27
|
+
### 2. Using Memlab to Find Leaks (Recommended)
|
|
28
|
+
|
|
29
|
+
Once you have generated `.heapsnapshot` files using `take_heapsnapshot`, use `memlab` to automatically find memory leaks.
|
|
30
|
+
|
|
31
|
+
- Read [references/memlab.md](references/memlab.md) for how to use `memlab` to analyze the generated heapsnapshots.
|
|
32
|
+
- Do **not** read raw `.heapsnapshot` files using `read_file` or `cat`.
|
|
33
|
+
|
|
34
|
+
### 3. Identifying Common Leaks
|
|
35
|
+
|
|
36
|
+
When you have found a leak trace (e.g., via `memlab` output), you must identify the root cause in the code.
|
|
37
|
+
|
|
38
|
+
- Read [references/common-leaks.md](references/common-leaks.md) for examples of common memory leaks and how to fix them.
|
|
39
|
+
|
|
40
|
+
### 4. Fallback: Comparing Snapshots Manually
|
|
41
|
+
|
|
42
|
+
If `memlab` is not available, you MUST use the fallback script in the references directory to compare two `.heapsnapshot` files and identify the top growing objects and common leak types.
|
|
43
|
+
|
|
44
|
+
Run the script using Node.js:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
node skills/memory-leak-debugging/references/compare_snapshots.js <baseline.heapsnapshot> <target.heapsnapshot>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The script will analyze and output the top growing objects by size and highlight the 3 most common types of memory leaks (e.g., Detached DOM nodes, closures, Contexts) if they are present.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Common Memory Leaks
|
|
2
|
+
|
|
3
|
+
When analyzing a retainer trace from `memlab`, look for these common patterns in the codebase:
|
|
4
|
+
|
|
5
|
+
## 1. Uncleared Event Listeners
|
|
6
|
+
|
|
7
|
+
Event listeners attached to global objects (like `window` or `document`) or long-living objects prevent garbage collection of the objects referenced in their callbacks.
|
|
8
|
+
|
|
9
|
+
**Fix:** Always call `removeEventListener` when a component unmounts or the listener is no longer needed.
|
|
10
|
+
|
|
11
|
+
## 2. Detached DOM Nodes
|
|
12
|
+
|
|
13
|
+
A DOM node is removed from the document tree but is still referenced by a JavaScript variable. While detachedness is a good signal for a memory leak, it's not always a bug. For example, websites sometimes intentionally cache detached navigation trees.
|
|
14
|
+
|
|
15
|
+
**Fix:** Signal the detached nodes to the user first. **Ask the user first** before nulling the references or changing the code, as the detached nodes might be part of an intentional cache. If confirmed as a leak, ensure variables holding DOM references are set to `null` when the node is removed, or limit their scope.
|
|
16
|
+
|
|
17
|
+
## 3. Unintentional Global Variables
|
|
18
|
+
|
|
19
|
+
Variables declared without `var`, `let`, or `const` (in non-strict mode) or explicitly attached to `window` remain in memory forever.
|
|
20
|
+
|
|
21
|
+
**Fix:** Use strict mode, properly declare variables, and avoid global state.
|
|
22
|
+
|
|
23
|
+
## 4. Closures
|
|
24
|
+
|
|
25
|
+
Closures can unintentionally keep references to large objects in their outer scope.
|
|
26
|
+
|
|
27
|
+
**Fix:** Nullify large objects when they are no longer needed, or refactor the closure to not capture unnecessary variables.
|
|
28
|
+
|
|
29
|
+
## 5. Unbounded Caches or Arrays
|
|
30
|
+
|
|
31
|
+
Data structures used for caching (like objects, Arrays, or Maps) that grow without limits.
|
|
32
|
+
|
|
33
|
+
**Fix:** Implement caching limits, use LRU caches, or use `WeakMap`/`WeakSet` for data associated with object lifecycles.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
|
|
9
|
+
function parseSnapshot(filePath) {
|
|
10
|
+
console.log(`Loading ${filePath}...`);
|
|
11
|
+
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
12
|
+
const strings = data.strings;
|
|
13
|
+
const nodes = data.nodes;
|
|
14
|
+
const nodeFields = data.snapshot.meta.node_fields;
|
|
15
|
+
const nodeFieldCount = nodeFields.length;
|
|
16
|
+
|
|
17
|
+
const typeOffset = nodeFields.indexOf('type');
|
|
18
|
+
const nameOffset = nodeFields.indexOf('name');
|
|
19
|
+
const sizeOffset = nodeFields.indexOf('self_size');
|
|
20
|
+
|
|
21
|
+
const nodeTypes = data.snapshot.meta.node_types[typeOffset];
|
|
22
|
+
|
|
23
|
+
const counts = {};
|
|
24
|
+
const sizes = {};
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < nodes.length; i += nodeFieldCount) {
|
|
27
|
+
const typeIdx = nodes[i + typeOffset];
|
|
28
|
+
const typeName = nodeTypes[typeIdx];
|
|
29
|
+
const nameIdx = nodes[i + nameOffset];
|
|
30
|
+
const name = typeof nameIdx === 'number' ? strings[nameIdx] : nameIdx;
|
|
31
|
+
const size = nodes[i + sizeOffset];
|
|
32
|
+
|
|
33
|
+
// Ignore native primitives/arrays that clutter the output unless specifically looking for them
|
|
34
|
+
if (
|
|
35
|
+
typeName === 'string' ||
|
|
36
|
+
typeName === 'number' ||
|
|
37
|
+
typeName === 'array'
|
|
38
|
+
) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const key = `${typeName}::${name}`;
|
|
43
|
+
counts[key] = (counts[key] || 0) + 1;
|
|
44
|
+
sizes[key] = (sizes[key] || 0) + size;
|
|
45
|
+
}
|
|
46
|
+
return {counts, sizes};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const [, , file1, file2] = process.argv;
|
|
50
|
+
if (!file1 || !file2) {
|
|
51
|
+
console.error(
|
|
52
|
+
'Usage: node compare_snapshots.js <baseline.heapsnapshot> <target.heapsnapshot>',
|
|
53
|
+
);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const snap1 = parseSnapshot(file1);
|
|
59
|
+
const snap2 = parseSnapshot(file2);
|
|
60
|
+
|
|
61
|
+
const diffs = [];
|
|
62
|
+
for (const key in snap2.counts) {
|
|
63
|
+
const count1 = snap1.counts[key] || 0;
|
|
64
|
+
const count2 = snap2.counts[key];
|
|
65
|
+
const size1 = snap1.sizes[key] || 0;
|
|
66
|
+
const size2 = snap2.sizes[key];
|
|
67
|
+
|
|
68
|
+
if (count2 > count1) {
|
|
69
|
+
diffs.push({
|
|
70
|
+
key,
|
|
71
|
+
countDiff: count2 - count1,
|
|
72
|
+
sizeDiff: size2 - size1,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
diffs.sort((a, b) => b.sizeDiff - a.sizeDiff);
|
|
78
|
+
|
|
79
|
+
console.log('\n--- Top 10 growing objects by size ---');
|
|
80
|
+
diffs.slice(0, 10).forEach(d => {
|
|
81
|
+
console.log(`${d.key}: +${d.countDiff} objects, +${d.sizeDiff} bytes`);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Look for common leak indicators
|
|
85
|
+
const commonLeaks = diffs.filter(
|
|
86
|
+
d =>
|
|
87
|
+
d.key.toLowerCase().includes('detached') ||
|
|
88
|
+
d.key.toLowerCase().includes('html') ||
|
|
89
|
+
d.key.toLowerCase().includes('eventlistener') ||
|
|
90
|
+
d.key.toLowerCase().includes('context') ||
|
|
91
|
+
d.key.toLowerCase().includes('closure'),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
commonLeaks.sort((a, b) => b.countDiff - a.countDiff);
|
|
95
|
+
|
|
96
|
+
console.log('\n--- Top 3 most common types of memory leaks found ---');
|
|
97
|
+
if (commonLeaks.length === 0) {
|
|
98
|
+
console.log('No common DOM or Closure leaks detected.');
|
|
99
|
+
} else {
|
|
100
|
+
commonLeaks.slice(0, 3).forEach(d => {
|
|
101
|
+
console.log(`${d.key}: +${d.countDiff} objects, +${d.sizeDiff} bytes`);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error(
|
|
106
|
+
'Error parsing snapshots. They might be too large for JSON.parse or invalid.',
|
|
107
|
+
);
|
|
108
|
+
console.error(error.message);
|
|
109
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Using Memlab
|
|
2
|
+
|
|
3
|
+
[Memlab](https://facebook.github.io/memlab/) is an E2E testing and analysis framework for finding JavaScript memory leaks.
|
|
4
|
+
|
|
5
|
+
## Important Rule
|
|
6
|
+
|
|
7
|
+
**NEVER read raw `.heapsnapshot` files directly.** They are too large and will exceed context limits. Always use `memlab` commands to analyze them.
|
|
8
|
+
|
|
9
|
+
## Analyzing Snapshots
|
|
10
|
+
|
|
11
|
+
You can use the `take_heapsnapshot` tool provided by the `chrome-devtools-mcp` extension to generate heap snapshots during an investigation. To find leaks, you generally need 3 snapshots:
|
|
12
|
+
|
|
13
|
+
1. **Baseline:** Before the suspect action.
|
|
14
|
+
2. **Target:** After the suspect action.
|
|
15
|
+
3. **Final:** After reverting the suspect action (e.g., closing a modal, navigating away).
|
|
16
|
+
|
|
17
|
+
Once you have these 3 snapshots saved to disk, you can use `memlab` to find leaks:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx memlab find-leaks --baseline <path-to-baseline> --target <path-to-target> --final <path-to-final>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
You can also parse a single snapshot to find the largest objects or explore it individually:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx memlab analyze snapshot --snapshot <path-to-snapshot>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Memlab will output the retainer traces for identified leaks. Use these traces to guide your search in the codebase.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: troubleshooting
|
|
3
|
+
description: Uses Chrome DevTools MCP and documentation to troubleshoot connection and target issues. Trigger this skill when list_pages, new_page, or navigate_page fail, or when the server initialization fails.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Troubleshooting Wizard
|
|
7
|
+
|
|
8
|
+
You are acting as a troubleshooting wizard to help the user configure and fix their Chrome DevTools MCP server setup. When this skill is triggered (e.g., because `list_pages`, `new_page`, or `navigate_page` failed, or the server wouldn't start), follow this step-by-step diagnostic process:
|
|
9
|
+
|
|
10
|
+
### Step 1: Find and Read Configuration
|
|
11
|
+
|
|
12
|
+
Your first action should be to locate and read the MCP configuration file. Search for the following files in the user's workspace: `.mcp.json`, `gemini-extension.json`, `.claude/settings.json`, `.vscode/launch.json`, or `.gemini/settings.json`.
|
|
13
|
+
|
|
14
|
+
If you find a configuration file, read and interpret it to identify potential issues such as:
|
|
15
|
+
|
|
16
|
+
- Incorrect arguments or flags.
|
|
17
|
+
- Missing environment variables.
|
|
18
|
+
- Usage of `--autoConnect` in incompatible environments.
|
|
19
|
+
|
|
20
|
+
If you cannot find any of these files, only then should you ask the user to provide their configuration file content.
|
|
21
|
+
|
|
22
|
+
### Step 2: Triage Common Connection Errors
|
|
23
|
+
|
|
24
|
+
Before reading documentation or suggesting configuration changes, check if the error message matches one of the following common patterns.
|
|
25
|
+
|
|
26
|
+
#### Error: `Could not find DevToolsActivePort`
|
|
27
|
+
|
|
28
|
+
This error is highly specific to the `--autoConnect` feature. It means the MCP server cannot find the file created by a running, debuggable Chrome instance. This is not a generic connection failure.
|
|
29
|
+
|
|
30
|
+
Your primary goal is to guide the user to ensure Chrome is running and properly configured. Do not immediately suggest switching to `--browserUrl`. Follow this exact sequence:
|
|
31
|
+
|
|
32
|
+
1. **Ask the user to confirm that the correct Chrome version** (e.g., "Chrome Canary" if the error mentions it) is currently running.
|
|
33
|
+
2. **If the user confirms it is running, instruct them to enable remote debugging.** Be very specific about the URL and the action: "Please open a new tab in Chrome, navigate to `chrome://inspect/#remote-debugging`, and make sure the 'Enable remote debugging' checkbox is checked."
|
|
34
|
+
3. **Once the user confirms both steps, your only next action should be to call the `list_pages` tool.** This is the simplest and safest way to verify if the connection is now successful. Do not retry the original, more complex command yet.
|
|
35
|
+
4. **If `list_pages` succeeds, the problem is resolved.** If it still fails with the same error, then you can proceed to the more advanced steps like suggesting `--browserUrl` or checking for sandboxing issues.
|
|
36
|
+
|
|
37
|
+
#### Symptom: Server starts but creates a new empty profile
|
|
38
|
+
|
|
39
|
+
If the server starts successfully but `list_pages` returns an empty list or creates a new profile instead of connecting to the existing Chrome instance, check for typos in the arguments.
|
|
40
|
+
|
|
41
|
+
- **Check for flag typos:** For example, `--autoBronnect` instead of `--autoConnect`.
|
|
42
|
+
- **Verify the configuration:** Ensure the arguments match the expected flags exactly.
|
|
43
|
+
|
|
44
|
+
#### Symptom: Missing Tools / Only 9 tools available
|
|
45
|
+
|
|
46
|
+
If the server starts successfully but only a limited subset of tools (like `list_pages`, `get_console_message`, `lighthouse_audit`, `take_heapsnapshot`) are available, this is likely because the MCP client is enforcing a **read-only mode**.
|
|
47
|
+
|
|
48
|
+
All tools in `chrome-devtools-mcp` are annotated with `readOnlyHint: true` (for safe, non-modifying tools) or `readOnlyHint: false` (for tools that modify browser state, like `emulate`, `click`, `navigate_page`). To access the full suite of tools, the user must disable read-only mode in their MCP client (e.g., by exiting "Plan Mode" in Gemini CLI or adjusting their client's tool safety settings).
|
|
49
|
+
|
|
50
|
+
#### Symptom: Extension tools are missing or extensions fail to load
|
|
51
|
+
|
|
52
|
+
If the tools related to extensions (like `install_extension`) are not available, or if the extensions you load are not functioning:
|
|
53
|
+
|
|
54
|
+
1. **Check for the `--categoryExtensions` flag**: Ensure this flag is passed in the MCP server configuration to enable the extension category tools.
|
|
55
|
+
2. **Make sure the MCP server in configured to launch Chrome instead of connecting to an instance**: Chrome before 149 is not able to load extensions when connecting to an existing instance (`--auto-connect`, `--browserUrl`).
|
|
56
|
+
|
|
57
|
+
#### Other Common Errors
|
|
58
|
+
|
|
59
|
+
Identify other error messages from the failed tool call or the MCP initialization logs:
|
|
60
|
+
|
|
61
|
+
- `Target closed`
|
|
62
|
+
- "Tool not found" (check if they are using `--slim` which only enables navigation and screenshot tools).
|
|
63
|
+
- `ProtocolError: Network.enable timed out` or `The socket connection was closed unexpectedly`
|
|
64
|
+
- `Error [ERR_MODULE_NOT_FOUND]: Cannot find module`
|
|
65
|
+
- Any sandboxing or host validation errors.
|
|
66
|
+
|
|
67
|
+
### Step 3: Read Known Issues
|
|
68
|
+
|
|
69
|
+
Read the contents of https://github.com/ChromeDevTools/chrome-devtools-mcp/blob/main/docs/troubleshooting.md to map the error to a known issue. Pay close attention to:
|
|
70
|
+
|
|
71
|
+
- Sandboxing restrictions (macOS Seatbelt, Linux containers).
|
|
72
|
+
- WSL requirements.
|
|
73
|
+
- `--autoConnect` handshakes, timeouts, and requirements (requires **running** Chrome 144+).
|
|
74
|
+
|
|
75
|
+
### Step 4: Formulate a Configuration
|
|
76
|
+
|
|
77
|
+
Based on the exact error and the user's environment (OS, MCP client), formulate the correct MCP configuration snippet. Check if they need to:
|
|
78
|
+
|
|
79
|
+
- Pass `--browser-url=http://127.0.0.1:9222` instead of `--autoConnect` (e.g. if they are in a sandboxed environment like Claude Desktop).
|
|
80
|
+
- Enable remote debugging in Chrome (`chrome://inspect/#remote-debugging`) and accept the connection prompt. **Ask the user to verify this is enabled if using `--autoConnect`.**
|
|
81
|
+
- Add `--logFile <absolute_path_to_log_file>` to capture debug logs for analysis.
|
|
82
|
+
- Increase `startup_timeout_ms` (e.g. to 20000) if using Codex on Windows.
|
|
83
|
+
|
|
84
|
+
_If you are unsure of the user's configuration, ask the user to provide their current MCP server JSON configuration._
|
|
85
|
+
|
|
86
|
+
### Step 5: Run Diagnostic Commands
|
|
87
|
+
|
|
88
|
+
If the issue is still unclear, run diagnostic commands to test the server directly:
|
|
89
|
+
|
|
90
|
+
- Run `npx chrome-devtools-mcp@latest --help` to verify the installation and Node.js environment.
|
|
91
|
+
- If you need more information, run `DEBUG=* npx chrome-devtools-mcp@latest --logFile=/tmp/cdm-test.log` to capture verbose logs. Analyze the output for errors.
|
|
92
|
+
|
|
93
|
+
### Step 6: Check GitHub for Existing Issues
|
|
94
|
+
|
|
95
|
+
If https://github.com/ChromeDevTools/chrome-devtools-mcp/blob/main/docs/troubleshooting.md does not cover the specific error, check if the `gh` (GitHub CLI) tool is available in the environment. If so, search the GitHub repository for similar issues:
|
|
96
|
+
`gh issue list --repo ChromeDevTools/chrome-devtools-mcp --search "<error snippet>" --state all`
|
|
97
|
+
|
|
98
|
+
Alternatively, you can recommend that the user checks https://github.com/ChromeDevTools/chrome-devtools-mcp/issues and https://github.com/ChromeDevTools/chrome-devtools-mcp/discussions for help.
|