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.
Files changed (51) hide show
  1. package/README.md +15 -0
  2. package/build/src/HeapSnapshotManager.js +23 -13
  3. package/build/src/McpContext.js +174 -365
  4. package/build/src/McpPage.js +242 -31
  5. package/build/src/McpResponse.js +113 -67
  6. package/build/src/PageCollector.js +48 -122
  7. package/build/src/TextSnapshot.js +20 -2
  8. package/build/src/ToolHandler.js +13 -3
  9. package/build/src/WaitForHelper.js +18 -8
  10. package/build/src/bin/chrome-devtools-cli-options.js +25 -1
  11. package/build/src/bin/chrome-devtools-mcp-cli-options.js +15 -6
  12. package/build/src/bin/chrome-devtools-mcp-main.js +2 -2
  13. package/build/src/browser.js +1 -1
  14. package/build/src/daemon/client.js +33 -3
  15. package/build/src/daemon/daemon.js +2 -1
  16. package/build/src/daemon/utils.js +1 -1
  17. package/build/src/devtools/DevtoolsUtils.js +2 -63
  18. package/build/src/{issue-descriptions.js → devtools/issueDescriptions.js} +2 -2
  19. package/build/src/formatters/IssueFormatter.js +2 -2
  20. package/build/src/index.js +12 -3
  21. package/build/src/telemetry/ClearcutLogger.js +1 -1
  22. package/build/src/telemetry/WatchdogClient.js +1 -1
  23. package/build/src/telemetry/metricsRegistry.js +2 -9
  24. package/build/src/telemetry/persistence.js +1 -1
  25. package/build/src/telemetry/transformation.js +20 -0
  26. package/build/src/telemetry/watchdog/ClearcutSender.js +1 -1
  27. package/build/src/telemetry/watchdog/main.js +1 -1
  28. package/build/src/third_party/THIRD_PARTY_NOTICES +13 -249
  29. package/build/src/third_party/bundled-packages.json +2 -3
  30. package/build/src/third_party/index.js +1527 -1514
  31. package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +3082 -6343
  32. package/build/src/tools/emulation.js +2 -2
  33. package/build/src/tools/extensions.js +1 -1
  34. package/build/src/tools/input.js +17 -8
  35. package/build/src/tools/lighthouse.js +1 -1
  36. package/build/src/tools/memory.js +16 -2
  37. package/build/src/tools/network.js +4 -4
  38. package/build/src/tools/pages.js +21 -89
  39. package/build/src/tools/performance.js +2 -2
  40. package/build/src/tools/script.js +3 -0
  41. package/build/src/tools/snapshot.js +2 -2
  42. package/build/src/tools/thirdPartyDeveloper.js +1 -1
  43. package/build/src/tools/webmcp.js +1 -1
  44. package/build/src/trace-processing/parse.js +1 -1
  45. package/build/src/{logger.js → utils/logger.js} +1 -1
  46. package/build/src/{polyfill.js → utils/polyfill.js} +1 -1
  47. package/build/src/version.js +1 -1
  48. package/package.json +9 -5
  49. package/skills/memory-leak-debugging/SKILL.md +22 -14
  50. package/build/src/utils/types.js +0 -7
  51. /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, context) => {
78
+ handler: async (request, response) => {
79
79
  const page = request.page;
80
- await context.emulate(request.params, page.pptrPage);
80
+ await page.emulate(request.params);
81
81
  response.appendResponseLine('Emulation configured successfully');
82
82
  },
83
83
  });
