chrome-devtools-mcp 1.11.0 → 1.12.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 (72) hide show
  1. package/README.md +72 -20
  2. package/build/src/BrowserManager.js +27 -18
  3. package/build/src/McpContext.js +435 -87
  4. package/build/src/McpPage.js +189 -59
  5. package/build/src/McpResponse.js +61 -44
  6. package/build/src/TextSnapshot.js +37 -18
  7. package/build/src/ToolHandler.js +256 -135
  8. package/build/src/bin/chrome-devtools-mcp-main.js +6 -4
  9. package/build/src/bin/chrome-devtools.js +4 -4
  10. package/build/src/collectors/PageCollector.js +13 -9
  11. package/build/src/collectors/ServiceWorkerCollector.js +2 -2
  12. package/build/src/collectors/constants.js +7 -0
  13. package/build/src/config/ConfigParser.js +44 -149
  14. package/build/src/config/ConfigWatcher.js +3 -2
  15. package/build/src/config/ServerConfig.js +251 -0
  16. package/build/src/config/browser-options.js +13 -4
  17. package/build/src/config/cli-options.js +35 -19
  18. package/build/src/config/mcp-options.js +61 -35
  19. package/build/src/config/puppeteer-options.js +4 -2
  20. package/build/src/daemon/client.js +3 -3
  21. package/build/src/daemon/daemon.js +7 -3
  22. package/build/src/daemon/utils.js +2 -1
  23. package/build/src/devtools/DevToolsCommentBridge.js +28 -5
  24. package/build/src/devtools/DevtoolsUtils.js +49 -12
  25. package/build/src/formatters/ConsoleFormatter.js +28 -1
  26. package/build/src/formatters/HeapSnapshotFormatter.js +14 -18
  27. package/build/src/formatters/NetworkFormatter.js +54 -15
  28. package/build/src/formatters/RemoteObjectFormatter.js +231 -0
  29. package/build/src/formatters/SnapshotFormatter.js +13 -3
  30. package/build/src/index.js +256 -104
  31. package/build/src/processors/HeapSnapshotManager.js +390 -128
  32. package/build/src/third_party/THIRD_PARTY_NOTICES +542 -445
  33. package/build/src/third_party/bundled-packages.json +2 -2
  34. package/build/src/third_party/cli.js +9239 -0
  35. package/build/src/third_party/devtools-formatter-worker.js +3089 -2438
  36. package/build/src/third_party/devtools-heap-snapshot-worker.js +172 -1
  37. package/build/src/third_party/index.js +52247 -55764
  38. package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +54576 -52174
  39. package/build/src/tools/ToolDefinition.js +90 -12
  40. package/build/src/tools/comments.js +42 -3
  41. package/build/src/tools/console.js +6 -4
  42. package/build/src/tools/css.js +1 -0
  43. package/build/src/tools/emulation.js +5 -4
  44. package/build/src/tools/extensions.js +5 -0
  45. package/build/src/tools/input.js +21 -6
  46. package/build/src/tools/lighthouse.js +24 -8
  47. package/build/src/tools/memory.js +59 -53
  48. package/build/src/tools/network.js +5 -4
  49. package/build/src/tools/pages.js +48 -6
  50. package/build/src/tools/performance.js +7 -4
  51. package/build/src/tools/pwa.js +7 -0
  52. package/build/src/tools/screencast.js +3 -1
  53. package/build/src/tools/screenshot.js +23 -7
  54. package/build/src/tools/script.js +38 -6
  55. package/build/src/tools/slim/tools.js +21 -5
  56. package/build/src/tools/snapshot.js +13 -3
  57. package/build/src/tools/thirdPartyDeveloper.js +3 -1
  58. package/build/src/tools/webmcp.js +2 -0
  59. package/build/src/utils/TaskRunner.js +136 -0
  60. package/build/src/utils/WaitForHelper.js +1 -1
  61. package/build/src/utils/bytes.js +2 -12
  62. package/build/src/utils/check-for-updates.js +1 -1
  63. package/build/src/utils/disclaimers.js +27 -0
  64. package/build/src/utils/keyboard.js +14 -2
  65. package/build/src/utils/logger.js +69 -0
  66. package/build/src/utils/resourceType.js +27 -0
  67. package/build/src/utils/text.js +29 -0
  68. package/build/src/utils/timeout.js +14 -0
  69. package/build/src/utils/url.js +41 -0
  70. package/build/src/version.js +1 -1
  71. package/package.json +5 -4
  72. package/skills/a11y-debugging/SKILL.md +3 -8
