chrome-devtools-mcp 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/build/src/HeapSnapshotManager.js +23 -13
- package/build/src/McpContext.js +174 -365
- package/build/src/McpPage.js +242 -31
- package/build/src/McpResponse.js +113 -67
- package/build/src/PageCollector.js +48 -122
- package/build/src/TextSnapshot.js +20 -2
- package/build/src/ToolHandler.js +13 -3
- package/build/src/WaitForHelper.js +18 -8
- package/build/src/bin/chrome-devtools-cli-options.js +25 -1
- package/build/src/bin/chrome-devtools-mcp-cli-options.js +15 -6
- package/build/src/bin/chrome-devtools-mcp-main.js +2 -2
- package/build/src/browser.js +1 -1
- package/build/src/daemon/client.js +33 -3
- package/build/src/daemon/daemon.js +2 -1
- package/build/src/daemon/utils.js +1 -1
- package/build/src/devtools/DevtoolsUtils.js +2 -63
- package/build/src/{issue-descriptions.js → devtools/issueDescriptions.js} +2 -2
- package/build/src/formatters/IssueFormatter.js +2 -2
- package/build/src/index.js +12 -3
- package/build/src/telemetry/ClearcutLogger.js +1 -1
- package/build/src/telemetry/WatchdogClient.js +1 -1
- package/build/src/telemetry/metricsRegistry.js +2 -9
- package/build/src/telemetry/persistence.js +1 -1
- package/build/src/telemetry/transformation.js +20 -0
- package/build/src/telemetry/watchdog/ClearcutSender.js +1 -1
- package/build/src/telemetry/watchdog/main.js +1 -1
- package/build/src/third_party/THIRD_PARTY_NOTICES +13 -249
- package/build/src/third_party/bundled-packages.json +2 -3
- package/build/src/third_party/index.js +1527 -1514
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +3082 -6343
- package/build/src/tools/emulation.js +2 -2
- package/build/src/tools/extensions.js +1 -1
- package/build/src/tools/input.js +17 -8
- package/build/src/tools/lighthouse.js +1 -1
- package/build/src/tools/memory.js +16 -2
- package/build/src/tools/network.js +4 -4
- package/build/src/tools/pages.js +21 -89
- package/build/src/tools/performance.js +2 -2
- package/build/src/tools/script.js +3 -0
- package/build/src/tools/snapshot.js +2 -2
- package/build/src/tools/thirdPartyDeveloper.js +1 -1
- package/build/src/tools/webmcp.js +1 -1
- package/build/src/trace-processing/parse.js +1 -1
- package/build/src/{logger.js → utils/logger.js} +1 -1
- package/build/src/{polyfill.js → utils/polyfill.js} +1 -1
- package/build/src/version.js +1 -1
- package/package.json +9 -5
- package/skills/memory-leak-debugging/SKILL.md +22 -14
- package/build/src/utils/types.js +0 -7
- /package/build/src/{Mutex.js → utils/Mutex.js} +0 -0
|
@@ -75,9 +75,9 @@ export const emulate = definePageTool({
|
|
|
75
75
|
},
|
|
76
76
|
blockedByDialog: true,
|
|
77
77
|
verifyFilesSchema: [],
|
|
78
|
-
handler: async (request, response
|
|
78
|
+
handler: async (request, response) => {
|
|
79
79
|
const page = request.page;
|
|
80
|
-
await
|
|
80
|
+
await page.emulate(request.params);
|
|
81
81
|
response.appendResponseLine('Emulation configured successfully');
|
|
82
82
|
},
|
|
83
83
|
});
|
package/build/src/tools/input.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { logger } from '../logger.js';
|
|
7
6
|
import { zod } from '../third_party/index.js';
|
|
8
7
|
import { parseKey } from '../utils/keyboard.js';
|
|
8
|
+
import { logger } from '../utils/logger.js';
|
|
9
9
|
import { ToolCategory } from './categories.js';
|
|
10
10
|
import { definePageTool } from './ToolDefinition.js';
|
|
11
11
|
const dblClickSchema = zod
|
|
@@ -219,7 +219,7 @@ function hasOptionChildren(aXNode) {
|
|
|
219
219
|
async function fillFormElement(uid, value, context, page) {
|
|
220
220
|
const handle = await page.getElementByUid(uid);
|
|
221
221
|
try {
|
|
222
|
-
const aXNode =
|
|
222
|
+
const aXNode = page.getAXNodeByUid(uid);
|
|
223
223
|
// We assume that combobox needs to be handled as select if it has
|
|
224
224
|
// role='combobox' and option children.
|
|
225
225
|
if (aXNode && aXNode.role === 'combobox' && hasOptionChildren(aXNode)) {
|
|
@@ -399,7 +399,7 @@ export const uploadFile = definePageTool({
|
|
|
399
399
|
},
|
|
400
400
|
blockedByDialog: true,
|
|
401
401
|
verifyFilesSchema: ['filePath'],
|
|
402
|
-
handler: async (request, response
|
|
402
|
+
handler: async (request, response) => {
|
|
403
403
|
const { uid, filePath } = request.params;
|
|
404
404
|
const handle = (await request.page.getElementByUid(uid));
|
|
405
405
|
try {
|
|
@@ -451,12 +451,21 @@ export const pressKey = definePageTool({
|
|
|
451
451
|
const tokens = parseKey(request.params.key);
|
|
452
452
|
const [key, ...modifiers] = tokens;
|
|
453
453
|
const result = await page.waitForEventsAfterAction(async () => {
|
|
454
|
-
|
|
455
|
-
|
|
454
|
+
const heldModifiers = [];
|
|
455
|
+
try {
|
|
456
|
+
for (const modifier of modifiers) {
|
|
457
|
+
await page.pptrPage.keyboard.down(modifier);
|
|
458
|
+
heldModifiers.push(modifier);
|
|
459
|
+
}
|
|
460
|
+
await page.pptrPage.keyboard.press(key);
|
|
456
461
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
462
|
+
finally {
|
|
463
|
+
// Release every modifier that was successfully pressed, even if a
|
|
464
|
+
// later key event throws. Otherwise a failed press leaves modifiers
|
|
465
|
+
// logically held down in the browser (see #2309).
|
|
466
|
+
for (const modifier of heldModifiers.toReversed()) {
|
|
467
|
+
await page.pptrPage.keyboard.up(modifier);
|
|
468
|
+
}
|
|
460
469
|
}
|
|
461
470
|
});
|
|
462
471
|
response.appendResponseLine(`Successfully pressed key: ${request.params.key}`);
|
|
@@ -6,6 +6,12 @@
|
|
|
6
6
|
import { zod } from '../third_party/index.js';
|
|
7
7
|
import { ToolCategory } from './categories.js';
|
|
8
8
|
import { definePageTool, defineTool } from './ToolDefinition.js';
|
|
9
|
+
const HEAP_SNAPSHOT_FILTERS = [
|
|
10
|
+
'objectsRetainedByDetachedDomNodes',
|
|
11
|
+
'objectsRetainedByConsole',
|
|
12
|
+
'objectsRetainedByEventHandlers',
|
|
13
|
+
'objectsRetainedByContexts',
|
|
14
|
+
];
|
|
9
15
|
export const takeHeapSnapshot = definePageTool({
|
|
10
16
|
name: 'take_heapsnapshot',
|
|
11
17
|
description: `Capture a heap snapshot of the currently selected page. Use to analyze the memory distribution of JavaScript objects and debug memory leaks.`,
|
|
@@ -58,6 +64,10 @@ export const getHeapSnapshotDetails = defineTool({
|
|
|
58
64
|
},
|
|
59
65
|
schema: {
|
|
60
66
|
filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
|
|
67
|
+
filterName: zod
|
|
68
|
+
.enum(HEAP_SNAPSHOT_FILTERS)
|
|
69
|
+
.optional()
|
|
70
|
+
.describe('An optional filter to apply to the aggregates.'),
|
|
61
71
|
pageIdx: zod
|
|
62
72
|
.number()
|
|
63
73
|
.optional()
|
|
@@ -70,7 +80,7 @@ export const getHeapSnapshotDetails = defineTool({
|
|
|
70
80
|
blockedByDialog: false,
|
|
71
81
|
verifyFilesSchema: ['filePath'],
|
|
72
82
|
handler: async (request, response, context) => {
|
|
73
|
-
const aggregates = await context.getHeapSnapshotAggregates(request.params.filePath);
|
|
83
|
+
const aggregates = await context.getHeapSnapshotAggregates(request.params.filePath, request.params.filterName);
|
|
74
84
|
response.setHeapSnapshotAggregates(aggregates, {
|
|
75
85
|
pageIdx: request.params.pageIdx,
|
|
76
86
|
pageSize: request.params.pageSize,
|
|
@@ -88,13 +98,17 @@ export const getHeapSnapshotClassNodes = defineTool({
|
|
|
88
98
|
schema: {
|
|
89
99
|
filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
|
|
90
100
|
id: zod.number().describe('The ID for the class, obtained from details.'),
|
|
101
|
+
filterName: zod
|
|
102
|
+
.enum(HEAP_SNAPSHOT_FILTERS)
|
|
103
|
+
.optional()
|
|
104
|
+
.describe('An optional filter to apply to the nodes.'),
|
|
91
105
|
pageIdx: zod.number().optional().describe('The page index for pagination.'),
|
|
92
106
|
pageSize: zod.number().optional().describe('The page size for pagination.'),
|
|
93
107
|
},
|
|
94
108
|
blockedByDialog: false,
|
|
95
109
|
verifyFilesSchema: ['filePath'],
|
|
96
110
|
handler: async (request, response, context) => {
|
|
97
|
-
const nodes = await context.getHeapSnapshotNodesById(request.params.filePath, request.params.id);
|
|
111
|
+
const nodes = await context.getHeapSnapshotNodesById(request.params.filePath, request.params.id, request.params.filterName);
|
|
98
112
|
response.setHeapSnapshotNodes(nodes, {
|
|
99
113
|
pageIdx: request.params.pageIdx,
|
|
100
114
|
pageSize: request.params.pageSize,
|
|
@@ -59,11 +59,11 @@ export const listNetworkRequests = definePageTool({
|
|
|
59
59
|
},
|
|
60
60
|
blockedByDialog: false,
|
|
61
61
|
verifyFilesSchema: [],
|
|
62
|
-
handler: async (request, response
|
|
62
|
+
handler: async (request, response) => {
|
|
63
63
|
const data = await request.page.getDevToolsData();
|
|
64
64
|
response.attachDevToolsData(data);
|
|
65
65
|
const reqid = data?.cdpRequestId
|
|
66
|
-
?
|
|
66
|
+
? request.page.resolveCdpRequestId(data.cdpRequestId)
|
|
67
67
|
: undefined;
|
|
68
68
|
response.setIncludeNetworkRequests(true, {
|
|
69
69
|
pageSize: request.params.pageSize,
|
|
@@ -97,7 +97,7 @@ export const getNetworkRequest = definePageTool({
|
|
|
97
97
|
},
|
|
98
98
|
blockedByDialog: true,
|
|
99
99
|
verifyFilesSchema: ['requestFilePath', 'responseFilePath'],
|
|
100
|
-
handler: async (request, response
|
|
100
|
+
handler: async (request, response) => {
|
|
101
101
|
if (request.params.reqid) {
|
|
102
102
|
response.attachNetworkRequest(request.params.reqid, {
|
|
103
103
|
requestFilePath: request.params.requestFilePath,
|
|
@@ -108,7 +108,7 @@ export const getNetworkRequest = definePageTool({
|
|
|
108
108
|
const data = await request.page.getDevToolsData();
|
|
109
109
|
response.attachDevToolsData(data);
|
|
110
110
|
const reqid = data?.cdpRequestId
|
|
111
|
-
?
|
|
111
|
+
? request.page.resolveCdpRequestId(data.cdpRequestId)
|
|
112
112
|
: undefined;
|
|
113
113
|
if (reqid) {
|
|
114
114
|
response.attachNetworkRequest(reqid, {
|
package/build/src/tools/pages.js
CHANGED
|
@@ -3,55 +3,10 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { logger } from '../logger.js';
|
|
7
6
|
import { zod } from '../third_party/index.js';
|
|
7
|
+
import { logger } from '../utils/logger.js';
|
|
8
8
|
import { ToolCategory } from './categories.js';
|
|
9
9
|
import { CLOSE_PAGE_ERROR, definePageTool, defineTool, timeoutSchema, } from './ToolDefinition.js';
|
|
10
|
-
async function navigateWithInterception(page, action, allowListString, timeout) {
|
|
11
|
-
const allowList = allowListString
|
|
12
|
-
? allowListString.split(',').map((p) => new URLPattern(p.trim()))
|
|
13
|
-
: undefined;
|
|
14
|
-
const requestHandler = (interceptedRequest) => {
|
|
15
|
-
if (!interceptedRequest.isNavigationRequest()) {
|
|
16
|
-
void interceptedRequest.continue();
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const requestUrl = interceptedRequest.url();
|
|
20
|
-
const isAllowed = allowList.some((pattern) => pattern.test(requestUrl));
|
|
21
|
-
if (isAllowed) {
|
|
22
|
-
void interceptedRequest.continue();
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
logger?.(`Blocking request to: ${requestUrl}`);
|
|
26
|
-
void interceptedRequest.abort('blockedbyclient');
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
const cleanupInterception = async () => {
|
|
30
|
-
if (allowList) {
|
|
31
|
-
page.pptrPage.off('request', requestHandler);
|
|
32
|
-
await page.pptrPage.setRequestInterception(false).catch(error => {
|
|
33
|
-
logger?.(`Failed to disable request interception`, error);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
if (allowList) {
|
|
38
|
-
await page.pptrPage.setRequestInterception(true);
|
|
39
|
-
page.pptrPage.on('request', requestHandler);
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
await page.waitForEventsAfterAction(async () => {
|
|
43
|
-
try {
|
|
44
|
-
await action();
|
|
45
|
-
}
|
|
46
|
-
finally {
|
|
47
|
-
await cleanupInterception();
|
|
48
|
-
}
|
|
49
|
-
}, { timeout });
|
|
50
|
-
}
|
|
51
|
-
finally {
|
|
52
|
-
await cleanupInterception();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
10
|
export const listPages = defineTool(args => {
|
|
56
11
|
return {
|
|
57
12
|
name: 'list_pages',
|
|
@@ -129,7 +84,7 @@ export const closePage = defineTool({
|
|
|
129
84
|
response.setListThirdPartyDeveloperTools();
|
|
130
85
|
},
|
|
131
86
|
});
|
|
132
|
-
export const newPage = defineTool(
|
|
87
|
+
export const newPage = defineTool(() => {
|
|
133
88
|
return {
|
|
134
89
|
name: 'new_page',
|
|
135
90
|
description: `Open a new tab and load a URL. Use project URL if not specified otherwise.`,
|
|
@@ -149,29 +104,23 @@ export const newPage = defineTool(args => {
|
|
|
149
104
|
.describe('If specified, the page is created in an isolated browser context with the given name. ' +
|
|
150
105
|
'Pages in the same browser context share cookies and storage. ' +
|
|
151
106
|
'Pages in different browser contexts are fully isolated.'),
|
|
152
|
-
...(args?.experimentalNavigationAllowlist
|
|
153
|
-
? {
|
|
154
|
-
allowList: zod
|
|
155
|
-
.string()
|
|
156
|
-
.optional()
|
|
157
|
-
.describe('Optional comma-separated list of URL patterns to allow. If provided, all other navigations will be blocked.'),
|
|
158
|
-
}
|
|
159
|
-
: {}),
|
|
160
107
|
...timeoutSchema,
|
|
161
108
|
},
|
|
162
109
|
blockedByDialog: false,
|
|
163
110
|
verifyFilesSchema: [],
|
|
164
111
|
handler: async (request, response, context) => {
|
|
165
112
|
const page = await context.newPage(request.params.background, request.params.isolatedContext);
|
|
166
|
-
await
|
|
167
|
-
|
|
168
|
-
|
|
113
|
+
await page.waitForEventsAfterAction(async () => {
|
|
114
|
+
await page.pptrPage.goto(request.params.url, {
|
|
115
|
+
timeout: request.params.timeout,
|
|
116
|
+
});
|
|
117
|
+
}, { timeout: request.params.timeout });
|
|
169
118
|
response.setIncludePages(true);
|
|
170
119
|
response.setListThirdPartyDeveloperTools();
|
|
171
120
|
},
|
|
172
121
|
};
|
|
173
122
|
});
|
|
174
|
-
export const navigatePage = definePageTool(
|
|
123
|
+
export const navigatePage = definePageTool(() => {
|
|
175
124
|
return {
|
|
176
125
|
name: 'navigate_page',
|
|
177
126
|
description: `Go to a URL, or back, forward, or reload. Use project URL if not specified otherwise.`,
|
|
@@ -190,21 +139,13 @@ export const navigatePage = definePageTool(args => {
|
|
|
190
139
|
.optional()
|
|
191
140
|
.describe('Whether to ignore cache on reload.'),
|
|
192
141
|
handleBeforeUnload: zod
|
|
193
|
-
.enum(['accept', '
|
|
142
|
+
.enum(['accept', 'dismiss'])
|
|
194
143
|
.optional()
|
|
195
144
|
.describe('Whether to auto accept or beforeunload dialogs triggered by this navigation. Default is accept.'),
|
|
196
145
|
initScript: zod
|
|
197
146
|
.string()
|
|
198
147
|
.optional()
|
|
199
148
|
.describe('A JavaScript script to be executed on each new document before any other scripts for the next navigation.'),
|
|
200
|
-
...(args?.experimentalNavigationAllowlist
|
|
201
|
-
? {
|
|
202
|
-
allowList: zod
|
|
203
|
-
.string()
|
|
204
|
-
.optional()
|
|
205
|
-
.describe('Optional comma-separated list of URL patterns to allow. If provided, all other navigations will be blocked.'),
|
|
206
|
-
}
|
|
207
|
-
: {}),
|
|
208
149
|
...timeoutSchema,
|
|
209
150
|
},
|
|
210
151
|
blockedByDialog: false,
|
|
@@ -220,29 +161,14 @@ export const navigatePage = definePageTool(args => {
|
|
|
220
161
|
if (!request.params.type) {
|
|
221
162
|
request.params.type = 'url';
|
|
222
163
|
}
|
|
223
|
-
const handleBeforeUnload = request.params.handleBeforeUnload ?? 'accept';
|
|
224
|
-
const dialogHandler = (dialog) => {
|
|
225
|
-
if (dialog.type() === 'beforeunload') {
|
|
226
|
-
if (handleBeforeUnload === 'accept') {
|
|
227
|
-
response.appendResponseLine(`Accepted a beforeunload dialog.`);
|
|
228
|
-
void dialog.accept();
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
response.appendResponseLine(`Declined a beforeunload dialog.`);
|
|
232
|
-
void dialog.dismiss();
|
|
233
|
-
}
|
|
234
|
-
// We are not going to report the dialog like regular dialogs.
|
|
235
|
-
page.clearDialog();
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
164
|
let initScriptId;
|
|
239
165
|
if (request.params.initScript) {
|
|
240
166
|
const { identifier } = await page.pptrPage.evaluateOnNewDocument(request.params.initScript);
|
|
241
167
|
initScriptId = identifier;
|
|
242
168
|
}
|
|
243
|
-
page.pptrPage.on('dialog', dialogHandler);
|
|
244
169
|
try {
|
|
245
|
-
|
|
170
|
+
const action = request.params.handleBeforeUnload ?? 'accept';
|
|
171
|
+
const result = await page.waitForEventsAfterAction(async () => {
|
|
246
172
|
switch (request.params.type) {
|
|
247
173
|
case 'url':
|
|
248
174
|
if (!request.params.url) {
|
|
@@ -287,10 +213,16 @@ export const navigatePage = definePageTool(args => {
|
|
|
287
213
|
}
|
|
288
214
|
break;
|
|
289
215
|
}
|
|
290
|
-
},
|
|
216
|
+
}, {
|
|
217
|
+
timeout: request.params.timeout,
|
|
218
|
+
handleDialog: { beforeunload: action },
|
|
219
|
+
});
|
|
220
|
+
if (result.dialogHandled) {
|
|
221
|
+
response.appendResponseLine(`${action === 'dismiss' ? 'Dismissed' : 'Accepted'} a beforeunload dialog.`);
|
|
222
|
+
page.clearDialog();
|
|
223
|
+
}
|
|
291
224
|
}
|
|
292
225
|
finally {
|
|
293
|
-
page.pptrPage.off('dialog', dialogHandler);
|
|
294
226
|
if (initScriptId) {
|
|
295
227
|
await page.pptrPage
|
|
296
228
|
.removeScriptToEvaluateOnNewDocument(initScriptId)
|
|
@@ -318,7 +250,7 @@ export const resizePage = definePageTool({
|
|
|
318
250
|
},
|
|
319
251
|
blockedByDialog: false,
|
|
320
252
|
verifyFilesSchema: [],
|
|
321
|
-
handler: async (request, response
|
|
253
|
+
handler: async (request, response) => {
|
|
322
254
|
const page = request.page;
|
|
323
255
|
try {
|
|
324
256
|
const browser = page.pptrPage.browser();
|
|
@@ -361,7 +293,7 @@ export const handleDialog = definePageTool({
|
|
|
361
293
|
},
|
|
362
294
|
blockedByDialog: false,
|
|
363
295
|
verifyFilesSchema: [],
|
|
364
|
-
handler: async (request, response
|
|
296
|
+
handler: async (request, response) => {
|
|
365
297
|
const page = request.page;
|
|
366
298
|
const dialog = page.getDialog();
|
|
367
299
|
if (!dialog) {
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import zlib from 'node:zlib';
|
|
7
|
-
import { logger } from '../logger.js';
|
|
8
7
|
import { zod, DevTools } from '../third_party/index.js';
|
|
9
8
|
import { parseRawTraceBuffer, traceResultIsSuccess, } from '../trace-processing/parse.js';
|
|
9
|
+
import { logger } from '../utils/logger.js';
|
|
10
10
|
import { ToolCategory } from './categories.js';
|
|
11
11
|
import { definePageTool } from './ToolDefinition.js';
|
|
12
12
|
const filePathSchema = zod
|
|
@@ -148,7 +148,7 @@ async function stopTracingAndAppendOutput(page, response, context, filePath) {
|
|
|
148
148
|
});
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
|
-
const file = await context.saveFile(dataToWrite, filePath, filePath.endsWith('.gz') ? '.
|
|
151
|
+
const file = await context.saveFile(dataToWrite, filePath, filePath.endsWith('.gz') ? '.gz' : '.json');
|
|
152
152
|
response.appendResponseLine(`The raw trace data was saved to ${file.filename}.`);
|
|
153
153
|
}
|
|
154
154
|
const result = await parseRawTraceBuffer(traceEventsBuffer, {
|
|
@@ -63,6 +63,9 @@ Example with arguments: \`(el) => el.innerText\`
|
|
|
63
63
|
context,
|
|
64
64
|
});
|
|
65
65
|
}, { handleDialog: dialogAction ?? 'accept' });
|
|
66
|
+
if (result.dialogHandled) {
|
|
67
|
+
context.getSelectedMcpPage().clearDialog();
|
|
68
|
+
}
|
|
66
69
|
response.attachWaitForResult(result);
|
|
67
70
|
return;
|
|
68
71
|
}
|
|
@@ -51,9 +51,9 @@ export const waitFor = definePageTool({
|
|
|
51
51
|
},
|
|
52
52
|
blockedByDialog: true,
|
|
53
53
|
verifyFilesSchema: [],
|
|
54
|
-
handler: async (request, response
|
|
54
|
+
handler: async (request, response) => {
|
|
55
55
|
const page = request.page;
|
|
56
|
-
await
|
|
56
|
+
await page.waitForTextOnPage(request.params.text, request.params.timeout);
|
|
57
57
|
response.appendResponseLine(`Element matching one of ${JSON.stringify(request.params.text)} found.`);
|
|
58
58
|
response.includeSnapshot();
|
|
59
59
|
},
|
|
@@ -22,7 +22,7 @@ third-party developer tools with additional functionality.`,
|
|
|
22
22
|
schema: {},
|
|
23
23
|
blockedByDialog: false,
|
|
24
24
|
verifyFilesSchema: [],
|
|
25
|
-
handler: async (_request, response
|
|
25
|
+
handler: async (_request, response) => {
|
|
26
26
|
response.setListThirdPartyDeveloperTools();
|
|
27
27
|
},
|
|
28
28
|
});
|
|
@@ -16,7 +16,7 @@ export const listWebMcpTools = definePageTool({
|
|
|
16
16
|
schema: {},
|
|
17
17
|
blockedByDialog: false,
|
|
18
18
|
verifyFilesSchema: [],
|
|
19
|
-
handler: async (_request, response
|
|
19
|
+
handler: async (_request, response) => {
|
|
20
20
|
response.setListWebMcpTools();
|
|
21
21
|
},
|
|
22
22
|
});
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { logger } from '../logger.js';
|
|
7
6
|
import { DevTools } from '../third_party/index.js';
|
|
7
|
+
import { logger } from '../utils/logger.js';
|
|
8
8
|
const engine = DevTools.TraceEngine.TraceModel.Model.createWithAllHandlers();
|
|
9
9
|
export function traceResultIsSuccess(x) {
|
|
10
10
|
return 'parsedTrace' in x;
|
package/build/src/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chrome-devtools-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "MCP server for Chrome DevTools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -55,12 +55,13 @@
|
|
|
55
55
|
"@rollup/plugin-json": "^6.1.0",
|
|
56
56
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
57
57
|
"@stylistic/eslint-plugin": "^5.4.0",
|
|
58
|
+
"@blackwell-systems/gcf": "^2.2.2",
|
|
58
59
|
"@toon-format/toon": "^2.2.0",
|
|
59
60
|
"@types/debug": "^4.1.12",
|
|
60
61
|
"@types/filesystem": "^0.0.36",
|
|
61
62
|
"@types/node": "^26.0.0",
|
|
62
63
|
"@types/semver": "^7.7.1",
|
|
63
|
-
"@types/sinon": "^
|
|
64
|
+
"@types/sinon": "^22.0.0",
|
|
64
65
|
"@types/yargs": "^17.0.33",
|
|
65
66
|
"@typescript-eslint/eslint-plugin": "^8.43.0",
|
|
66
67
|
"@typescript-eslint/parser": "^8.43.0",
|
|
@@ -73,7 +74,7 @@
|
|
|
73
74
|
"globals": "^17.0.0",
|
|
74
75
|
"lighthouse": "13.4.0",
|
|
75
76
|
"prettier": "^3.6.2",
|
|
76
|
-
"puppeteer": "25.
|
|
77
|
+
"puppeteer": "25.3.0",
|
|
77
78
|
"rollup": "4.62.2",
|
|
78
79
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
79
80
|
"rollup-plugin-license": "^3.6.0",
|
|
@@ -81,15 +82,18 @@
|
|
|
81
82
|
"sinon": "^22.0.0",
|
|
82
83
|
"typescript": "^6.0.2",
|
|
83
84
|
"typescript-eslint": "^8.43.0",
|
|
84
|
-
"urlpattern-polyfill": "^10.1.0",
|
|
85
85
|
"yargs": "18.0.0"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
|
-
"@toon-format/toon": "^2.2.0"
|
|
88
|
+
"@toon-format/toon": "^2.2.0",
|
|
89
|
+
"@blackwell-systems/gcf": "^2.2.2"
|
|
89
90
|
},
|
|
90
91
|
"peerDependenciesMeta": {
|
|
91
92
|
"@toon-format/toon": {
|
|
92
93
|
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"@blackwell-systems/gcf": {
|
|
96
|
+
"optional": true
|
|
93
97
|
}
|
|
94
98
|
},
|
|
95
99
|
"engines": {
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: memory-leak-debugging
|
|
3
|
-
description: Diagnoses and resolves memory leaks in JavaScript/Node.js applications. Use when a user reports high memory usage, OOM errors, or wants to
|
|
3
|
+
description: Diagnoses and resolves memory leaks in JavaScript/Node.js applications. Use when a user reports high memory usage, OOM errors, or wants to capture, compare, or inspect heap snapshots with Chrome DevTools MCP memory tools.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Memory Leak Debugging
|
|
7
7
|
|
|
8
|
-
This skill provides expert guidance and workflows for finding, diagnosing, and fixing memory leaks in JavaScript and Node.js applications.
|
|
8
|
+
This skill provides expert guidance and workflows for finding, diagnosing, and fixing memory leaks in JavaScript and Node.js applications using Chrome DevTools MCP.
|
|
9
9
|
|
|
10
10
|
## Core Principles
|
|
11
11
|
|
|
12
|
-
- **Prefer
|
|
12
|
+
- **Prefer MCP memory tools:** Do NOT attempt to read raw `.heapsnapshot` files directly, as they are extremely large and will consume too many tokens. Use the Chrome DevTools MCP heap snapshot tools to summarize, compare, and inspect snapshots.
|
|
13
13
|
- **Isolate the Leak:** Determine if the leak is in the browser (client-side) or Node.js (server-side).
|
|
14
14
|
- **Common Culprits:** Look for detached DOM nodes, unhandled closures, global variables, event listeners not being removed, and caches growing unbounded. _Note: Detached DOM nodes are sometimes intentional caches; always ask the user before nulling them._
|
|
15
|
+
- **Close Loaded Snapshots:** Heap snapshots can be large. After completing an investigation, use `close_heapsnapshot` for each loaded snapshot to release memory held by the MCP server.
|
|
15
16
|
|
|
16
17
|
## Workflows
|
|
17
18
|
|
|
@@ -24,27 +25,34 @@ When investigating a frontend web application memory leak, utilize the `chrome-d
|
|
|
24
25
|
- Repeat the same user interactions 10 times to amplify the leak.
|
|
25
26
|
- Use `take_heapsnapshot` to save `.heapsnapshot` files to disk at baseline, target (after actions), and final (after reverting actions) states.
|
|
26
27
|
|
|
27
|
-
### 2.
|
|
28
|
+
### 2. Comparing Snapshots
|
|
28
29
|
|
|
29
|
-
Once you have generated `.heapsnapshot` files using `take_heapsnapshot`,
|
|
30
|
+
Once you have generated `.heapsnapshot` files using `take_heapsnapshot`, compare them with Chrome DevTools MCP memory tools.
|
|
30
31
|
|
|
31
|
-
-
|
|
32
|
-
-
|
|
32
|
+
- Start with `get_heapsnapshot_summary` for each snapshot to confirm that the files load and to compare high-level totals.
|
|
33
|
+
- Use `compare_heapsnapshots` to compare baseline and target snapshots. Start without `classIndex` for the summary diff, then request detailed class diffs only for suspicious growth.
|
|
34
|
+
- Use the summary output from `compare_heapsnapshots` before drilling into specific node IDs.
|
|
33
35
|
|
|
34
|
-
### 3.
|
|
36
|
+
### 3. Inspecting Retainers
|
|
35
37
|
|
|
36
|
-
When
|
|
38
|
+
When a class or object type grows unexpectedly, inspect the retaining chain with the MCP tools before changing code.
|
|
37
39
|
|
|
38
|
-
-
|
|
40
|
+
- Use `get_heapsnapshot_class_nodes` to list instances of the suspicious class.
|
|
41
|
+
- Use `get_heapsnapshot_retainers`, `get_heapsnapshot_retaining_paths`, `get_heapsnapshot_dominators`, and `get_heapsnapshot_edges` to understand why representative nodes are still reachable.
|
|
42
|
+
- Use `get_heapsnapshot_duplicate_strings` when string growth dominates the diff.
|
|
43
|
+
- Read [references/common-leaks.md](references/common-leaks.md) for examples of common memory leaks and how to fix them after the retaining path points at application code.
|
|
39
44
|
|
|
40
|
-
### 4.
|
|
45
|
+
### 4. External Tool Fallback
|
|
41
46
|
|
|
42
|
-
If
|
|
47
|
+
If the built-in MCP memory tools are not enough, use external tools as a fallback rather than reading raw snapshots directly.
|
|
43
48
|
|
|
44
|
-
|
|
49
|
+
- Read [references/memlab.md](references/memlab.md) for how to use `memlab` to analyze generated heap snapshots.
|
|
50
|
+
- If `memlab` is not available, use the fallback script in the references directory to compare two `.heapsnapshot` files and identify the top growing objects and common leak types.
|
|
51
|
+
|
|
52
|
+
Run the fallback script using Node.js:
|
|
45
53
|
|
|
46
54
|
```bash
|
|
47
55
|
node skills/memory-leak-debugging/references/compare_snapshots.js <baseline.heapsnapshot> <target.heapsnapshot>
|
|
48
56
|
```
|
|
49
57
|
|
|
50
|
-
The script will analyze and output the top growing objects by size and highlight the 3 most common types of memory leaks (
|
|
58
|
+
The script will analyze and output the top growing objects by size and highlight the 3 most common types of memory leaks (for example, detached DOM nodes, closures, and contexts) if they are present.
|
package/build/src/utils/types.js
DELETED
|
File without changes
|