chrome-devtools-mcp 1.10.0 → 1.11.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 (86) hide show
  1. package/build/src/BrowserManager.js +132 -13
  2. package/build/src/McpContext.js +188 -138
  3. package/build/src/McpPage.js +348 -96
  4. package/build/src/McpResponse.js +234 -76
  5. package/build/src/McpWorker.js +66 -0
  6. package/build/src/SlimMcpResponse.js +5 -1
  7. package/build/src/TextSnapshot.js +3 -2
  8. package/build/src/ToolHandler.js +80 -42
  9. package/build/src/bin/chrome-devtools-mcp-main.js +8 -7
  10. package/build/src/bin/chrome-devtools-mcp.js +1 -1
  11. package/build/src/bin/chrome-devtools.js +31 -41
  12. package/build/src/collectors/ServiceWorkerCollector.js +18 -11
  13. package/build/src/config/ConfigLocator.js +70 -0
  14. package/build/src/config/ConfigParser.js +264 -0
  15. package/build/src/config/ConfigWatcher.js +93 -0
  16. package/build/src/config/browser-options.js +2 -13
  17. package/build/src/config/category-options.js +15 -30
  18. package/build/src/config/cli-commands.js +165 -5
  19. package/build/src/config/cli-options.js +410 -43
  20. package/build/src/config/mcp-options.js +156 -234
  21. package/build/src/config/puppeteer-options.js +65 -0
  22. package/build/src/config/tool-options.js +60 -0
  23. package/build/src/daemon/client.js +81 -41
  24. package/build/src/daemon/daemon.js +55 -45
  25. package/build/src/daemon/utils.js +44 -11
  26. package/build/src/devtools/DevToolsCommentBridge.js +43 -6
  27. package/build/src/devtools/DevtoolsUtils.js +3 -3
  28. package/build/src/devtools/McpHostBindingAdapter.js +0 -1
  29. package/build/src/formatters/CommentFormatter.js +4 -13
  30. package/build/src/formatters/ConsoleFormatter.js +1 -1
  31. package/build/src/formatters/CssFormatter.js +3 -2
  32. package/build/src/formatters/HeapSnapshotFormatter.js +104 -46
  33. package/build/src/formatters/IssueFormatter.js +33 -32
  34. package/build/src/formatters/NetworkFormatter.js +12 -11
  35. package/build/src/formatters/SnapshotFormatter.js +31 -4
  36. package/build/src/index.js +54 -9
  37. package/build/src/processors/ChunkedTraceParser.js +11 -11
  38. package/build/src/processors/HeapSnapshotManager.js +121 -84
  39. package/build/src/processors/PerformanceTrace.js +9 -9
  40. package/build/src/telemetry/ClearcutLogger.js +1 -1
  41. package/build/src/telemetry/transformation.js +7 -11
  42. package/build/src/telemetry/watchdog/main.js +1 -1
  43. package/build/src/third_party/THIRD_PARTY_NOTICES +10 -367
  44. package/build/src/third_party/bundled-packages.json +7 -8
  45. package/build/src/third_party/devtools-formatter-worker.js +1193 -62
  46. package/build/src/third_party/devtools-heap-snapshot-worker.js +1126 -21
  47. package/build/src/third_party/index.js +8087 -19416
  48. package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantRead.md +0 -1
  49. package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantReadOptOut.md +5 -0
  50. package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSet.md +0 -1
  51. package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSetOptOut.md +5 -0
  52. package/build/src/third_party/issue-descriptions/deprecation.md +1 -1
  53. package/build/src/third_party/issue-descriptions/genericGeolocationPromptWithoutUserGesture.md +5 -0
  54. package/build/src/third_party/issue-descriptions/sriValidationFailedIntegrityMismatch.md +2 -0
  55. package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +3 -3
  56. package/build/src/tools/ToolDefinition.js +16 -4
  57. package/build/src/tools/comments.js +20 -1
  58. package/build/src/tools/css.js +4 -2
  59. package/build/src/tools/emulation.js +17 -4
  60. package/build/src/tools/input.js +8 -3
  61. package/build/src/tools/lighthouse.js +112 -4
  62. package/build/src/tools/memory.js +129 -28
  63. package/build/src/tools/pages.js +5 -2
  64. package/build/src/tools/performance.js +21 -3
  65. package/build/src/tools/screencast.js +71 -32
  66. package/build/src/tools/screenshot.js +29 -14
  67. package/build/src/tools/script.js +90 -37
  68. package/build/src/tools/slim/tools.js +6 -8
  69. package/build/src/tools/thirdPartyDeveloper.js +6 -4
  70. package/build/src/tools/tools.js +35 -22
  71. package/build/src/tools/webmcp.js +9 -6
  72. package/build/src/types.js +11 -0
  73. package/build/src/utils/WaitForHelper.js +14 -1
  74. package/build/src/utils/check-for-updates.js +1 -1
  75. package/build/src/utils/errorHandling.js +20 -0
  76. package/build/src/utils/logger.js +15 -5
  77. package/build/src/utils/text.js +15 -0
  78. package/build/src/utils/url.js +99 -3
  79. package/build/src/version.js +1 -1
  80. package/package.json +14 -10
  81. package/skills/a11y-debugging/SKILL.md +4 -4
  82. package/skills/chrome-devtools/SKILL.md +2 -2
  83. package/skills/chrome-devtools-cli/SKILL.md +18 -15
  84. package/skills/cookie-debugging/SKILL.md +8 -5
  85. package/skills/debug-optimize-lcp/SKILL.md +1 -1
  86. package/skills/troubleshooting/SKILL.md +5 -6