@@ -3,10 +3,74 @@
3
3
  * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
7
+ if (value !== null && value !== void 0) {
8
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
9
+ var dispose, inner;
10
+ if (async) {
11
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
12
+ dispose = value[Symbol.asyncDispose];
13
+ }
14
+ if (dispose === void 0) {
15
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
16
+ dispose = value[Symbol.dispose];
17
+ if (async) inner = dispose;
18
+ }
19
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
20
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
21
+ env.stack.push({ value: value, dispose: dispose, async: async });
22
+ }
23
+ else if (async) {
24
+ env.stack.push({ async: true });
25
+ }
26
+ return value;
27
+ };
28
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
29
+ return function (env) {
30
+ function fail(e) {
31
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
32
+ env.hasError = true;
33
+ }
34
+ var r, s = 0;
35
+ function next() {
36
+ while (r = env.stack.pop()) {
37
+ try {
38
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
39
+ if (r.dispose) {
40
+ var result = r.dispose.call(r.value);
41
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
42
+ }
43
+ else s |= 1;
44
+ }
45
+ catch (e) {
46
+ fail(e);
47
+ }
48
+ }
49
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
50
+ if (env.hasError) throw env.error;
51
+ }
52
+ return next();
53
+ };
54
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
55
+ var e = new Error(message);
56
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
57
+ });
6
58
  import fsSync from 'node:fs';
7
59
  import path from 'node:path';
8
60
  import { DevTools } from '../third_party/index.js';
9
61
  import { createIdGenerator } from '../utils/id.js';
