chrome-devtools-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.
Files changed (56) hide show
  1. package/README.md +20 -3
  2. package/build/src/HeapSnapshotManager.js +83 -16
  3. package/build/src/McpContext.js +218 -367
  4. package/build/src/McpPage.js +242 -31
  5. package/build/src/McpResponse.js +165 -60
  6. package/build/src/PageCollector.js +48 -122
  7. package/build/src/TextSnapshot.js +20 -2
  8. package/build/src/ToolHandler.js +13 -3
  9. package/build/src/WaitForHelper.js +18 -8
  10. package/build/src/bin/chrome-devtools-cli-options.js +76 -4
  11. package/build/src/bin/chrome-devtools-mcp-cli-options.js +15 -6
  12. package/build/src/bin/chrome-devtools-mcp-main.js +2 -2
  13. package/build/src/bin/chrome-devtools.js +25 -1
  14. package/build/src/browser.js +1 -1
  15. package/build/src/daemon/client.js +33 -3
  16. package/build/src/daemon/daemon.js +3 -2
  17. package/build/src/daemon/utils.js +1 -1
  18. package/build/src/devtools/DevtoolsUtils.js +2 -63
  19. package/build/src/{issue-descriptions.js → devtools/issueDescriptions.js} +8 -6
  20. package/build/src/formatters/HeapSnapshotFormatter.js +43 -0
  21. package/build/src/formatters/IssueFormatter.js +2 -2
  22. package/build/src/index.js +14 -5
  23. package/build/src/telemetry/ClearcutLogger.js +1 -1
  24. package/build/src/telemetry/WatchdogClient.js +1 -1
  25. package/build/src/telemetry/metricsRegistry.js +2 -9
  26. package/build/src/telemetry/persistence.js +1 -1
  27. package/build/src/telemetry/transformation.js +20 -0
  28. package/build/src/telemetry/watchdog/ClearcutSender.js +1 -1
  29. package/build/src/telemetry/watchdog/main.js +1 -1
  30. package/build/src/third_party/THIRD_PARTY_NOTICES +13 -279
  31. package/build/src/third_party/bundled-packages.json +3 -5
  32. package/build/src/third_party/devtools-heap-snapshot-worker.js +81 -0
  33. package/build/src/third_party/index.js +2418 -2197
  34. package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +3082 -6343
  35. package/build/src/tools/emulation.js +2 -2
  36. package/build/src/tools/extensions.js +1 -1
  37. package/build/src/tools/input.js +17 -8
  38. package/build/src/tools/lighthouse.js +1 -1
  39. package/build/src/tools/memory.js +76 -6
  40. package/build/src/tools/network.js +4 -4
  41. package/build/src/tools/pages.js +21 -89
  42. package/build/src/tools/performance.js +2 -2
  43. package/build/src/tools/screencast.js +1 -2
  44. package/build/src/tools/script.js +6 -10
  45. package/build/src/tools/snapshot.js +2 -2
  46. package/build/src/tools/thirdPartyDeveloper.js +7 -7
  47. package/build/src/tools/webmcp.js +1 -1
  48. package/build/src/trace-processing/parse.js +1 -1
  49. package/build/src/utils/files.js +0 -4
  50. package/build/src/{logger.js → utils/logger.js} +1 -1
  51. package/build/src/{polyfill.js → utils/polyfill.js} +1 -1
  52. package/build/src/version.js +1 -1
  53. package/package.json +17 -5
  54. package/skills/memory-leak-debugging/SKILL.md +22 -14
  55. package/build/src/utils/types.js +0 -7
  56. /package/build/src/{Mutex.js → utils/Mutex.js} +0 -0
package/README.md CHANGED
@@ -121,9 +121,9 @@ To use the Chrome DevTools MCP server follow the instructions from <a href="http
121
121
  "chrome-devtools": {
122
122
  "command": "npx",
123
123
  "args": [
124
+ "-y",
124
125
  "chrome-devtools-mcp@latest",
125
- "--browser-url=http://127.0.0.1:9222",
126
- "-y"
126
+ "--browser-url=http://127.0.0.1:9222"
127
127
  ]
128
128
  }