@@ -20,8 +20,8 @@ const BYTE_COMMA = 0x2c;
20
20
  /**
21
21
  * Advances past any RFC 8259 JSON whitespace bytes.
22
22
  *
23
- * @param buffer - The trace byte buffer to inspect.
24
- * @param start - The buffer index where scanning begins.
23
+ * @param buffer The trace byte buffer to inspect.
24
+ * @param start The buffer index where scanning begins.
25
25
  * @returns The index of the first non-whitespace byte, or the buffer length if the buffer ends.
26
26
  */
27
27
  function skipWhitespace(buffer, start) {
@@ -38,8 +38,8 @@ function skipWhitespace(buffer, start) {
38
38
  /**
39
39
  * Scans past a JSON string starting at the opening quotation mark.
40
40
  *
41
- * @param buffer - The trace byte buffer to scan.
42
- * @param startQuotePos - The buffer index of the opening quotation mark.
41
+ * @param buffer The trace byte buffer to scan.
42
+ * @param startQuotePos The buffer index of the opening quotation mark.
43
43
  * @returns The index immediately following the closing quotation mark.
44
44
  * @throws {SyntaxError} If the string is unterminated before the end of the buffer.
45
45
  */
@@ -65,8 +65,8 @@ function skipString(buffer, startQuotePos) {
65
65
  * Scans past a complete JSON value starting at the specified buffer position.
66
66
  * Skips strings, compound objects, arrays, and primitive values without parsing them into memory.
67
67
  *
68
- * @param buffer - The trace byte buffer to scan.
69
- * @param startPos - The buffer index where the value begins.
68
+ * @param buffer The trace byte buffer to scan.
69
+ * @param startPos The buffer index where the value begins.
70
70
  * @returns The index immediately following the skipped JSON value.
71
71
  * @throws {SyntaxError} If the value contains unbalanced delimiters, unterminated strings, or empty primitive tokens.
72
72
  */
@@ -131,9 +131,9 @@ function skipValue(buffer, startPos) {
131
131
  /**
132
132
  * Scans trace events from a JSON array in bounded batches to limit memory consumption.
133
133
  *
134
- * @param buffer - The raw byte buffer containing the events array.
135
- * @param startPos - The index immediately after the opening array bracket.
136
- * @param config - Configuration settings controlling batch sizes and text decoding.
134
+ * @param buffer The raw byte buffer containing the events array.
135
+ * @param startPos The index immediately after the opening array bracket.
136
+ * @param config Configuration settings controlling batch sizes and text decoding.
137
137
  * @returns An object containing the parsed events and the ending buffer position.
138
138
  * @throws {SyntaxError} If the event array contains malformed JSON, unbalanced delimiters, or unexpected tokens.
139
139
  */
@@ -244,8 +244,8 @@ function parseEventsArray(buffer, startPos, config) {
244
244
  * Supports both root array format ([...]) and object container format ({"traceEvents": [...]}).
245
245
  * Parses events in chunks to prevent V8 string length and memory exhaustion errors.
246
246
  *
247
- * @param buffer - The raw trace buffer to parse.
248
- * @param options - Optional configuration settings for batch processing.
247
+ * @param buffer The raw trace buffer to parse.
248
+ * @param options Optional configuration settings for batch processing.
249
249
  * @returns A {@link ParsedTraceBuffer} containing parsed trace events and optional file metadata, or an object with an empty events array if the buffer is empty or contains only whitespace.
250
250
  * @throws {Error} If the buffer contains non-whitespace data that does not begin with a valid JSON array or object.
251
251
  * @throws {SyntaxError} If the underlying JSON syntax within batches or metadata is invalid.
@@ -6,7 +6,29 @@
6
6
  import fsSync from 'node:fs';
7
7
  import path from 'node:path';
8
8
  import { DevTools } from '../third_party/index.js';
9
- import { createIdGenerator, stableIdSymbol, } from '../utils/id.js';
9
+ import { createIdGenerator } from '../utils/id.js';
10
+ export class HeapSnapshot {
11
+ proxy;
12
+ worker;
13
+ // 1-indexed array where index is the class ID.
14
+ #idToClassKey = [''];
15
+ #classKeyToId = new Map();
16
+ constructor(proxy, worker, aggregates) {
17
+ this.proxy = proxy;
18
+ this.worker = worker;
19
+ for (const key of Object.keys(aggregates)) {
20
+ const id = this.#idToClassKey.length;
21
+ this.#classKeyToId.set(key, id);
22
+ this.#idToClassKey.push(key);
23
+ }
24
+ }
25
+ resolveIdFromClassKey(classKey) {
26
+ return this.#classKeyToId.get(classKey);
27
+ }
28
+ resolveClassKeyFromId(id) {
29
+ return this.#idToClassKey[id];
30
+ }
31
+ }
10
32
  const VALID_EXTENSIONS = ['.heapsnapshot', '.heaptimeline'];
11
33
  function hasValidHeapSnapshotExtension(filePath) {
12
34
  return VALID_EXTENSIONS.some(ext => filePath.endsWith(ext));
@@ -19,19 +41,13 @@ export class HeapSnapshotManager {
19
41
  throw new Error(`File ${filePath} must have a .heapsnapshot or .heaptimeline extension.`);
20
42
  }
21
43
  const absolutePath = path.resolve(filePath);
22
- const cached = this.#snapshots.get(absolutePath);
23
- if (cached) {
24
- return cached.snapshot;
44
+ let cached = this.#snapshots.get(absolutePath);
45
+ if (!cached) {
46
+ const uid = this.#snapshotIdGenerator();
47
+ cached = this.#loadSnapshot(absolutePath, uid);
48
+ this.#snapshots.set(absolutePath, cached);
25
49
  }
26
- const uid = this.#snapshotIdGenerator();
27
- const { snapshot, worker } = await this.#loadSnapshot(absolutePath, uid);
28
- this.#snapshots.set(absolutePath, {
29
- snapshot,
30
- worker,
31
- idToClassKey: [''],
32
- classKeyToId: new Map(),
33
- });
34
- return snapshot;
50
+ return await cached;
35
51
  }
36
52
  async #applyNodeFilter(snapshot, filter, filterName, objectId) {
37
53
  if (filterName === 'attributedToSpecificNativeContext') {
@@ -51,16 +67,27 @@ export class HeapSnapshotManager {
51
67
  async getAggregates(filePath, filterName, objectId) {
52
68
  const snapshot = await this.getSnapshot(filePath);
53
69
  const filter = new DevTools.HeapSnapshotModel.HeapSnapshotModel.NodeFilter();
54
- await this.#applyNodeFilter(snapshot, filter, filterName, objectId);
55
- const aggregates = await snapshot.aggregatesWithFilter(filter);
70
+ await this.#applyNodeFilter(snapshot.proxy, filter, filterName, objectId);
71
+ const rawAggregates = await snapshot.proxy.aggregatesWithFilter(filter);
56
72
  let objectCount = 0;
57
73
  let totalSelfSize = 0;
58
- for (const [key, aggregate] of Object.entries(aggregates)) {
59
- const id = await this.getOrCreateIdForClassKey(filePath, key);
60
- aggregate[stableIdSymbol] = id;
74
+ const aggregates = [];
75
+ for (const [key, aggregate] of Object.entries(rawAggregates)) {
76
+ const id = snapshot.resolveIdFromClassKey(key);
77
+ if (id === undefined) {
78
+ throw new Error(`No class ID found for class key ${key}`);
79
+ }
61
80
  objectCount += aggregate.count;
62
81
  totalSelfSize += aggregate.self;
82
+ aggregates.push({
83
+ id,
84
+ className: aggregate.name,
85
+ count: aggregate.count,
86
+ selfSize: aggregate.self,
87
+ retainedSize: aggregate.maxRet,
88
+ });
63
89
  }
90
+ aggregates.sort((a, b) => b.retainedSize - a.retainedSize);
64
91
  return {
65
92
  aggregates,
66
93
  objectCount,
@@ -69,94 +96,107 @@ export class HeapSnapshotManager {
69
96
  }
70
97
  async getStats(filePath) {
71
98
  const snapshot = await this.getSnapshot(filePath);
72
- return await snapshot.getStatistics();
99
+ return await snapshot.proxy.getStatistics();
73
100
  }
74
101
  async getStaticData(filePath) {
75
102
  const snapshot = await this.getSnapshot(filePath);
76
- return snapshot.staticData;
103
+ return snapshot.proxy.staticData;
77
104
  }
78
105
  async getNativeContextSizes(filePath) {
79
106
  const snapshot = await this.getSnapshot(filePath);
80
- return await snapshot.getNativeContextSizes();
107
+ return await snapshot.proxy.getNativeContextSizes();
81
108
  }
82
109
  async getRetainedByContextSummary(filePath) {
83
110
  const snapshot = await this.getSnapshot(filePath);
84
- return await snapshot.getRetainedByContextSummary();
85
- }
86
- async getOrCreateIdForClassKey(filePath, classKey) {
87
- const cached = this.#getCachedSnapshot(filePath);
88
- let id = cached.classKeyToId.get(classKey);
89
- if (!id) {
90
- id = cached.idToClassKey.length;
91
- cached.classKeyToId.set(classKey, id);
92
- cached.idToClassKey.push(classKey);
93
- }
94
- return id;
111
+ return await snapshot.proxy.getRetainedByContextSummary();
95
112
  }
96
113
  async getNodesById(filePath, id, filterName, objectId) {
97
114
  const snapshot = await this.getSnapshot(filePath);
98
115
  const filter = new DevTools.HeapSnapshotModel.HeapSnapshotModel.NodeFilter();
99
- await this.#applyNodeFilter(snapshot, filter, filterName, objectId);
100
- const className = await this.resolveClassKeyFromId(filePath, id);
116
+ await this.#applyNodeFilter(snapshot.proxy, filter, filterName, objectId);
117
+ const className = snapshot.resolveClassKeyFromId(id);
101
118
  if (!className) {
102
119
  throw new Error(`Class with ID ${id} not found in heap snapshot`);
103
120
  }
104
- const provider = snapshot.createNodesProviderForClass(className, filter);
121
+ const provider = snapshot.proxy.createNodesProviderForClass(className, filter);
105
122
  return await provider.serializeItemsRange(0, Infinity);
106
123
  }
107
124
  async getRetainers(filePath, nodeId) {
108
125
  const snapshot = await this.getSnapshot(filePath);
109
- const nodeIndex = await snapshot.nodeIndexForId(nodeId);
126
+ const nodeIndex = await snapshot.proxy.nodeIndexForId(nodeId);
110
127
  if (nodeIndex === undefined) {
111
128
  throw new Error(`Node with ID ${nodeId} not found`);
112
129
  }
113
- const provider = snapshot.createRetainingEdgesProvider(nodeIndex);
130
+ const provider = snapshot.proxy.createRetainingEdgesProvider(nodeIndex);
114
131
  return await provider.serializeItemsRange(0, Infinity);
115
132
  }
116
133
  async getObjectInfo(filePath, nodeId) {
117
134
  const snapshot = await this.getSnapshot(filePath);
118
- const nodeIndex = await snapshot.nodeIndexForId(nodeId);
135
+ const nodeIndex = await snapshot.proxy.nodeIndexForId(nodeId);
119
136
  if (nodeIndex === undefined) {
120
137
  throw new Error(`Node with ID ${nodeId} not found`);
121
138
  }
122
- return await snapshot.getObjectInfo(nodeIndex);
139
+ return await snapshot.proxy.getObjectInfo(nodeIndex);
140
+ }
141
+ async analyzeContexts(filePath) {
142
+ const snapshot = await this.getSnapshot(filePath);
143
+ return await snapshot.proxy.analyzeContexts();
123
144
  }
124
145
  async getRetainingPaths(filePath, nodeId, maxDepth, maxNodes, maxSiblings) {
125
146
  const snapshot = await this.getSnapshot(filePath);
126
- const nodeIndex = await snapshot.nodeIndexForId(nodeId);
147
+ const nodeIndex = await snapshot.proxy.nodeIndexForId(nodeId);
127
148
  if (nodeIndex === undefined) {
128
149
  throw new Error(`Node with ID ${nodeId} not found`);
129
150
  }
130
- return await snapshot.getRetainingPaths(nodeIndex, maxDepth, maxNodes, maxSiblings);
151
+ return await snapshot.proxy.getRetainingPaths(nodeIndex, maxDepth, maxNodes, maxSiblings);
131
152
  }
132
153
  async getDominatorsOf(filePath, nodeId) {
133
154
  const snapshot = await this.getSnapshot(filePath);
134
- const nodeIndex = await snapshot.nodeIndexForId(nodeId);
155
+ const nodeIndex = await snapshot.proxy.nodeIndexForId(nodeId);
135
156
  if (nodeIndex === undefined) {
136
157
  throw new Error(`Node with ID ${nodeId} not found`);
137
158
  }
138
- return await snapshot.getDominatorsOf(nodeIndex);
159
+ return await snapshot.proxy.getDominatorsOf(nodeIndex);
139
160
  }
140
161
  async getEdges(filePath, nodeId, options) {
141
162
  const snapshot = await this.getSnapshot(filePath);
142
- const nodeIndex = await snapshot.nodeIndexForId(nodeId);
163
+ const nodeIndex = await snapshot.proxy.nodeIndexForId(nodeId);
143
164
  if (nodeIndex === undefined) {
144
165
  throw new Error(`Node with ID ${nodeId} not found`);
145
166
  }
146
- const provider = snapshot.createEdgesProvider(nodeIndex, options);
167
+ const provider = snapshot.proxy.createEdgesProvider(nodeIndex, options);
147
168
  return await provider.serializeItemsRange(0, Infinity);
148
169
  }
149
170
  async getClassDiffs(baseFilePath, currentFilePath) {
150
171
  const rawDiffs = await this.#getSortedRawClassDiffs(baseFilePath, currentFilePath);
151
- return rawDiffs.map(rawDiff => ({
152
- className: rawDiff.name,
153
- addedCount: rawDiff.addedCount,
154
- removedCount: rawDiff.removedCount,
155
- countDelta: rawDiff.countDelta,
156
- addedSize: rawDiff.addedSize,
157
- removedSize: rawDiff.removedSize,
158
- sizeDelta: rawDiff.sizeDelta,
159
- }));
172
+ const classDiffs = [];
173
+ const totals = {
174
+ addedCount: 0,
175
+ removedCount: 0,
176
+ countDelta: 0,
177
+ addedSize: 0,
178
+ removedSize: 0,
179
+ sizeDelta: 0,
180
+ };
181
+ for (const [index, rawDiff] of rawDiffs.entries()) {
182
+ classDiffs.push({
183
+ index,
184
+ className: rawDiff.name,
185
+ addedCount: rawDiff.addedCount,
186
+ removedCount: rawDiff.removedCount,
187
+ countDelta: rawDiff.countDelta,
188
+ addedSize: rawDiff.addedSize,
189
+ removedSize: rawDiff.removedSize,
190
+ sizeDelta: rawDiff.sizeDelta,
191
+ });
192
+ totals.addedCount += rawDiff.addedCount;
193
+ totals.removedCount += rawDiff.removedCount;
194
+ totals.countDelta += rawDiff.countDelta;
195
+ totals.addedSize += rawDiff.addedSize;
196
+ totals.removedSize += rawDiff.removedSize;
197
+ totals.sizeDelta += rawDiff.sizeDelta;
198
+ }
199
+ return { classDiffs, totals };
160
200
  }
161
201
  async getDetailedClassDiff(baseFilePath, currentFilePath, classIndex) {
162
202
  const classDiffs = await this.#getSortedRawClassDiffs(baseFilePath, currentFilePath);
@@ -165,6 +205,7 @@ export class HeapSnapshotManager {
165
205
  throw new Error(`Invalid classIndex: ${classIndex}. Total classes with changes: ${classDiffs.length}`);
166
206
  }
167
207
  return {
208
+ index: classIndex,
168
209
  className: rawDiff.name,
169
210
  addedCount: rawDiff.addedCount,
170
211
  removedCount: rawDiff.removedCount,
@@ -178,26 +219,20 @@ export class HeapSnapshotManager {
178
219
  deletedSelfSizes: rawDiff.deletedSelfSizes ?? [],
179
220
  };
180
221
  }
181
- #getCachedSnapshot(filePath) {
182
- const absolutePath = path.resolve(filePath);
183
- const cached = this.#snapshots.get(absolutePath);
184
- if (!cached) {
185
- throw new Error(`Snapshot not loaded for ${filePath}`);
186
- }
187
- return cached;
188
- }
189
222
  async #getSortedRawClassDiffs(baseFilePath, currentFilePath) {
190
- const baseSnapshot = await this.getSnapshot(baseFilePath);
191
- const currentSnapshot = await this.getSnapshot(currentFilePath);
192
- const interfaceDefinitions = await currentSnapshot.interfaceDefinitions();
193
- const aggregatesForDiff = await baseSnapshot.aggregatesForDiff(interfaceDefinitions);
194
- const baseSnapshotId = baseSnapshot.uid;
223
+ const [baseSnapshot, currentSnapshot] = await Promise.all([
224
+ this.getSnapshot(baseFilePath),
225
+ this.getSnapshot(currentFilePath),
226
+ ]);
227
+ const interfaceDefinitions = await currentSnapshot.proxy.interfaceDefinitions();
228
+ const aggregatesForDiff = await baseSnapshot.proxy.aggregatesForDiff(interfaceDefinitions);
229
+ const baseSnapshotId = baseSnapshot.proxy.uid;
195
230
  if (baseSnapshotId === undefined) {
196
231
  throw new Error('Base snapshot UID is undefined');
197
232
  }
198
233
  // DevTools calculateSnapshotDiff uses the first parameter (baseSnapshotId)
199
234
  // as a cache key. We pass the unique UID of the base snapshot.
200
- const rawDiffs = await currentSnapshot.calculateSnapshotDiff(baseSnapshotId, aggregatesForDiff);
235
+ const rawDiffs = await currentSnapshot.proxy.calculateSnapshotDiff(baseSnapshotId, aggregatesForDiff);
201
236
  // Return a filtered and sorted array here to ensure that
202
237
  // compare_heapsnapshot_summary and compare_heapsnapshot_details agree
203
238
  // on indices.
@@ -205,10 +240,6 @@ export class HeapSnapshotManager {
205
240
  .filter(diff => diff.addedCount > 0 || diff.removedCount > 0)
206
241
  .sort((a, b) => b.sizeDelta - a.sizeDelta);
207
242
  }
208
- async resolveClassKeyFromId(filePath, id) {
209
- const cached = this.#getCachedSnapshot(filePath);
210
- return cached.idToClassKey[id];
211
- }
212
243
  async #loadSnapshot(absolutePath, uid) {
213
244
  const workerProxy = new DevTools.HeapSnapshotModel.HeapSnapshotProxy.HeapSnapshotWorkerProxy(() => {
214
245
  /* noop */
@@ -227,43 +258,49 @@ export class HeapSnapshotManager {
227
258
  }
228
259
  await loaderProxy.close();
229
260
  const snapshot = await snapshotPromise;
230
- return { snapshot, worker: workerProxy };
261
+ // Assign ids to all aggregates of this snapshot. This ensures ids are available
262
+ // even without calling getAggregates() and deterministic (do not depend on
263
+ // the filter used on the getAggregates() call).
264
+ const aggregates = await snapshot.aggregatesWithFilter(new DevTools.HeapSnapshotModel.HeapSnapshotModel.NodeFilter());
265
+ return new HeapSnapshot(snapshot, workerProxy, aggregates);
231
266
  }
232
267
  catch (error) {
233
- // The worker is created before the read, and a failed load never reaches
234
- // the #snapshots map, so dispose()/disposeAll() can never clean it up.
235
- // Dispose it here to avoid leaking a worker on every failed load (e.g. a
236
- // missing or invalid .heapsnapshot path).
268
+ // Remove the rejected promise from #snapshots and dispose the worker to
269
+ // avoid leaking it on a failed load (e.g. a missing or invalid
270
+ // .heapsnapshot path).
271
+ this.#snapshots.delete(absolutePath);
237
272
  workerProxy.dispose();
238
273
  throw error;
239
274
  }
240
275
  }
241
276
  async getDuplicateStrings(filePath) {
242
277
  const snapshot = await this.getSnapshot(filePath);
243
- return await snapshot.getDuplicateStrings();
278
+ return await snapshot.proxy.getDuplicateStrings();
244
279
  }
245
280
  async queryObjects(filePath, options) {
246
281
  const snapshot = await this.getSnapshot(filePath);
247
- const provider = snapshot.queryObjects(options);
282
+ const provider = snapshot.proxy.queryObjects(options);
248
283
  return await provider.serializeItemsRange(0, Infinity);
249
284
  }
250
285
  hasSnapshots() {
251
286
  return this.#snapshots.size > 0;
252
287
  }
253
- disposeSnapshot(filePath) {
288
+ async disposeSnapshot(filePath) {
254
289
  const absolutePath = path.resolve(filePath);
255
290
  const cached = this.#snapshots.get(absolutePath);
256
291
  if (cached) {
257
- cached.worker.dispose();
258
292
  this.#snapshots.delete(absolutePath);
293
+ const { worker } = await cached;
294
+ worker.dispose();
259
295
  return true;
260
296
  }
261
297
  return false;
262
298
  }
263
299
  dispose() {
264
- for (const cached of this.#snapshots.values()) {
265
- cached.worker.dispose();
266
- }
300
+ void Promise.allSettled(this.#snapshots.values().map(async (cached) => {
301
+ const { worker } = await cached;
302
+ worker.dispose();
303
+ }));
267
304
  this.#snapshots.clear();
268
305
  }
269
306
  }
@@ -9,7 +9,7 @@ import { parseTraceEventsFromBuffer } from './ChunkedTraceParser.js';
9
9
  /**
10
10
  * Type guard that verifies if an operation returned a valid TraceResult.
11
11
  *
12
- * @param x - The result or error object to inspect.
12
+ * @param x The result or error object to inspect.
13
13
  * @returns True if the object is a TraceResult; otherwise false.
14
14
  */
15
15
  export function traceResultIsSuccess(x) {
@@ -23,8 +23,8 @@ export function traceResultIsSuccess(x) {
23
23
  * allocation limits. A new trace engine model is created per call to ensure session
24
24
  * isolation and prevent memory retention.
25
25
  *
26
- * @param buffer - Raw binary trace data representing trace events and metadata.
27
- * @param metadata - Optional throttling configurations applied during recording; overrides embedded file metadata when defined.
26
+ * @param buffer Raw binary trace data representing trace events and metadata.
27
+ * @param metadata Optional throttling configurations applied during recording; overrides embedded file metadata when defined.
28
28
  * @returns A promise resolving to a {@link TraceResult} with parsed traces and insights, or a {@link TraceParseError} on failure.
29
29
  */
30
30
  export async function parseRawTraceBuffer(buffer, metadata) {
@@ -85,8 +85,8 @@ ${DevTools.PerformanceTraceFormatter.networkDataFormatDescription}`;
85
85
  /**
86
86
  * Generates a Markdown summary of main thread activity and network metrics from a parsed trace.
87
87
  *
88
- * @param result - The parsed trace result to summarize.
89
- * @param deviceScope - Optional CrUX device scope to filter field data.
88
+ * @param result The parsed trace result to summarize.
89
+ * @param deviceScope Optional CrUX device scope to filter field data.
90
90
  * @returns Formatted Markdown text describing performance findings.
91
91
  */
92
92
  export function getTraceSummary(result, deviceScope) {
@@ -102,10 +102,10 @@ ${extraFormatDescriptions}`;
102
102
  /**
103
103
  * Formats a specific performance insight from a parsed trace for display.
104
104
  *
105
- * @param result - The parsed trace result containing computed insight sets.
106
- * @param insightSetId - The identifier of the target insight set.
107
- * @param insightName - The name of the insight model to extract.
108
- * @param deviceScope - Optional CrUX device scope to contextualize metrics.
105
+ * @param result The parsed trace result containing computed insight sets.
106
+ * @param insightSetId The identifier of the target insight set.
107
+ * @param insightName The name of the insight model to extract.
108
+ * @param deviceScope Optional CrUX device scope to contextualize metrics.
109
109
  * @returns An object containing the formatted insight output text or an error message.
110
110
  */
111
111
  export function getInsightOutput(result, insightSetId, insightName, deviceScope) {
@@ -161,7 +161,7 @@ export class ClearcutLogger {
161
161
  this.#watchdog.send({
162
162
  type: WatchdogMessageType.LOG_EVENT,
163
163
  payload: this.#addMcpClient({
164
- tool_invocation: tool_invocation,
164
+ tool_invocation,
165
165
  }),
166
166
  });
167
167
  }
@@ -156,34 +156,30 @@ function transformValue(zodType, value) {
156
156
  if (zodType === 'ZodString') {
157
157
  return bucketize(value.length);
158
158
  }
159
- else if (zodType === 'ZodArray') {
159
+ if (zodType === 'ZodArray') {
160
160
  return value.length;
161
161
  }
162
- else {
163
- return value;
164
- }
162
+ return value;
165
163
  }
166
164
  function hasEquivalentType(zodType, value) {
167
165
  if (zodType === 'ZodString') {
168
166
  return typeof value === 'string';
169
167
  }
170
- else if (zodType === 'ZodArray') {
168
+ if (zodType === 'ZodArray') {
171
169
  return Array.isArray(value);
172
170
  }
173
- else if (zodType === 'ZodNumber') {
171
+ if (zodType === 'ZodNumber') {
174
172
  return typeof value === 'number';
175
173
  }
176
- else if (zodType === 'ZodBoolean') {
174
+ if (zodType === 'ZodBoolean') {
177
175
  return typeof value === 'boolean';
178
176
  }
179
- else if (zodType === 'ZodEnum') {
177
+ if (zodType === 'ZodEnum') {
180
178
  return (typeof value === 'string' ||
181
179
  typeof value === 'number' ||
182
180
  typeof value === 'boolean');
183
181
  }
184
- else {
185
- return false;
186
- }
182
+ return false;
187
183
  }
188
184
  export function sanitizeParams(params, schema) {
189
185
  const transformed = {};
@@ -73,7 +73,7 @@ function main() {
73
73
  }, null, 2));
74
74
  const sender = new ClearcutSender({
75
75
  appVersion,
76
- osType: osType,
76
+ osType,
77
77
  clearcutEndpoint,
78
78
  forceFlushIntervalMs: clearcutForceFlushIntervalMs,
79
79
  includePidHeader: clearcutIncludePidHeader,