chrome-devtools-mcp 1.10.1 → 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.
- package/build/src/BrowserManager.js +132 -13
- package/build/src/McpContext.js +188 -138
- package/build/src/McpPage.js +348 -96
- package/build/src/McpResponse.js +234 -76
- package/build/src/McpWorker.js +66 -0
- package/build/src/SlimMcpResponse.js +5 -1
- package/build/src/TextSnapshot.js +3 -2
- package/build/src/ToolHandler.js +80 -42
- package/build/src/bin/chrome-devtools-mcp-main.js +8 -7
- package/build/src/bin/chrome-devtools-mcp.js +1 -1
- package/build/src/bin/chrome-devtools.js +31 -41
- package/build/src/collectors/ServiceWorkerCollector.js +18 -11
- package/build/src/config/ConfigLocator.js +70 -0
- package/build/src/config/ConfigParser.js +264 -0
- package/build/src/config/ConfigWatcher.js +93 -0
- package/build/src/config/browser-options.js +2 -13
- package/build/src/config/category-options.js +15 -30
- package/build/src/config/cli-commands.js +165 -5
- package/build/src/config/cli-options.js +410 -43
- package/build/src/config/mcp-options.js +156 -234
- package/build/src/config/puppeteer-options.js +65 -0
- package/build/src/config/tool-options.js +60 -0
- package/build/src/daemon/client.js +81 -41
- package/build/src/daemon/daemon.js +55 -45
- package/build/src/daemon/utils.js +44 -11
- package/build/src/devtools/DevToolsCommentBridge.js +43 -6
- package/build/src/devtools/DevtoolsUtils.js +3 -3
- package/build/src/devtools/McpHostBindingAdapter.js +0 -1
- package/build/src/formatters/CommentFormatter.js +4 -13
- package/build/src/formatters/ConsoleFormatter.js +1 -1
- package/build/src/formatters/CssFormatter.js +3 -2
- package/build/src/formatters/HeapSnapshotFormatter.js +104 -46
- package/build/src/formatters/IssueFormatter.js +33 -32
- package/build/src/formatters/NetworkFormatter.js +12 -11
- package/build/src/formatters/SnapshotFormatter.js +31 -4
- package/build/src/index.js +54 -9
- package/build/src/processors/ChunkedTraceParser.js +11 -11
- package/build/src/processors/HeapSnapshotManager.js +121 -84
- package/build/src/processors/PerformanceTrace.js +9 -9
- package/build/src/telemetry/ClearcutLogger.js +1 -1
- package/build/src/telemetry/transformation.js +7 -11
- package/build/src/telemetry/watchdog/main.js +1 -1
- package/build/src/third_party/THIRD_PARTY_NOTICES +10 -397
- package/build/src/third_party/bundled-packages.json +7 -8
- package/build/src/third_party/devtools-formatter-worker.js +1193 -62
- package/build/src/third_party/devtools-heap-snapshot-worker.js +1126 -21
- package/build/src/third_party/index.js +8087 -19419
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantRead.md +0 -1
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantReadOptOut.md +5 -0
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSet.md +0 -1
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSetOptOut.md +5 -0
- package/build/src/third_party/issue-descriptions/deprecation.md +1 -1
- package/build/src/third_party/issue-descriptions/genericGeolocationPromptWithoutUserGesture.md +5 -0
- package/build/src/third_party/issue-descriptions/sriValidationFailedIntegrityMismatch.md +2 -0
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +3 -3
- package/build/src/tools/ToolDefinition.js +16 -4
- package/build/src/tools/comments.js +20 -1
- package/build/src/tools/css.js +4 -2
- package/build/src/tools/emulation.js +17 -4
- package/build/src/tools/input.js +8 -3
- package/build/src/tools/lighthouse.js +112 -4
- package/build/src/tools/memory.js +129 -28
- package/build/src/tools/pages.js +5 -2
- package/build/src/tools/performance.js +21 -3
- package/build/src/tools/screencast.js +71 -32
- package/build/src/tools/screenshot.js +29 -14
- package/build/src/tools/script.js +90 -37
- package/build/src/tools/slim/tools.js +6 -8
- package/build/src/tools/thirdPartyDeveloper.js +6 -4
- package/build/src/tools/tools.js +35 -22
- package/build/src/tools/webmcp.js +9 -6
- package/build/src/types.js +11 -0
- package/build/src/utils/WaitForHelper.js +14 -1
- package/build/src/utils/check-for-updates.js +1 -1
- package/build/src/utils/errorHandling.js +20 -0
- package/build/src/utils/logger.js +15 -5
- package/build/src/utils/text.js +15 -0
- package/build/src/utils/url.js +99 -3
- package/build/src/version.js +1 -1
- package/package.json +14 -10
- package/skills/a11y-debugging/SKILL.md +4 -4
- package/skills/chrome-devtools/SKILL.md +2 -2
- package/skills/chrome-devtools-cli/SKILL.md +18 -15
- package/skills/cookie-debugging/SKILL.md +8 -5
- package/skills/debug-optimize-lcp/SKILL.md +1 -1
- package/skills/troubleshooting/SKILL.md +5 -6
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { MAX_NAME_LENGTH } from '../formatters/HeapSnapshotFormatter.js';
|
|
6
7
|
import { zod } from '../third_party/index.js';
|
|
7
8
|
import { byteSizeRangeSchema } from '../utils/bytes.js';
|
|
8
9
|
import { ToolCategory } from './categories.js';
|
|
@@ -16,6 +17,24 @@ const HEAP_SNAPSHOT_FILTERS = [
|
|
|
16
17
|
'noNativeContext',
|
|
17
18
|
'attributedToSpecificNativeContext',
|
|
18
19
|
];
|
|
20
|
+
const maxNameLengthSchema = zod
|
|
21
|
+
.number()
|
|
22
|
+
.int()
|
|
23
|
+
.min(1)
|
|
24
|
+
.optional()
|
|
25
|
+
.describe(`Maximum length of names before truncation. Defaults to ${MAX_NAME_LENGTH}.`);
|
|
26
|
+
const pageIdxSchema = zod
|
|
27
|
+
.number()
|
|
28
|
+
.int()
|
|
29
|
+
.nonnegative()
|
|
30
|
+
.optional()
|
|
31
|
+
.describe('The page index for pagination.');
|
|
32
|
+
const pageSizeSchema = zod
|
|
33
|
+
.number()
|
|
34
|
+
.int()
|
|
35
|
+
.positive()
|
|
36
|
+
.optional()
|
|
37
|
+
.describe('The page size for pagination.');
|
|
19
38
|
export const takeHeapSnapshot = definePageTool(() => ({
|
|
20
39
|
name: 'take_heapsnapshot',
|
|
21
40
|
description: `Capture a heap snapshot of the target page. Use to analyze the memory distribution of JavaScript objects and debug memory leaks.`,
|
|
@@ -43,7 +62,7 @@ export const takeHeapSnapshot = definePageTool(() => ({
|
|
|
43
62
|
}));
|
|
44
63
|
export const getHeapSnapshotSummary = defineTool(() => ({
|
|
45
64
|
name: 'get_heapsnapshot_summary',
|
|
46
|
-
description: 'Loads a memory heapsnapshot and returns snapshot summary stats, including native contexts and their sizes, and retained by context summary.',
|
|
65
|
+
description: 'Loads and caches a memory heapsnapshot and returns snapshot summary stats, including native contexts and their sizes, and retained by context summary.',
|
|
47
66
|
annotations: {
|
|
48
67
|
category: ToolCategory.MEMORY,
|
|
49
68
|
readOnlyHint: true,
|
|
@@ -51,6 +70,7 @@ export const getHeapSnapshotSummary = defineTool(() => ({
|
|
|
51
70
|
},
|
|
52
71
|
schema: {
|
|
53
72
|
filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
|
|
73
|
+
maxNameLength: maxNameLengthSchema,
|
|
54
74
|
},
|
|
55
75
|
blockedByDialog: false,
|
|
56
76
|
verifyFilesSchema: {
|
|
@@ -61,12 +81,14 @@ export const getHeapSnapshotSummary = defineTool(() => ({
|
|
|
61
81
|
const staticData = await context.getHeapSnapshotStaticData(request.params.filePath);
|
|
62
82
|
const nativeContextSizes = await context.getHeapSnapshotNativeContextSizes(request.params.filePath);
|
|
63
83
|
const retainedByContextSummary = await context.getHeapSnapshotRetainedByContextSummary(request.params.filePath);
|
|
64
|
-
response.setHeapSnapshotStats(stats, staticData, nativeContextSizes, retainedByContextSummary
|
|
84
|
+
response.setHeapSnapshotStats(stats, staticData, nativeContextSizes, retainedByContextSummary, {
|
|
85
|
+
maxNameLength: request.params.maxNameLength,
|
|
86
|
+
});
|
|
65
87
|
},
|
|
66
88
|
}));
|
|
67
89
|
export const getHeapSnapshotDetails = defineTool(() => ({
|
|
68
90
|
name: 'get_heapsnapshot_details',
|
|
69
|
-
description: 'Loads a memory heapsnapshot and returns all available information including statistics, static data, and aggregated node information. Supports pagination for aggregates.',
|
|
91
|
+
description: 'Loads and caches a memory heapsnapshot and returns all available information including statistics, static data, and aggregated node information. Supports pagination for aggregates.',
|
|
70
92
|
annotations: {
|
|
71
93
|
category: ToolCategory.MEMORY,
|
|
72
94
|
readOnlyHint: true,
|
|
@@ -82,12 +104,17 @@ export const getHeapSnapshotDetails = defineTool(() => ({
|
|
|
82
104
|
.number()
|
|
83
105
|
.optional()
|
|
84
106
|
.describe('The object ID (nodeId) of the specific native context to filter by when filterName is attributedToSpecificNativeContext.'),
|
|
107
|
+
maxNameLength: maxNameLengthSchema,
|
|
85
108
|
pageIdx: zod
|
|
86
109
|
.number()
|
|
110
|
+
.int()
|
|
111
|
+
.nonnegative()
|
|
87
112
|
.optional()
|
|
88
113
|
.describe('The page index for pagination of aggregates.'),
|
|
89
114
|
pageSize: zod
|
|
90
115
|
.number()
|
|
116
|
+
.int()
|
|
117
|
+
.positive()
|
|
91
118
|
.optional()
|
|
92
119
|
.describe('The page size for pagination of aggregates.'),
|
|
93
120
|
},
|
|
@@ -100,12 +127,13 @@ export const getHeapSnapshotDetails = defineTool(() => ({
|
|
|
100
127
|
response.setHeapSnapshotAggregates(aggregates, {
|
|
101
128
|
pageIdx: request.params.pageIdx,
|
|
102
129
|
pageSize: request.params.pageSize,
|
|
130
|
+
maxNameLength: request.params.maxNameLength,
|
|
103
131
|
});
|
|
104
132
|
},
|
|
105
133
|
}));
|
|
106
134
|
export const getHeapSnapshotClassNodes = defineTool(() => ({
|
|
107
135
|
name: 'get_heapsnapshot_class_nodes',
|
|
108
|
-
description: 'Loads a memory heapsnapshot and returns instances of a specific class with their IDs.',
|
|
136
|
+
description: 'Loads and caches a memory heapsnapshot and returns instances of a specific class with their IDs.',
|
|
109
137
|
annotations: {
|
|
110
138
|
category: ToolCategory.MEMORY,
|
|
111
139
|
readOnlyHint: true,
|
|
@@ -122,8 +150,9 @@ export const getHeapSnapshotClassNodes = defineTool(() => ({
|
|
|
122
150
|
.number()
|
|
123
151
|
.optional()
|
|
124
152
|
.describe('The object ID (nodeId) of the specific native context to filter by when filterName is attributedToSpecificNativeContext.'),
|
|
125
|
-
|
|
126
|
-
|
|
153
|
+
maxNameLength: maxNameLengthSchema,
|
|
154
|
+
pageIdx: pageIdxSchema,
|
|
155
|
+
pageSize: pageSizeSchema,
|
|
127
156
|
},
|
|
128
157
|
blockedByDialog: false,
|
|
129
158
|
verifyFilesSchema: {
|
|
@@ -134,12 +163,13 @@ export const getHeapSnapshotClassNodes = defineTool(() => ({
|
|
|
134
163
|
response.setHeapSnapshotNodes(nodes, {
|
|
135
164
|
pageIdx: request.params.pageIdx,
|
|
136
165
|
pageSize: request.params.pageSize,
|
|
166
|
+
maxNameLength: request.params.maxNameLength,
|
|
137
167
|
});
|
|
138
168
|
},
|
|
139
169
|
}));
|
|
140
170
|
export const getHeapSnapshotRetainers = defineTool(() => ({
|
|
141
171
|
name: 'get_heapsnapshot_retainers',
|
|
142
|
-
description: 'Loads a memory heapsnapshot and returns retainers for a specific node ID.',
|
|
172
|
+
description: 'Loads and caches a memory heapsnapshot and returns retainers for a specific node ID.',
|
|
143
173
|
annotations: {
|
|
144
174
|
category: ToolCategory.MEMORY,
|
|
145
175
|
readOnlyHint: true,
|
|
@@ -152,20 +182,22 @@ export const getHeapSnapshotRetainers = defineTool(() => ({
|
|
|
152
182
|
schema: {
|
|
153
183
|
filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
|
|
154
184
|
nodeId: zod.number().describe('The node ID to get retainers for.'),
|
|
155
|
-
|
|
156
|
-
|
|
185
|
+
maxNameLength: maxNameLengthSchema,
|
|
186
|
+
pageIdx: pageIdxSchema,
|
|
187
|
+
pageSize: pageSizeSchema,
|
|
157
188
|
},
|
|
158
189
|
handler: async (request, response, context) => {
|
|
159
190
|
const retainers = await context.getHeapSnapshotRetainers(request.params.filePath, request.params.nodeId);
|
|
160
191
|
response.setHeapSnapshotNodes(retainers, {
|
|
161
192
|
pageIdx: request.params.pageIdx,
|
|
162
193
|
pageSize: request.params.pageSize,
|
|
194
|
+
maxNameLength: request.params.maxNameLength,
|
|
163
195
|
});
|
|
164
196
|
},
|
|
165
197
|
}));
|
|
166
198
|
export const closeHeapSnapshot = defineTool(() => ({
|
|
167
199
|
name: 'close_heapsnapshot',
|
|
168
|
-
description: 'Closes a previously loaded memory heapsnapshot, freeing its memory.',
|
|
200
|
+
description: 'Closes a previously loaded and cached memory heapsnapshot, freeing its memory.',
|
|
169
201
|
annotations: {
|
|
170
202
|
category: ToolCategory.MEMORY,
|
|
171
203
|
readOnlyHint: false,
|
|
@@ -190,7 +222,7 @@ export const closeHeapSnapshot = defineTool(() => ({
|
|
|
190
222
|
}));
|
|
191
223
|
export const getHeapSnapshotRetainingPaths = defineTool(() => ({
|
|
192
224
|
name: 'get_heapsnapshot_retaining_paths',
|
|
193
|
-
description: 'Loads a memory heapsnapshot and returns retaining paths for a specific node ID. This helps to understand why a node is not being garbage collected.',
|
|
225
|
+
description: 'Loads and caches a memory heapsnapshot and returns retaining paths for a specific node ID. This helps to understand why a node is not being garbage collected.',
|
|
194
226
|
annotations: {
|
|
195
227
|
category: ToolCategory.MEMORY,
|
|
196
228
|
readOnlyHint: true,
|
|
@@ -215,15 +247,18 @@ export const getHeapSnapshotRetainingPaths = defineTool(() => ({
|
|
|
215
247
|
.number()
|
|
216
248
|
.optional()
|
|
217
249
|
.describe('The maximum number of siblings to return.'),
|
|
250
|
+
maxNameLength: maxNameLengthSchema,
|
|
218
251
|
},
|
|
219
252
|
handler: async (request, response, context) => {
|
|
220
253
|
const retainingPaths = await context.getHeapSnapshotRetainingPaths(request.params.filePath, request.params.nodeId, request.params.maxDepth, request.params.maxNodes, request.params.maxSiblings);
|
|
221
|
-
response.setHeapSnapshotRetainingPaths(retainingPaths
|
|
254
|
+
response.setHeapSnapshotRetainingPaths(retainingPaths, {
|
|
255
|
+
maxNameLength: request.params.maxNameLength,
|
|
256
|
+
});
|
|
222
257
|
},
|
|
223
258
|
}));
|
|
224
259
|
export const getHeapSnapshotEdges = defineTool(() => ({
|
|
225
260
|
name: 'get_heapsnapshot_edges',
|
|
226
|
-
description: 'Loads a memory heapsnapshot and returns outgoing edges (references) for a specific node ID.',
|
|
261
|
+
description: 'Loads and caches a memory heapsnapshot and returns outgoing edges (references) for a specific node ID.',
|
|
227
262
|
annotations: {
|
|
228
263
|
category: ToolCategory.MEMORY,
|
|
229
264
|
readOnlyHint: true,
|
|
@@ -245,8 +280,9 @@ export const getHeapSnapshotEdges = defineTool(() => ({
|
|
|
245
280
|
.boolean()
|
|
246
281
|
.optional()
|
|
247
282
|
.describe('Whether to exclude primitive target nodes. Default is true.'),
|
|
248
|
-
|
|
249
|
-
|
|
283
|
+
maxNameLength: maxNameLengthSchema,
|
|
284
|
+
pageIdx: pageIdxSchema,
|
|
285
|
+
pageSize: pageSizeSchema,
|
|
250
286
|
},
|
|
251
287
|
handler: async (request, response, context) => {
|
|
252
288
|
const edges = await context.getHeapSnapshotEdges(request.params.filePath, request.params.nodeId, {
|
|
@@ -258,12 +294,13 @@ export const getHeapSnapshotEdges = defineTool(() => ({
|
|
|
258
294
|
response.setHeapSnapshotNodes(edges, {
|
|
259
295
|
pageIdx: request.params.pageIdx,
|
|
260
296
|
pageSize: request.params.pageSize,
|
|
297
|
+
maxNameLength: request.params.maxNameLength,
|
|
261
298
|
});
|
|
262
299
|
},
|
|
263
300
|
}));
|
|
264
301
|
export const getHeapSnapshotDominators = defineTool(() => ({
|
|
265
302
|
name: 'get_heapsnapshot_dominators',
|
|
266
|
-
description: 'Loads a memory heapsnapshot and returns the dominator chain for a specific node ID. This helps to identify which objects are keeping the target node alive.',
|
|
303
|
+
description: 'Loads and caches a memory heapsnapshot and returns the dominator chain for a specific node ID. This helps to identify which objects are keeping the target node alive.',
|
|
267
304
|
annotations: {
|
|
268
305
|
category: ToolCategory.MEMORY,
|
|
269
306
|
readOnlyHint: true,
|
|
@@ -278,15 +315,18 @@ export const getHeapSnapshotDominators = defineTool(() => ({
|
|
|
278
315
|
nodeId: zod
|
|
279
316
|
.number()
|
|
280
317
|
.describe('The node ID to get the dominator chain for.'),
|
|
318
|
+
maxNameLength: maxNameLengthSchema,
|
|
281
319
|
},
|
|
282
320
|
handler: async (request, response, context) => {
|
|
283
321
|
const dominators = await context.getHeapSnapshotDominators(request.params.filePath, request.params.nodeId);
|
|
284
|
-
response.setHeapSnapshotDominators(dominators
|
|
322
|
+
response.setHeapSnapshotDominators(dominators, {
|
|
323
|
+
maxNameLength: request.params.maxNameLength,
|
|
324
|
+
});
|
|
285
325
|
},
|
|
286
326
|
}));
|
|
287
327
|
export const compareHeapSnapshots = defineTool(() => ({
|
|
288
328
|
name: 'compare_heapsnapshots',
|
|
289
|
-
description: 'Loads two memory heapsnapshots and returns the comparison. If classIndex is provided, returns detailed diff for that class, otherwise returns summary diff.',
|
|
329
|
+
description: 'Loads and caches two memory heapsnapshots and returns the comparison. If classIndex is provided, returns detailed diff for that class, otherwise returns summary diff.',
|
|
290
330
|
annotations: {
|
|
291
331
|
category: ToolCategory.MEMORY,
|
|
292
332
|
readOnlyHint: true,
|
|
@@ -307,22 +347,31 @@ export const compareHeapSnapshots = defineTool(() => ({
|
|
|
307
347
|
.number()
|
|
308
348
|
.optional()
|
|
309
349
|
.describe('Optional 0-based index of the class in the summary list to filter results, showing individual objects.'),
|
|
350
|
+
maxNameLength: maxNameLengthSchema,
|
|
351
|
+
pageIdx: pageIdxSchema,
|
|
352
|
+
pageSize: pageSizeSchema,
|
|
310
353
|
},
|
|
311
354
|
blockedByDialog: false,
|
|
312
355
|
handler: async (request, response, context) => {
|
|
313
356
|
if (request.params.classIndex !== undefined) {
|
|
314
357
|
const classDiffResult = await context.getHeapSnapshotDetailedClassDiff(request.params.baseFilePath, request.params.currentFilePath, request.params.classIndex);
|
|
315
|
-
response.setHeapSnapshotDetailedClassDiff(classDiffResult
|
|
358
|
+
response.setHeapSnapshotDetailedClassDiff(classDiffResult, {
|
|
359
|
+
maxNameLength: request.params.maxNameLength,
|
|
360
|
+
});
|
|
316
361
|
}
|
|
317
362
|
else {
|
|
318
363
|
const diff = await context.getHeapSnapshotClassDiffs(request.params.baseFilePath, request.params.currentFilePath);
|
|
319
|
-
response.setHeapSnapshotClassDiffs(diff
|
|
364
|
+
response.setHeapSnapshotClassDiffs(diff, {
|
|
365
|
+
pageIdx: request.params.pageIdx,
|
|
366
|
+
pageSize: request.params.pageSize,
|
|
367
|
+
maxNameLength: request.params.maxNameLength,
|
|
368
|
+
});
|
|
320
369
|
}
|
|
321
370
|
},
|
|
322
371
|
}));
|
|
323
372
|
export const getHeapSnapshotDuplicateStrings = defineTool(() => ({
|
|
324
373
|
name: 'get_heapsnapshot_duplicate_strings',
|
|
325
|
-
description: 'Loads a memory heapsnapshot and returns duplicate strings grouped by their value.',
|
|
374
|
+
description: 'Loads and caches a memory heapsnapshot and returns duplicate strings grouped by their value.',
|
|
326
375
|
annotations: {
|
|
327
376
|
category: ToolCategory.MEMORY,
|
|
328
377
|
readOnlyHint: true,
|
|
@@ -334,20 +383,22 @@ export const getHeapSnapshotDuplicateStrings = defineTool(() => ({
|
|
|
334
383
|
},
|
|
335
384
|
schema: {
|
|
336
385
|
filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
|
|
337
|
-
pageIdx:
|
|
338
|
-
pageSize:
|
|
386
|
+
pageIdx: pageIdxSchema,
|
|
387
|
+
pageSize: pageSizeSchema,
|
|
388
|
+
maxNameLength: maxNameLengthSchema,
|
|
339
389
|
},
|
|
340
390
|
handler: async (request, response, context) => {
|
|
341
391
|
const duplicateStrings = await context.getHeapSnapshotDuplicateStrings(request.params.filePath);
|
|
342
392
|
response.setHeapSnapshotDuplicateStrings(duplicateStrings, {
|
|
343
393
|
pageIdx: request.params.pageIdx,
|
|
344
394
|
pageSize: request.params.pageSize,
|
|
395
|
+
maxNameLength: request.params.maxNameLength,
|
|
345
396
|
});
|
|
346
397
|
},
|
|
347
398
|
}));
|
|
348
399
|
export const getHeapSnapshotObjectDetails = defineTool(() => ({
|
|
349
400
|
name: 'get_heapsnapshot_object_details',
|
|
350
|
-
description: 'Loads a memory heapsnapshot and returns detailed information about a specific object by its node ID, including size, type, distance, and DOM detachedness.',
|
|
401
|
+
description: 'Loads and caches a memory heapsnapshot and returns detailed information about a specific object by its node ID, including size, type, distance, and DOM detachedness.',
|
|
351
402
|
annotations: {
|
|
352
403
|
category: ToolCategory.MEMORY,
|
|
353
404
|
readOnlyHint: true,
|
|
@@ -360,15 +411,18 @@ export const getHeapSnapshotObjectDetails = defineTool(() => ({
|
|
|
360
411
|
schema: {
|
|
361
412
|
filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
|
|
362
413
|
nodeId: zod.number().describe('The node ID to get object details for.'),
|
|
414
|
+
maxNameLength: maxNameLengthSchema,
|
|
363
415
|
},
|
|
364
416
|
handler: async (request, response, context) => {
|
|
365
417
|
const objectInfo = await context.getHeapSnapshotObjectDetails(request.params.filePath, request.params.nodeId);
|
|
366
|
-
response.setHeapSnapshotObjectDetails(objectInfo
|
|
418
|
+
response.setHeapSnapshotObjectDetails(objectInfo, {
|
|
419
|
+
maxNameLength: request.params.maxNameLength,
|
|
420
|
+
});
|
|
367
421
|
},
|
|
368
422
|
}));
|
|
369
423
|
export const queryHeapSnapshotObjects = defineTool(() => ({
|
|
370
424
|
name: 'query_heapsnapshot_objects',
|
|
371
|
-
description: 'Loads a memory heapsnapshot and queries objects matching specific filters (className, propertyName, nodeType, retainedSize, selfSize, isDetached, sortBy).',
|
|
425
|
+
description: 'Loads and caches a memory heapsnapshot and queries objects matching specific filters (className, propertyName, nodeType, retainedSize, selfSize, isDetached, sortBy).',
|
|
372
426
|
annotations: {
|
|
373
427
|
category: ToolCategory.MEMORY,
|
|
374
428
|
readOnlyHint: true,
|
|
@@ -400,8 +454,9 @@ export const queryHeapSnapshotObjects = defineTool(() => ({
|
|
|
400
454
|
.enum(['retainedSize', 'selfSize', 'id'])
|
|
401
455
|
.optional()
|
|
402
456
|
.describe('Sort order for results. Default is retainedSize.'),
|
|
403
|
-
pageIdx:
|
|
404
|
-
pageSize:
|
|
457
|
+
pageIdx: pageIdxSchema,
|
|
458
|
+
pageSize: pageSizeSchema,
|
|
459
|
+
maxNameLength: maxNameLengthSchema,
|
|
405
460
|
},
|
|
406
461
|
handler: async (request, response, context) => {
|
|
407
462
|
const range = await context.queryHeapSnapshotObjects(request.params.filePath, {
|
|
@@ -418,6 +473,52 @@ export const queryHeapSnapshotObjects = defineTool(() => ({
|
|
|
418
473
|
response.setHeapSnapshotNodes(range, {
|
|
419
474
|
pageIdx: request.params.pageIdx,
|
|
420
475
|
pageSize: request.params.pageSize,
|
|
476
|
+
maxNameLength: request.params.maxNameLength,
|
|
477
|
+
});
|
|
478
|
+
},
|
|
479
|
+
}));
|
|
480
|
+
export const analyzeHeapSnapshotContexts = defineTool(() => ({
|
|
481
|
+
name: 'analyze_heapsnapshot_contexts',
|
|
482
|
+
description: 'Loads and caches a memory heapsnapshot to identify and rank closure contexts holding dead captured fields—variables no remaining live closure can read. Scopes are ranked globally by the retained size of these dead values to provide a prioritizing heuristic, rather than an exact measure of reclaimable bytes.',
|
|
483
|
+
annotations: {
|
|
484
|
+
category: ToolCategory.MEMORY,
|
|
485
|
+
readOnlyHint: true,
|
|
486
|
+
conditions: ['memoryDebugging'],
|
|
487
|
+
},
|
|
488
|
+
blockedByDialog: false,
|
|
489
|
+
verifyFilesSchema: {
|
|
490
|
+
filePath: true,
|
|
491
|
+
},
|
|
492
|
+
schema: {
|
|
493
|
+
filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
|
|
494
|
+
retainedSize: byteSizeRangeSchema('Inclusive range for the dead-field score of a context (e.g. "10KB", "1MB-2MB", "-1MB", or "1MB-"). A single value is treated as a minimum.').optional(),
|
|
495
|
+
scopeInfoNodeId: zod
|
|
496
|
+
.number()
|
|
497
|
+
.int()
|
|
498
|
+
.optional()
|
|
499
|
+
.describe('Only return contexts declared by the scope with this ScopeInfo node id, as reported in the scope header of a previous call.'),
|
|
500
|
+
maxNameLength: maxNameLengthSchema,
|
|
501
|
+
pageIdx: zod
|
|
502
|
+
.number()
|
|
503
|
+
.int()
|
|
504
|
+
.nonnegative()
|
|
505
|
+
.optional()
|
|
506
|
+
.describe('The zero-based page index. Defaults to 0.'),
|
|
507
|
+
pageSize: zod
|
|
508
|
+
.number()
|
|
509
|
+
.int()
|
|
510
|
+
.positive()
|
|
511
|
+
.optional()
|
|
512
|
+
.describe('The number of contexts to return per page. Defaults to 20.'),
|
|
513
|
+
},
|
|
514
|
+
handler: async (request, response, context) => {
|
|
515
|
+
const analysis = await context.analyzeHeapSnapshotContexts(request.params.filePath);
|
|
516
|
+
response.setHeapSnapshotContextAnalysis(analysis, {
|
|
517
|
+
retainedSize: request.params.retainedSize,
|
|
518
|
+
scopeInfoNodeId: request.params.scopeInfoNodeId,
|
|
519
|
+
maxNameLength: request.params.maxNameLength,
|
|
520
|
+
pageIdx: request.params.pageIdx,
|
|
521
|
+
pageSize: request.params.pageSize,
|
|
421
522
|
});
|
|
422
523
|
},
|
|
423
524
|
}));
|
package/build/src/tools/pages.js
CHANGED
|
@@ -46,6 +46,7 @@ export const selectPage = defineTool((args) => ({
|
|
|
46
46
|
verifyFilesSchema: {},
|
|
47
47
|
handler: async (request, response, context) => {
|
|
48
48
|
const page = context.getPageById(request.params.pageId);
|
|
49
|
+
await page.init();
|
|
49
50
|
context.selectPage(page);
|
|
50
51
|
response.setIncludePages(true);
|
|
51
52
|
response.setListThirdPartyDeveloperTools();
|
|
@@ -113,6 +114,7 @@ export const newPage = defineTool((args) => {
|
|
|
113
114
|
validateUrl(request.params.url, {
|
|
114
115
|
javascriptEvaluation: args?.javascriptEvaluation,
|
|
115
116
|
categoryExtensions: args?.categoryExtensions,
|
|
117
|
+
fileNavigations: args?.fileNavigations,
|
|
116
118
|
});
|
|
117
119
|
const page = await context.newPage(request.params.background, request.params.isolatedContext);
|
|
118
120
|
await page.waitForEventsAfterAction(async () => {
|
|
@@ -174,6 +176,7 @@ export const navigatePage = definePageTool((args) => {
|
|
|
174
176
|
validateUrl(request.params.url, {
|
|
175
177
|
javascriptEvaluation: args?.javascriptEvaluation,
|
|
176
178
|
categoryExtensions: args?.categoryExtensions,
|
|
179
|
+
fileNavigations: args?.fileNavigations,
|
|
177
180
|
});
|
|
178
181
|
}
|
|
179
182
|
let initScriptId;
|
|
@@ -260,8 +263,8 @@ export const resizePage = definePageTool(() => ({
|
|
|
260
263
|
readOnlyHint: false,
|
|
261
264
|
},
|
|
262
265
|
schema: {
|
|
263
|
-
width: zod.number().describe('Page width'),
|
|
264
|
-
height: zod.number().describe('Page height'),
|
|
266
|
+
width: zod.number().int().positive().describe('Page width'),
|
|
267
|
+
height: zod.number().int().positive().describe('Page height'),
|
|
265
268
|
},
|
|
266
269
|
blockedByDialog: false,
|
|
267
270
|
verifyFilesSchema: {},
|
|
@@ -29,6 +29,10 @@ export const startTrace = definePageTool(() => ({
|
|
|
29
29
|
.boolean()
|
|
30
30
|
.default(true)
|
|
31
31
|
.describe('Determines if the trace recording should be automatically stopped.'),
|
|
32
|
+
ignoreCache: zod
|
|
33
|
+
.boolean()
|
|
34
|
+
.optional()
|
|
35
|
+
.describe('Whether to bypass the HTTP cache when reloading the page, to measure a cold page load. Only applies if reload is true.'),
|
|
32
36
|
filePath: filePathSchema,
|
|
33
37
|
},
|
|
34
38
|
blockedByDialog: true,
|
|
@@ -63,9 +67,22 @@ export const startTrace = definePageTool(() => ({
|
|
|
63
67
|
bufferSize: 1200 * 1000,
|
|
64
68
|
});
|
|
65
69
|
if (request.params.reload) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
const ignoreCache = request.params.ignoreCache ?? false;
|
|
71
|
+
if (ignoreCache) {
|
|
72
|
+
// Disable the HTTP cache so that the main document and all
|
|
73
|
+
// subresources are fetched from the network, like a hard reload.
|
|
74
|
+
await page.pptrPage.setCacheEnabled(false);
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
await page.pptrPage.goto(pageUrlForTracing, {
|
|
78
|
+
waitUntil: ['load'],
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
if (ignoreCache) {
|
|
83
|
+
await page.pptrPage.setCacheEnabled(true);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
69
86
|
}
|
|
70
87
|
if (request.params.autoStop) {
|
|
71
88
|
await new Promise(resolve => setTimeout(resolve, 5_000));
|
|
@@ -111,6 +128,7 @@ export const stopTrace = definePageTool(() => ({
|
|
|
111
128
|
},
|
|
112
129
|
handler: async (request, response, context) => {
|
|
113
130
|
if (!context.isRunningPerformanceTrace()) {
|
|
131
|
+
response.appendResponseLine('Error: no active performance trace recording to stop.');
|
|
114
132
|
return;
|
|
115
133
|
}
|
|
116
134
|
const page = request.page;
|
|
@@ -14,56 +14,92 @@ async function generateTempFilePath() {
|
|
|
14
14
|
return path.join(dir, `screencast.mp4`);
|
|
15
15
|
}
|
|
16
16
|
const supportedExtensions = ['.webm', '.mp4'];
|
|
17
|
+
/**
|
|
18
|
+
* Resolves the output extension for the legacy ffmpeg-based recorder.
|
|
19
|
+
*
|
|
20
|
+
* Matches the extension case-insensitively so e.g. `.WEBM` is recognized as
|
|
21
|
+
* WebM. An explicitly requested but unsupported extension is rejected rather
|
|
22
|
+
* than being silently rewritten to `.mp4` (which would change both the format
|
|
23
|
+
* and the output path from what was requested). A missing extension falls
|
|
24
|
+
* back to `.mp4`. The matched extension is normalized to lower case.
|
|
25
|
+
*/
|
|
26
|
+
function getLegacyExtension(filePath) {
|
|
27
|
+
const requestedExtension = path.extname(filePath);
|
|
28
|
+
const matchedExtension = supportedExtensions.find(supportedExtension => supportedExtension === requestedExtension.toLowerCase());
|
|
29
|
+
if (!matchedExtension && requestedExtension !== '') {
|
|
30
|
+
throw new Error(`Unsupported screencast file extension "${requestedExtension}". ` +
|
|
31
|
+
`Supported formats: ${supportedExtensions.join(', ')} (case-insensitive).`);
|
|
32
|
+
}
|
|
33
|
+
return matchedExtension ?? '.mp4';
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns the size of the page viewport in device pixels.
|
|
37
|
+
*/
|
|
38
|
+
async function getPagePixelSize(pptrPage) {
|
|
39
|
+
const { width, height, dpr } = await pptrPage.evaluate(() => ({
|
|
40
|
+
width: window.innerWidth,
|
|
41
|
+
height: window.innerHeight,
|
|
42
|
+
dpr: window.devicePixelRatio,
|
|
43
|
+
}));
|
|
44
|
+
return {
|
|
45
|
+
maxWidth: Math.max(1, Math.round(width * dpr)),
|
|
46
|
+
maxHeight: Math.max(1, Math.round(height * dpr)),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
17
49
|
export const startScreencast = definePageTool((args) => ({
|
|
18
50
|
name: 'screencast_start',
|
|
19
|
-
description: `Starts recording a screencast (video) of the target page
|
|
51
|
+
description: `Starts recording a screencast (video) of the target page.`,
|
|
20
52
|
annotations: {
|
|
21
53
|
category: ToolCategory.DEBUGGING,
|
|
22
54
|
readOnlyHint: false,
|
|
23
|
-
conditions: ['experimentalScreencast'],
|
|
24
55
|
},
|
|
25
56
|
schema: {
|
|
26
57
|
filePath: zod
|
|
27
58
|
.string()
|
|
28
59
|
.optional()
|
|
29
|
-
.describe(
|
|
60
|
+
.describe(args?.experimentalScreencast
|
|
61
|
+
? `Output file path (${supportedExtensions.join(',')} are supported). Uses mkdtemp to generate a unique path if not provided.`
|
|
62
|
+
: 'Output file path (.mp4). Uses mkdtemp to generate a unique path if not provided.'),
|
|
30
63
|
},
|
|
31
64
|
blockedByDialog: false,
|
|
32
65
|
verifyFilesSchema: {
|
|
33
66
|
filePath: true,
|
|
34
67
|
},
|
|
35
68
|
handler: async (request, response, context) => {
|
|
36
|
-
|
|
69
|
+
const page = request.page;
|
|
70
|
+
if (page.getScreenRecorder() !== null) {
|
|
37
71
|
response.appendResponseLine('Error: a screencast recording is already in progress. Use screencast_stop to stop it before starting a new one.');
|
|
38
72
|
return;
|
|
39
73
|
}
|
|
40
74
|
const requestedFilePath = request.params.filePath;
|
|
41
75
|
const filePath = requestedFilePath ?? (await generateTempFilePath());
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// lower case.
|
|
48
|
-
const requestedExtension = path.extname(filePath);
|
|
49
|
-
const matchedExtension = supportedExtensions.find(supportedExtension => supportedExtension === requestedExtension.toLowerCase());
|
|
50
|
-
if (!matchedExtension && requestedExtension !== '') {
|
|
51
|
-
throw new Error(`Unsupported screencast file extension "${requestedExtension}". ` +
|
|
52
|
-
`Supported formats: ${supportedExtensions.join(', ')} (case-insensitive).`);
|
|
53
|
-
}
|
|
54
|
-
const enforcedExtension = matchedExtension ?? '.mp4';
|
|
55
|
-
const format = (matchedExtension?.substring(1) ??
|
|
56
|
-
'mp4');
|
|
57
|
-
const resolvedPath = await context.ensureExtension(filePath, enforcedExtension);
|
|
58
|
-
const page = request.page;
|
|
76
|
+
// The built-in Chrome recorder (page.record) always produces mp4. The
|
|
77
|
+
// legacy ffmpeg recorder (page.screencast) also supports WebM.
|
|
78
|
+
const useLegacy = Boolean(args?.experimentalScreencast);
|
|
79
|
+
const extension = useLegacy ? getLegacyExtension(filePath) : '.mp4';
|
|
80
|
+
const resolvedPath = await context.ensureExtension(filePath, extension);
|
|
59
81
|
let recorder;
|
|
60
82
|
try {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
83
|
+
if (useLegacy) {
|
|
84
|
+
const format = extension === '.webm' ? 'webm' : 'mp4';
|
|
85
|
+
recorder = await page.pptrPage.screencast({
|
|
86
|
+
path: resolvedPath,
|
|
87
|
+
format,
|
|
88
|
+
ffmpegPath: args?.experimentalFfmpegPath,
|
|
89
|
+
fps: args?.screencastFps,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// Without explicit limits Chrome downscales frames to a small default
|
|
94
|
+
// size. Record at the actual device pixel size of the page instead.
|
|
95
|
+
const { maxWidth, maxHeight } = await getPagePixelSize(page.pptrPage);
|
|
96
|
+
recorder = await page.pptrPage.record({
|
|
97
|
+
path: resolvedPath,
|
|
98
|
+
fps: args?.screencastFps,
|
|
99
|
+
maxWidth,
|
|
100
|
+
maxHeight,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
67
103
|
}
|
|
68
104
|
catch (err) {
|
|
69
105
|
// If we generated a temporary directory for this recording, remove it so
|
|
@@ -84,9 +120,12 @@ export const startScreencast = definePageTool((args) => ({
|
|
|
84
120
|
throw new Error('ffmpeg is required for screencast recording but was not found. ' +
|
|
85
121
|
'Install ffmpeg (https://ffmpeg.org/) and ensure it is available in your PATH.');
|
|
86
122
|
}
|
|
123
|
+
if (message.includes('Page.startScreenRecording')) {
|
|
124
|
+
throw new Error('The connected Chrome does not support screen recording. Update Chrome to a newer version.');
|
|
125
|
+
}
|
|
87
126
|
throw err;
|
|
88
127
|
}
|
|
89
|
-
|
|
128
|
+
page.setScreenRecorder({ recorder, filePath: resolvedPath });
|
|
90
129
|
response.appendResponseLine(`Screencast recording started. The recording will be saved to ${resolvedPath}. Use ${stopScreencast(args).name} to stop recording.`);
|
|
91
130
|
},
|
|
92
131
|
}));
|
|
@@ -96,13 +135,13 @@ export const stopScreencast = definePageTool(() => ({
|
|
|
96
135
|
annotations: {
|
|
97
136
|
category: ToolCategory.DEBUGGING,
|
|
98
137
|
readOnlyHint: false,
|
|
99
|
-
conditions: ['experimentalScreencast'],
|
|
100
138
|
},
|
|
101
139
|
schema: {},
|
|
102
140
|
blockedByDialog: false,
|
|
103
141
|
verifyFilesSchema: {},
|
|
104
|
-
handler: async (
|
|
105
|
-
const
|
|
142
|
+
handler: async (request, response) => {
|
|
143
|
+
const page = request.page;
|
|
144
|
+
const data = page.getScreenRecorder();
|
|
106
145
|
if (!data) {
|
|
107
146
|
response.appendResponseLine('Error: no active screencast recording to stop.');
|
|
108
147
|
return;
|
|
@@ -112,7 +151,7 @@ export const stopScreencast = definePageTool(() => ({
|
|
|
112
151
|
response.appendResponseLine(`The screencast recording has been stopped and saved to ${data.filePath}.`);
|
|
113
152
|
}
|
|
114
153
|
finally {
|
|
115
|
-
|
|
154
|
+
page.setScreenRecorder(null);
|
|
116
155
|
}
|
|
117
156
|
},
|
|
118
157
|
}));
|