@@ -54,7 +54,7 @@ export const listExtensions = defineTool({
54
54
  schema: {},
55
55
  blockedByDialog: false,
56
56
  verifyFilesSchema: [],
57
- handler: async (_request, response, _context) => {
57
+ handler: async (_request, response) => {
58
58
  response.setListExtensions();
59
59
  },
60
60
  });
@@ -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 = context.getAXNodeByUid(uid);
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, _context) => {
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
- for (const modifier of modifiers) {
455
- await page.pptrPage.keyboard.down(modifier);
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
- await page.pptrPage.keyboard.press(key);
458
- for (const modifier of modifiers.toReversed()) {
459
- await page.pptrPage.keyboard.up(modifier);
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}`);
@@ -84,7 +84,7 @@ export const lighthouseAudit = definePageTool({
84
84
  }
85
85
  }
86
86
  finally {
87
- await context.restoreEmulation(page);
87
+ await page.restoreEmulation();
88
88
  }
89
89
  const lhr = result.lhr;
90
90
  const reportPaths = [];
@@ -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, context) => {
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
- ? context.resolveCdpRequestId(request.page, data.cdpRequestId)
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, context) => {
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
- ? context.resolveCdpRequestId(request.page, data.cdpRequestId)
111
+ ? request.page.resolveCdpRequestId(data.cdpRequestId)
112
112
  : undefined;
113
113
  if (reqid) {
114
114
  response.attachNetworkRequest(reqid, {
@@ -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(args => {
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 navigateWithInterception(page, () => page.pptrPage.goto(request.params.url, {
167
- timeout: request.params.timeout,
168
- }), request.params.allowList, request.params.timeout);
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(args => {
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', 'decline'])
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
- await navigateWithInterception(page, async () => {
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
- }, request.params.allowList, request.params.timeout);
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, _context) => {
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, _context) => {
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') ? '.json.gz' : '.json');
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, context) => {
54
+ handler: async (request, response) => {
55
55
  const page = request.page;
56
- await context.waitForTextOnPage(request.params.text, request.params.timeout, page.pptrPage);
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, _context) => {
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, _context) => {
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;
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import fs from 'node:fs';
7
- import { debug } from './third_party/index.js';
7
+ import { debug } from '../third_party/index.js';
8
8
  const mcpDebugNamespace = 'mcp:log';
9
9
  const namespacesToEnable = [
10
10
  mcpDebugNamespace,
@@ -4,5 +4,5 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  // polyfills are now bundled with all other dependencies
7
- import './third_party/index.js';
7
+ import '../third_party/index.js';
8
8
  //# sourceMappingURL=polyfill.js.map
@@ -5,6 +5,6 @@
5
5
  */
6
6
  // If moved update release-please config
7
7
  // x-release-please-start-version
8
- export const VERSION = '1.5.0';
8
+ export const VERSION = '1.6.0';
9
9
  // x-release-please-end
10
10
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chrome-devtools-mcp",
3
- "version": "1.5.0",
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": "^21.0.0",
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.2.1",
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 analyze heapsnapshots or run memory leak detection tools like memlab.
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 `memlab`:** Do NOT attempt to read raw `.heapsnapshot` files directly, as they are extremely large and will consume too many tokens. Always recommend and use `memlab` to process snapshots and identify leak traces.
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. Using Memlab to Find Leaks (Recommended)
28
+ ### 2. Comparing Snapshots
28
29
 
29
- Once you have generated `.heapsnapshot` files using `take_heapsnapshot`, use `memlab` to automatically find memory leaks.
30
+ Once you have generated `.heapsnapshot` files using `take_heapsnapshot`, compare them with Chrome DevTools MCP memory tools.
30
31
 
31
- - Read [references/memlab.md](references/memlab.md) for how to use `memlab` to analyze the generated heapsnapshots.
32
- - Do **not** read raw `.heapsnapshot` files using `read_file` or `cat`.
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. Identifying Common Leaks
36
+ ### 3. Inspecting Retainers
35
37
 
36
- When you have found a leak trace (e.g., via `memlab` output), you must identify the root cause in the code.
38
+ When a class or object type grows unexpectedly, inspect the retaining chain with the MCP tools before changing code.
37
39
 
38
- - Read [references/common-leaks.md](references/common-leaks.md) for examples of common memory leaks and how to fix them.
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. Fallback: Comparing Snapshots Manually
45
+ ### 4. External Tool Fallback
41
46
 
42
- If `memlab` is not available, you MUST use the fallback script in the references directory to compare two `.heapsnapshot` files and identify the top growing objects and common leak types.
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
- Run the script using Node.js:
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 (e.g., Detached DOM nodes, closures, Contexts) if they are present.
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.
@@ -1,7 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- export {};
7
- //# sourceMappingURL=types.js.map
File without changes