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.
- package/README.md +72 -20
- package/build/src/BrowserManager.js +27 -18
- package/build/src/McpContext.js +435 -87
- package/build/src/McpPage.js +189 -59
- package/build/src/McpResponse.js +61 -44
- package/build/src/TextSnapshot.js +37 -18
- package/build/src/ToolHandler.js +256 -135
- package/build/src/bin/chrome-devtools-mcp-main.js +6 -4
- package/build/src/bin/chrome-devtools.js +4 -4
- package/build/src/collectors/PageCollector.js +13 -9
- package/build/src/collectors/ServiceWorkerCollector.js +2 -2
- package/build/src/collectors/constants.js +7 -0
- package/build/src/config/ConfigParser.js +44 -149
- package/build/src/config/ConfigWatcher.js +3 -2
- package/build/src/config/ServerConfig.js +251 -0
- package/build/src/config/browser-options.js +13 -4
- package/build/src/config/cli-options.js +35 -19
- package/build/src/config/mcp-options.js +61 -35
- package/build/src/config/puppeteer-options.js +4 -2
- package/build/src/daemon/client.js +3 -3
- package/build/src/daemon/daemon.js +7 -3
- package/build/src/daemon/utils.js +2 -1
- package/build/src/devtools/DevToolsCommentBridge.js +28 -5
- package/build/src/devtools/DevtoolsUtils.js +49 -12
- package/build/src/formatters/ConsoleFormatter.js +28 -1
- package/build/src/formatters/HeapSnapshotFormatter.js +14 -18
- package/build/src/formatters/NetworkFormatter.js +54 -15
- package/build/src/formatters/RemoteObjectFormatter.js +231 -0
- package/build/src/formatters/SnapshotFormatter.js +13 -3
- package/build/src/index.js +256 -104
- package/build/src/processors/HeapSnapshotManager.js +390 -128
- package/build/src/third_party/THIRD_PARTY_NOTICES +542 -445
- package/build/src/third_party/bundled-packages.json +2 -2
- package/build/src/third_party/cli.js +9239 -0
- package/build/src/third_party/devtools-formatter-worker.js +3089 -2438
- package/build/src/third_party/devtools-heap-snapshot-worker.js +172 -1
- package/build/src/third_party/index.js +52247 -55764
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +54576 -52174
- package/build/src/tools/ToolDefinition.js +90 -12
- package/build/src/tools/comments.js +42 -3
- package/build/src/tools/console.js +6 -4
- package/build/src/tools/css.js +1 -0
- package/build/src/tools/emulation.js +5 -4
- package/build/src/tools/extensions.js +5 -0
- package/build/src/tools/input.js +21 -6
- package/build/src/tools/lighthouse.js +24 -8
- package/build/src/tools/memory.js +59 -53
- package/build/src/tools/network.js +5 -4
- package/build/src/tools/pages.js +48 -6
- package/build/src/tools/performance.js +7 -4
- package/build/src/tools/pwa.js +7 -0
- package/build/src/tools/screencast.js +3 -1
- package/build/src/tools/screenshot.js +23 -7
- package/build/src/tools/script.js +38 -6
- package/build/src/tools/slim/tools.js +21 -5
- package/build/src/tools/snapshot.js +13 -3
- package/build/src/tools/thirdPartyDeveloper.js +3 -1
- package/build/src/tools/webmcp.js +2 -0
- package/build/src/utils/TaskRunner.js +136 -0
- package/build/src/utils/WaitForHelper.js +1 -1
- package/build/src/utils/bytes.js +2 -12
- package/build/src/utils/check-for-updates.js +1 -1
- package/build/src/utils/disclaimers.js +27 -0
- package/build/src/utils/keyboard.js +14 -2
- package/build/src/utils/logger.js +69 -0
- package/build/src/utils/resourceType.js +27 -0
- package/build/src/utils/text.js +29 -0
- package/build/src/utils/timeout.js +14 -0
- package/build/src/utils/url.js +41 -0
- package/build/src/version.js +1 -1
- package/package.json +5 -4
- 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
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
|
99
|
-
|
|
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
|
|
103
|
-
|
|
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
|
|
107
|
-
|
|
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
|
|
111
|
-
|
|
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
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
|
143
|
-
|
|
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
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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 [
|
|
224
|
-
|
|
225
|
-
this
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
|
278
|
-
|
|
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
|
|
282
|
-
|
|
283
|
-
|
|
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
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
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) => {
|