129
129
  }
@@ -333,6 +333,16 @@ Alternatively, follow the <a href="https://github.com/google-gemini/gemini-cli/b
333
333
  using the standard config from above.
334
334
  </details>
335
335
 
336
+ <details>
337
+ <summary>Grok Build CLI</summary>
338
+
339
+ ```bash
340
+ grok mcp add chrome-devtools npx chrome-devtools-mcp@latest
341
+ ```
342
+
343
+ See the <a href="https://docs.x.ai/build/features/skills-plugins-marketplaces">docs</a> for more options
344
+ </details>
345
+
336
346
  <details>
337
347
  <summary>JetBrains AI Assistant & Junie</summary>
338
348
 
@@ -514,12 +524,14 @@ If you run into any issues, checkout our [troubleshooting guide](./docs/troubles
514
524
  - [`take_snapshot`](docs/tool-reference.md#take_snapshot)
515
525
  - [`screencast_start`](docs/tool-reference.md#screencast_start)
516
526
  - [`screencast_stop`](docs/tool-reference.md#screencast_stop)
517
- - **Memory** (9 tools)
527
+ - **Memory** (11 tools)
518
528
  - [`take_heapsnapshot`](docs/tool-reference.md#take_heapsnapshot)
519
529
  - [`close_heapsnapshot`](docs/tool-reference.md#close_heapsnapshot)
530
+ - [`compare_heapsnapshots`](docs/tool-reference.md#compare_heapsnapshots)
520
531
  - [`get_heapsnapshot_class_nodes`](docs/tool-reference.md#get_heapsnapshot_class_nodes)
521
532
  - [`get_heapsnapshot_details`](docs/tool-reference.md#get_heapsnapshot_details)
522
533
  - [`get_heapsnapshot_dominators`](docs/tool-reference.md#get_heapsnapshot_dominators)
534
+ - [`get_heapsnapshot_duplicate_strings`](docs/tool-reference.md#get_heapsnapshot_duplicate_strings)
523
535
  - [`get_heapsnapshot_edges`](docs/tool-reference.md#get_heapsnapshot_edges)
524
536
  - [`get_heapsnapshot_retainers`](docs/tool-reference.md#get_heapsnapshot_retainers)
525
537
  - [`get_heapsnapshot_retaining_paths`](docs/tool-reference.md#get_heapsnapshot_retaining_paths)
@@ -742,6 +754,11 @@ The Chrome DevTools MCP server supports the following configuration option:
742
754
  - **Type:** boolean
743
755
  - **Default:** `false`
744
756
 
757
+ - **`--allowUnrestrictedPaths`/ `--allow-unrestricted-paths`**
758
+ If set, disables the default path restriction that applies when the MCP client does not negotiate the roots capability. By default, file-writing tools are restricted to the OS temp directory when no roots are configured. Use this only when connecting a trusted local client that does not implement MCP roots and requires access to paths outside the temp directory.
759
+ - **Type:** boolean
760
+ - **Default:** `false`
761
+
745
762
  <!-- END AUTO GENERATED OPTIONS -->
746
763
 
747
764
  Pass them via the `args` property in the JSON configuration. For example:
@@ -8,6 +8,7 @@ import path from 'node:path';
8
8
  import { DevTools } from './third_party/index.js';
9
9
  import { createIdGenerator, stableIdSymbol, } from './utils/id.js';
10
10
  export class HeapSnapshotManager {
11
+ #snapshotIdGenerator = createIdGenerator();
11
12
  #snapshots = new Map();
12
13
  async getSnapshot(filePath) {
13
14
  const absolutePath = path.resolve(filePath);
@@ -15,28 +16,36 @@ export class HeapSnapshotManager {
15
16
  if (cached) {
16
17
  return cached.snapshot;
17
18
  }
18
- const { snapshot, worker } = await this.#loadSnapshot(absolutePath);
19
+ const uid = this.#snapshotIdGenerator();
20
+ const { snapshot, worker } = await this.#loadSnapshot(absolutePath, uid);
19
21
  this.#snapshots.set(absolutePath, {
20
22
  snapshot,
21
23
  worker,
22
- idToClassKey: new Map(),
24
+ idToClassKey: [''],
23
25
  classKeyToId: new Map(),
24
- idGenerator: createIdGenerator(),
25
26
  });
26
27
  return snapshot;
27
28
  }
28
- async getAggregates(filePath) {
29
+ async getAggregates(filePath, filterName) {
29
30
  const snapshot = await this.getSnapshot(filePath);
30
31
  const filter = new DevTools.HeapSnapshotModel.HeapSnapshotModel.NodeFilter();
32
+ if (filterName) {
33
+ filter.filterName = filterName;
34
+ }
31
35
  const aggregates = await snapshot.aggregatesWithFilter(filter);
32
- for (const key of Object.keys(aggregates)) {
36
+ let objectCount = 0;
37
+ let totalSelfSize = 0;
38
+ for (const [key, aggregate] of Object.entries(aggregates)) {
33
39
  const id = await this.getOrCreateIdForClassKey(filePath, key);
34
- const aggregate = aggregates[key];
35
- if (aggregate) {
36
- aggregate[stableIdSymbol] = id;
37
- }
40
+ aggregate[stableIdSymbol] = id;
41
+ objectCount += aggregate.count;
42
+ totalSelfSize += aggregate.self;
38
43
  }
39
- return aggregates;
44
+ return {
45
+ aggregates,
46
+ objectCount,
47
+ totalSelfSize,
48
+ };
40
49
  }
41
50
  async getStats(filePath) {
42
51
  const snapshot = await this.getSnapshot(filePath);
@@ -50,15 +59,18 @@ export class HeapSnapshotManager {
50
59
  const cached = this.#getCachedSnapshot(filePath);
51
60
  let id = cached.classKeyToId.get(classKey);
52
61
  if (!id) {
53
- id = cached.idGenerator();
62
+ id = cached.idToClassKey.length;
54
63
  cached.classKeyToId.set(classKey, id);
55
- cached.idToClassKey.set(id, classKey);
64
+ cached.idToClassKey.push(classKey);
56
65
  }
57
66
  return id;
58
67
  }
59
- async getNodesById(filePath, id) {
68
+ async getNodesById(filePath, id, filterName) {
60
69
  const snapshot = await this.getSnapshot(filePath);
61
70
  const filter = new DevTools.HeapSnapshotModel.HeapSnapshotModel.NodeFilter();
71
+ if (filterName) {
72
+ filter.filterName = filterName;
73
+ }
62
74
  const className = await this.resolveClassKeyFromId(filePath, id);
63
75
  if (!className) {
64
76
  throw new Error(`Class with ID ${id} not found in heap snapshot`);
@@ -100,6 +112,38 @@ export class HeapSnapshotManager {
100
112
  const provider = snapshot.createEdgesProvider(nodeIndex);
101
113
  return await provider.serializeItemsRange(0, Infinity);
102
114
  }
115
+ async getClassDiffs(baseFilePath, currentFilePath) {
116
+ const rawDiffs = await this.#getSortedRawClassDiffs(baseFilePath, currentFilePath);
117
+ return rawDiffs.map(rawDiff => ({
118
+ className: rawDiff.name,
119
+ addedCount: rawDiff.addedCount,
120
+ removedCount: rawDiff.removedCount,
121
+ countDelta: rawDiff.countDelta,
122
+ addedSize: rawDiff.addedSize,
123
+ removedSize: rawDiff.removedSize,
124
+ sizeDelta: rawDiff.sizeDelta,
125
+ }));
126
+ }
127
+ async getDetailedClassDiff(baseFilePath, currentFilePath, classIndex) {
128
+ const classDiffs = await this.#getSortedRawClassDiffs(baseFilePath, currentFilePath);
129
+ const rawDiff = classDiffs[classIndex];
130
+ if (!rawDiff) {
131
+ throw new Error(`Invalid classIndex: ${classIndex}. Total classes with changes: ${classDiffs.length}`);
132
+ }
133
+ return {
134
+ className: rawDiff.name,
135
+ addedCount: rawDiff.addedCount,
136
+ removedCount: rawDiff.removedCount,
137
+ countDelta: rawDiff.countDelta,
138
+ addedSize: rawDiff.addedSize,
139
+ removedSize: rawDiff.removedSize,
140
+ sizeDelta: rawDiff.sizeDelta,
141
+ addedIds: rawDiff.addedIds ?? [],
142
+ addedSelfSizes: rawDiff.addedSelfSizes ?? [],
143
+ deletedIds: rawDiff.deletedIds ?? [],
144
+ deletedSelfSizes: rawDiff.deletedSelfSizes ?? [],
145
+ };
146
+ }
103
147
  #getCachedSnapshot(filePath) {
104
148
  const absolutePath = path.resolve(filePath);
105
149
  const cached = this.#snapshots.get(absolutePath);
@@ -108,16 +152,35 @@ export class HeapSnapshotManager {
108
152
  }
109
153
  return cached;
110
154
  }
155
+ async #getSortedRawClassDiffs(baseFilePath, currentFilePath) {
156
+ const baseSnapshot = await this.getSnapshot(baseFilePath);
157
+ const currentSnapshot = await this.getSnapshot(currentFilePath);
158
+ const interfaceDefinitions = await currentSnapshot.interfaceDefinitions();
159
+ const aggregatesForDiff = await baseSnapshot.aggregatesForDiff(interfaceDefinitions);
160
+ const baseSnapshotId = baseSnapshot.uid;
161
+ if (baseSnapshotId === undefined) {
162
+ throw new Error('Base snapshot UID is undefined');
163
+ }
164
+ // DevTools calculateSnapshotDiff uses the first parameter (baseSnapshotId)
165
+ // as a cache key. We pass the unique UID of the base snapshot.
166
+ const rawDiffs = await currentSnapshot.calculateSnapshotDiff(baseSnapshotId, aggregatesForDiff);
167
+ // Return a filtered and sorted array here to ensure that
168
+ // compare_heapsnapshot_summary and compare_heapsnapshot_details agree
169
+ // on indices.
170
+ return Object.values(rawDiffs)
171
+ .filter(diff => diff.addedCount > 0 || diff.removedCount > 0)
172
+ .sort((a, b) => b.sizeDelta - a.sizeDelta);
173
+ }
111
174
  async resolveClassKeyFromId(filePath, id) {
112
175
  const cached = this.#getCachedSnapshot(filePath);
113
- return cached.idToClassKey.get(id);
176
+ return cached.idToClassKey[id];
114
177
  }
115
- async #loadSnapshot(absolutePath) {
178
+ async #loadSnapshot(absolutePath, uid) {
116
179
  const workerProxy = new DevTools.HeapSnapshotModel.HeapSnapshotProxy.HeapSnapshotWorkerProxy(() => {
117
180
  /* noop */
118
181
  }, import.meta.resolve('./third_party/devtools-heap-snapshot-worker.js'));
119
182
  const { promise: snapshotPromise, resolve: resolveSnapshot } = Promise.withResolvers();
120
- const loaderProxy = workerProxy.createLoader(1, snapshotProxy => {
183
+ const loaderProxy = workerProxy.createLoader(uid, snapshotProxy => {
121
184
  resolveSnapshot(snapshotProxy);
122
185
  });
123
186
  const fileStream = fsSync.createReadStream(absolutePath, {
@@ -131,6 +194,10 @@ export class HeapSnapshotManager {
131
194
  const snapshot = await snapshotPromise;
132
195
  return { snapshot, worker: workerProxy };
133
196
  }
197
+ async getDuplicateStrings(filePath) {
198
+ const snapshot = await this.getSnapshot(filePath);
199
+ return await snapshot.getDuplicateStrings();
200
+ }
134
201
  hasSnapshots() {
135
202
  return this.#snapshots.size > 0;
136
203
  }