62
+ function toClassDiff(index, rawDiff) {
63
+ return {
64
+ index,
65
+ className: rawDiff.name,
66
+ addedCount: rawDiff.addedCount,
67
+ removedCount: rawDiff.removedCount,
68
+ countDelta: rawDiff.countDelta,
69
+ addedSize: rawDiff.addedSize,
70
+ removedSize: rawDiff.removedSize,
71
+ sizeDelta: rawDiff.sizeDelta,
72
+ };
73
+ }
10
74
  export class HeapSnapshot {
11
75
  proxy;
12
76
  worker;
@@ -36,6 +100,36 @@ function hasValidHeapSnapshotExtension(filePath) {
36
100
  export class HeapSnapshotManager {
37
101
  #snapshotIdGenerator = createIdGenerator();
38
102
  #snapshots = new Map();
103
+ /**
104
+ * Queue for all heap snapshot work, with one child queue per absolute file
105
+ * path. A read of one file holds the file queue, so reads of different
106
+ * files run at the same time. A read of several files holds this queue.
107
+ * `disposeSnapshot()` holds the file queue, so it waits for in-flight
108
+ * reads of the file, and a read that starts after it loads the file again.
109
+ */
110
+ #taskQueue;
111
+ #taskRunner;
112
+ #fileTaskQueues = new Map();
113
+ constructor(taskRunner) {
114
+ this.#taskRunner = taskRunner;
115
+ this.#taskQueue = taskRunner.createQueue();
116
+ }
117
+ /**
118
+ * Holds the queue of `filePath`, or the heap queue without a path, until
119
+ * the guard is disposed.
120
+ */
121
+ async #scheduleTask(filePath) {
122
+ if (filePath === undefined) {
123
+ return await this.#taskQueue.scheduleTask();
124
+ }
125
+ const absolutePath = path.resolve(filePath);
126
+ let queue = this.#fileTaskQueues.get(absolutePath);
127
+ if (!queue) {
128
+ queue = this.#taskRunner.createQueue(this.#taskQueue);
129
+ this.#fileTaskQueues.set(absolutePath, queue);
130
+ }
131
+ return await queue.scheduleTask();
132
+ }
39
133
  async getSnapshot(filePath) {
40
134
  if (!hasValidHeapSnapshotExtension(filePath)) {
41
135
  throw new Error(`File ${filePath} must have a .heapsnapshot or .heaptimeline extension.`);
@@ -65,107 +159,239 @@ export class HeapSnapshotManager {
65
159
  }
66
160
  }
67
161
  async getAggregates(filePath, filterName, objectId) {
68
- const snapshot = await this.getSnapshot(filePath);
69
- const filter = new DevTools.HeapSnapshotModel.HeapSnapshotModel.NodeFilter();
70
- await this.#applyNodeFilter(snapshot.proxy, filter, filterName, objectId);
71
- const rawAggregates = await snapshot.proxy.aggregatesWithFilter(filter);
72
- let objectCount = 0;
73
- let totalSelfSize = 0;
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}`);
162
+ const env_1 = { stack: [], error: void 0, hasError: false };
163
+ try {
164
+ const guard = __addDisposableResource(env_1, await this.#scheduleTask(filePath), false);
165
+ const snapshot = await this.getSnapshot(filePath);
166
+ const filter = new DevTools.HeapSnapshotModel.HeapSnapshotModel.NodeFilter();
167
+ await this.#applyNodeFilter(snapshot.proxy, filter, filterName, objectId);
168
+ const rawAggregates = await snapshot.proxy.aggregatesWithFilter(filter);
169
+ let objectCount = 0;
170
+ let totalSelfSize = 0;
171
+ const aggregates = [];
172
+ for (const [key, aggregate] of Object.entries(rawAggregates)) {
173
+ const id = snapshot.resolveIdFromClassKey(key);
174
+ if (id === undefined) {
175
+ throw new Error(`No class ID found for class key ${key}`);
176
+ }
177
+ objectCount += aggregate.count;
178
+ totalSelfSize += aggregate.self;
179
+ aggregates.push({
180
+ id,
181
+ className: aggregate.name,
182
+ count: aggregate.count,
183
+ selfSize: aggregate.self,
184
+ retainedSize: aggregate.maxRet,
185
+ });
79
186
  }
80
- objectCount += aggregate.count;
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
- });
187
+ aggregates.sort((a, b) => b.retainedSize - a.retainedSize);
188
+ return {
189
+ aggregates,
190
+ objectCount,
191
+ totalSelfSize,
192
+ };
193
+ }
194
+ catch (e_1) {
195
+ env_1.error = e_1;
196
+ env_1.hasError = true;
197
+ }
198
+ finally {
199
+ __disposeResources(env_1);
89
200
  }
90
- aggregates.sort((a, b) => b.retainedSize - a.retainedSize);
91
- return {
92
- aggregates,
93
- objectCount,
94
- totalSelfSize,
95
- };
96
201
  }
97
202
  async getStats(filePath) {
98
- const snapshot = await this.getSnapshot(filePath);
99
- return await snapshot.proxy.getStatistics();
203
+ const env_2 = { stack: [], error: void 0, hasError: false };
204
+ try {
205
+ const guard = __addDisposableResource(env_2, await this.#scheduleTask(filePath), false);
206
+ const snapshot = await this.getSnapshot(filePath);
207
+ return await snapshot.proxy.getStatistics();
208
+ }
209
+ catch (e_2) {
210
+ env_2.error = e_2;
211
+ env_2.hasError = true;
212
+ }
213
+ finally {
214
+ __disposeResources(env_2);
215
+ }
100
216
  }
101
217
  async getStaticData(filePath) {
102
- const snapshot = await this.getSnapshot(filePath);
103
- return snapshot.proxy.staticData;
218
+ const env_3 = { stack: [], error: void 0, hasError: false };
219
+ try {
220
+ const guard = __addDisposableResource(env_3, await this.#scheduleTask(filePath), false);
221
+ const snapshot = await this.getSnapshot(filePath);
222
+ return snapshot.proxy.staticData;
223
+ }
224
+ catch (e_3) {
225
+ env_3.error = e_3;
226
+ env_3.hasError = true;
227
+ }
228
+ finally {
229
+ __disposeResources(env_3);
230
+ }
104
231
  }
105
232
  async getNativeContextSizes(filePath) {
106
- const snapshot = await this.getSnapshot(filePath);
107
- return await snapshot.proxy.getNativeContextSizes();
233
+ const env_4 = { stack: [], error: void 0, hasError: false };
234
+ try {
235
+ const guard = __addDisposableResource(env_4, await this.#scheduleTask(filePath), false);
236
+ const snapshot = await this.getSnapshot(filePath);
237
+ return await snapshot.proxy.getNativeContextSizes();
238
+ }
239
+ catch (e_4) {
240
+ env_4.error = e_4;
241
+ env_4.hasError = true;
242
+ }
243
+ finally {
244
+ __disposeResources(env_4);
245
+ }
108
246
  }
109
247
  async getRetainedByContextSummary(filePath) {
110
- const snapshot = await this.getSnapshot(filePath);
111
- return await snapshot.proxy.getRetainedByContextSummary();
248
+ const env_5 = { stack: [], error: void 0, hasError: false };
249
+ try {
250
+ const guard = __addDisposableResource(env_5, await this.#scheduleTask(filePath), false);
251
+ const snapshot = await this.getSnapshot(filePath);
252
+ return await snapshot.proxy.getRetainedByContextSummary();
253
+ }
254
+ catch (e_5) {
255
+ env_5.error = e_5;
256
+ env_5.hasError = true;
257
+ }
258
+ finally {
259
+ __disposeResources(env_5);
260
+ }
112
261
  }
113
262
  async getNodesById(filePath, id, filterName, objectId) {
114
- const snapshot = await this.getSnapshot(filePath);
115
- const filter = new DevTools.HeapSnapshotModel.HeapSnapshotModel.NodeFilter();
116
- await this.#applyNodeFilter(snapshot.proxy, filter, filterName, objectId);
117
- const className = snapshot.resolveClassKeyFromId(id);
118
- if (!className) {
119
- throw new Error(`Class with ID ${id} not found in heap snapshot`);
120
- }
121
- const provider = snapshot.proxy.createNodesProviderForClass(className, filter);
122
- return await provider.serializeItemsRange(0, Infinity);
263
+ const env_6 = { stack: [], error: void 0, hasError: false };
264
+ try {
265
+ const guard = __addDisposableResource(env_6, await this.#scheduleTask(filePath), false);
266
+ const snapshot = await this.getSnapshot(filePath);
267
+ const filter = new DevTools.HeapSnapshotModel.HeapSnapshotModel.NodeFilter();
268
+ await this.#applyNodeFilter(snapshot.proxy, filter, filterName, objectId);
269
+ const className = snapshot.resolveClassKeyFromId(id);
270
+ if (!className) {
271
+ throw new Error(`Class with ID ${id} not found in heap snapshot`);
272
+ }
273
+ const provider = snapshot.proxy.createNodesProviderForClass(className, filter);
274
+ return await provider.serializeItemsRange(0, Infinity);
275
+ }
276
+ catch (e_6) {
277
+ env_6.error = e_6;
278
+ env_6.hasError = true;
279
+ }
280
+ finally {
281
+ __disposeResources(env_6);
282
+ }
123
283
  }
124
284
  async getRetainers(filePath, nodeId) {
125
- const snapshot = await this.getSnapshot(filePath);
126
- const nodeIndex = await snapshot.proxy.nodeIndexForId(nodeId);
127
- if (nodeIndex === undefined) {
128
- throw new Error(`Node with ID ${nodeId} not found`);
285
+ const env_7 = { stack: [], error: void 0, hasError: false };
286
+ try {
287
+ const guard = __addDisposableResource(env_7, await this.#scheduleTask(filePath), false);
288
+ const snapshot = await this.getSnapshot(filePath);
289
+ const nodeIndex = await snapshot.proxy.nodeIndexForId(nodeId);
290
+ if (nodeIndex === undefined) {
291
+ throw new Error(`Node with ID ${nodeId} not found`);
292
+ }
293
+ const provider = snapshot.proxy.createRetainingEdgesProvider(nodeIndex);
294
+ return await provider.serializeItemsRange(0, Infinity);
295
+ }
296
+ catch (e_7) {
297
+ env_7.error = e_7;
298
+ env_7.hasError = true;
299
+ }
300
+ finally {
301
+ __disposeResources(env_7);
129
302
  }
130
- const provider = snapshot.proxy.createRetainingEdgesProvider(nodeIndex);
131
- return await provider.serializeItemsRange(0, Infinity);
132
303
  }
133
304
  async getObjectInfo(filePath, nodeId) {
134
- const snapshot = await this.getSnapshot(filePath);
135
- const nodeIndex = await snapshot.proxy.nodeIndexForId(nodeId);
136
- if (nodeIndex === undefined) {
137
- throw new Error(`Node with ID ${nodeId} not found`);
305
+ const env_8 = { stack: [], error: void 0, hasError: false };
306
+ try {
307
+ const guard = __addDisposableResource(env_8, await this.#scheduleTask(filePath), false);
308
+ const snapshot = await this.getSnapshot(filePath);
309
+ const nodeIndex = await snapshot.proxy.nodeIndexForId(nodeId);
310
+ if (nodeIndex === undefined) {
311
+ throw new Error(`Node with ID ${nodeId} not found`);
312
+ }
313
+ return await snapshot.proxy.getObjectInfo(nodeIndex);
314
+ }
315
+ catch (e_8) {
316
+ env_8.error = e_8;
317
+ env_8.hasError = true;
318
+ }
319
+ finally {
320
+ __disposeResources(env_8);
138
321
  }
139
- return await snapshot.proxy.getObjectInfo(nodeIndex);
140
322
  }
141
323
  async analyzeContexts(filePath) {
142
- const snapshot = await this.getSnapshot(filePath);
143
- return await snapshot.proxy.analyzeContexts();
324
+ const env_9 = { stack: [], error: void 0, hasError: false };
325
+ try {
326
+ const guard = __addDisposableResource(env_9, await this.#scheduleTask(filePath), false);
327
+ const snapshot = await this.getSnapshot(filePath);
328
+ return await snapshot.proxy.analyzeContexts();
329
+ }
330
+ catch (e_9) {
331
+ env_9.error = e_9;
332
+ env_9.hasError = true;
333
+ }
334
+ finally {
335
+ __disposeResources(env_9);
336
+ }
144
337
  }
145
338
  async getRetainingPaths(filePath, nodeId, maxDepth, maxNodes, maxSiblings) {
146
- const snapshot = await this.getSnapshot(filePath);
147
- const nodeIndex = await snapshot.proxy.nodeIndexForId(nodeId);
148
- if (nodeIndex === undefined) {
149
- throw new Error(`Node with ID ${nodeId} not found`);
339
+ const env_10 = { stack: [], error: void 0, hasError: false };
340
+ try {
341
+ const guard = __addDisposableResource(env_10, await this.#scheduleTask(filePath), false);
342
+ const snapshot = await this.getSnapshot(filePath);
343
+ const nodeIndex = await snapshot.proxy.nodeIndexForId(nodeId);
344
+ if (nodeIndex === undefined) {
345
+ throw new Error(`Node with ID ${nodeId} not found`);
346
+ }
347
+ return await snapshot.proxy.getRetainingPaths(nodeIndex, maxDepth, maxNodes, maxSiblings);
348
+ }
349
+ catch (e_10) {
350
+ env_10.error = e_10;
351
+ env_10.hasError = true;
352
+ }
353
+ finally {
354
+ __disposeResources(env_10);
150
355
  }
151
- return await snapshot.proxy.getRetainingPaths(nodeIndex, maxDepth, maxNodes, maxSiblings);
152
356
  }
153
357
  async getDominatorsOf(filePath, nodeId) {
154
- const snapshot = await this.getSnapshot(filePath);
155
- const nodeIndex = await snapshot.proxy.nodeIndexForId(nodeId);
156
- if (nodeIndex === undefined) {
157
- throw new Error(`Node with ID ${nodeId} not found`);
358
+ const env_11 = { stack: [], error: void 0, hasError: false };
359
+ try {
360
+ const guard = __addDisposableResource(env_11, await this.#scheduleTask(filePath), false);
361
+ const snapshot = await this.getSnapshot(filePath);
362
+ const nodeIndex = await snapshot.proxy.nodeIndexForId(nodeId);
363
+ if (nodeIndex === undefined) {
364
+ throw new Error(`Node with ID ${nodeId} not found`);
365
+ }
366
+ return await snapshot.proxy.getDominatorsOf(nodeIndex);
367
+ }
368
+ catch (e_11) {
369
+ env_11.error = e_11;
370
+ env_11.hasError = true;
371
+ }
372
+ finally {
373
+ __disposeResources(env_11);
158
374
  }
159
- return await snapshot.proxy.getDominatorsOf(nodeIndex);
160
375
  }
161
376
  async getEdges(filePath, nodeId, options) {
162
- const snapshot = await this.getSnapshot(filePath);
163
- const nodeIndex = await snapshot.proxy.nodeIndexForId(nodeId);
164
- if (nodeIndex === undefined) {
165
- throw new Error(`Node with ID ${nodeId} not found`);
377
+ const env_12 = { stack: [], error: void 0, hasError: false };
378
+ try {
379
+ const guard = __addDisposableResource(env_12, await this.#scheduleTask(filePath), false);
380
+ const snapshot = await this.getSnapshot(filePath);
381
+ const nodeIndex = await snapshot.proxy.nodeIndexForId(nodeId);
382
+ if (nodeIndex === undefined) {
383
+ throw new Error(`Node with ID ${nodeId} not found`);
384
+ }
385
+ const provider = snapshot.proxy.createEdgesProvider(nodeIndex, options);
386
+ return await provider.serializeItemsRange(0, Infinity);
387
+ }
388
+ catch (e_12) {
389
+ env_12.error = e_12;
390
+ env_12.hasError = true;
391
+ }
392
+ finally {
393
+ __disposeResources(env_12);
166
394
  }
167
- const provider = snapshot.proxy.createEdgesProvider(nodeIndex, options);
168
- return await provider.serializeItemsRange(0, Infinity);
169
395
  }
170
396
  async getClassDiffs(baseFilePath, currentFilePath) {
171
397
  const rawDiffs = await this.#getSortedRawClassDiffs(baseFilePath, currentFilePath);
@@ -179,16 +405,7 @@ export class HeapSnapshotManager {
179
405
  sizeDelta: 0,
180
406
  };
181
407
  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
- });
408
+ classDiffs.push(toClassDiff(index, rawDiff));
192
409
  totals.addedCount += rawDiff.addedCount;
193
410
  totals.removedCount += rawDiff.removedCount;
194
411
  totals.countDelta += rawDiff.countDelta;
@@ -204,41 +421,53 @@ export class HeapSnapshotManager {
204
421
  if (!rawDiff) {
205
422
  throw new Error(`Invalid classIndex: ${classIndex}. Total classes with changes: ${classDiffs.length}`);
206
423
  }
207
- return {
208
- index: classIndex,
209
- className: rawDiff.name,
210
- addedCount: rawDiff.addedCount,
211
- removedCount: rawDiff.removedCount,
212
- countDelta: rawDiff.countDelta,
213
- addedSize: rawDiff.addedSize,
214
- removedSize: rawDiff.removedSize,
215
- sizeDelta: rawDiff.sizeDelta,
216
- addedIds: rawDiff.addedIds ?? [],
217
- addedSelfSizes: rawDiff.addedSelfSizes ?? [],
218
- deletedIds: rawDiff.deletedIds ?? [],
219
- deletedSelfSizes: rawDiff.deletedSelfSizes ?? [],
220
- };
424
+ const objects = [];
425
+ const addedIds = rawDiff.addedIds ?? [];
426
+ const addedSelfSizes = rawDiff.addedSelfSizes ?? [];
427
+ for (const [i, id] of addedIds.entries()) {
428
+ objects.push({ id, selfSize: addedSelfSizes[i], change: 'added' });
429
+ }
430
+ const deletedIds = rawDiff.deletedIds ?? [];
431
+ const deletedSelfSizes = rawDiff.deletedSelfSizes ?? [];
432
+ for (const [i, id] of deletedIds.entries()) {
433
+ objects.push({ id, selfSize: deletedSelfSizes[i], change: 'deleted' });
434
+ }
435
+ // Largest objects first so that the first page of paginated output shows
436
+ // the most significant changes.
437
+ objects.sort((a, b) => b.selfSize - a.selfSize);
438
+ return { classDiff: toClassDiff(classIndex, rawDiff), objects };
221
439
  }
222
440
  async #getSortedRawClassDiffs(baseFilePath, currentFilePath) {
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;
230
- if (baseSnapshotId === undefined) {
231
- throw new Error('Base snapshot UID is undefined');
232
- }
233
- // DevTools calculateSnapshotDiff uses the first parameter (baseSnapshotId)
234
- // as a cache key. We pass the unique UID of the base snapshot.
235
- const rawDiffs = await currentSnapshot.proxy.calculateSnapshotDiff(baseSnapshotId, aggregatesForDiff);
236
- // Return a filtered and sorted array here to ensure that
237
- // compare_heapsnapshot_summary and compare_heapsnapshot_details agree
238
- // on indices.
239
- return Object.values(rawDiffs)
240
- .filter(diff => diff.addedCount > 0 || diff.removedCount > 0)
241
- .sort((a, b) => b.sizeDelta - a.sizeDelta);
441
+ const env_13 = { stack: [], error: void 0, hasError: false };
442
+ try {
443
+ const guard = __addDisposableResource(env_13, await this.#scheduleTask(), false);
444
+ const [baseSnapshot, currentSnapshot] = await Promise.all([
445
+ this.getSnapshot(baseFilePath),
446
+ this.getSnapshot(currentFilePath),
447
+ ]);
448
+ const interfaceDefinitions = await currentSnapshot.proxy.interfaceDefinitions();
449
+ const aggregatesForDiff = await baseSnapshot.proxy.aggregatesForDiff(interfaceDefinitions);
450
+ const baseSnapshotId = baseSnapshot.proxy.uid;
451
+ if (baseSnapshotId === undefined) {
452
+ throw new Error('Base snapshot UID is undefined');
453
+ }
454
+ // DevTools calculateSnapshotDiff uses the first parameter (baseSnapshotId)
455
+ // as a cache key. We pass the unique UID of the base snapshot.
456
+ const rawDiffs = await currentSnapshot.proxy.calculateSnapshotDiff(baseSnapshotId, aggregatesForDiff);
457
+ // Return a filtered and sorted array here to ensure that
458
+ // compare_heapsnapshot_summary and compare_heapsnapshot_details agree
459
+ // on indices.
460
+ return Object.values(rawDiffs)
461
+ .filter(diff => diff.addedCount > 0 || diff.removedCount > 0)
462
+ .sort((a, b) => b.sizeDelta - a.sizeDelta);
463
+ }
464
+ catch (e_13) {
465
+ env_13.error = e_13;
466
+ env_13.hasError = true;
467
+ }
468
+ finally {
469
+ __disposeResources(env_13);
470
+ }
242
471
  }
243
472
  async #loadSnapshot(absolutePath, uid) {
244
473
  const workerProxy = new DevTools.HeapSnapshotModel.HeapSnapshotProxy.HeapSnapshotWorkerProxy(() => {
@@ -274,27 +503,60 @@ export class HeapSnapshotManager {
274
503
  }
275
504
  }
276
505
  async getDuplicateStrings(filePath) {
277
- const snapshot = await this.getSnapshot(filePath);
278
- return await snapshot.proxy.getDuplicateStrings();
506
+ const env_14 = { stack: [], error: void 0, hasError: false };
507
+ try {
508
+ const guard = __addDisposableResource(env_14, await this.#scheduleTask(filePath), false);
509
+ const snapshot = await this.getSnapshot(filePath);
510
+ return await snapshot.proxy.getDuplicateStrings();
511
+ }
512
+ catch (e_14) {
513
+ env_14.error = e_14;
514
+ env_14.hasError = true;
515
+ }
516
+ finally {
517
+ __disposeResources(env_14);
518
+ }
279
519
  }
280
520
  async queryObjects(filePath, options) {
281
- const snapshot = await this.getSnapshot(filePath);
282
- const provider = snapshot.proxy.queryObjects(options);
283
- return await provider.serializeItemsRange(0, Infinity);
521
+ const env_15 = { stack: [], error: void 0, hasError: false };
522
+ try {
523
+ const guard = __addDisposableResource(env_15, await this.#scheduleTask(filePath), false);
524
+ const snapshot = await this.getSnapshot(filePath);
525
+ const provider = snapshot.proxy.queryObjects(options);
526
+ return await provider.serializeItemsRange(0, Infinity);
527
+ }
528
+ catch (e_15) {
529
+ env_15.error = e_15;
530
+ env_15.hasError = true;
531
+ }
532
+ finally {
533
+ __disposeResources(env_15);
534
+ }
284
535
  }
285
536
  hasSnapshots() {
286
537
  return this.#snapshots.size > 0;
287
538
  }
288
539
  async disposeSnapshot(filePath) {
289
- const absolutePath = path.resolve(filePath);
290
- const cached = this.#snapshots.get(absolutePath);
291
- if (cached) {
292
- this.#snapshots.delete(absolutePath);
293
- const { worker } = await cached;
294
- worker.dispose();
295
- return true;
540
+ const env_16 = { stack: [], error: void 0, hasError: false };
541
+ try {
542
+ const guard = __addDisposableResource(env_16, await this.#scheduleTask(filePath), false);
543
+ const absolutePath = path.resolve(filePath);
544
+ const cached = this.#snapshots.get(absolutePath);
545
+ if (cached) {
546
+ this.#snapshots.delete(absolutePath);
547
+ const { worker } = await cached;
548
+ worker.dispose();
549
+ return true;
550
+ }
551
+ return false;
552
+ }
553
+ catch (e_16) {
554
+ env_16.error = e_16;
555
+ env_16.hasError = true;
556
+ }
557
+ finally {
558
+ __disposeResources(env_16);
296
559
  }
297
- return false;
298
560
  }
299
561
  dispose() {
300
562
  void Promise.allSettled(this.#snapshots.values().map(async (cached) => {