chrome-devtools-mcp 1.4.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 (56) hide show
  1. package/README.md +20 -3
  2. package/build/src/HeapSnapshotManager.js +83 -16
  3. package/build/src/McpContext.js +218 -367
  4. package/build/src/McpPage.js +242 -31
  5. package/build/src/McpResponse.js +165 -60
  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 +76 -4
  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/bin/chrome-devtools.js +25 -1
  14. package/build/src/browser.js +1 -1
  15. package/build/src/daemon/client.js +33 -3
  16. package/build/src/daemon/daemon.js +3 -2
  17. package/build/src/daemon/utils.js +1 -1
  18. package/build/src/devtools/DevtoolsUtils.js +2 -63
  19. package/build/src/{issue-descriptions.js → devtools/issueDescriptions.js} +8 -6
  20. package/build/src/formatters/HeapSnapshotFormatter.js +43 -0
  21. package/build/src/formatters/IssueFormatter.js +2 -2
  22. package/build/src/index.js +14 -5
  23. package/build/src/telemetry/ClearcutLogger.js +1 -1
  24. package/build/src/telemetry/WatchdogClient.js +1 -1
  25. package/build/src/telemetry/metricsRegistry.js +2 -9
  26. package/build/src/telemetry/persistence.js +1 -1
  27. package/build/src/telemetry/transformation.js +20 -0
  28. package/build/src/telemetry/watchdog/ClearcutSender.js +1 -1
  29. package/build/src/telemetry/watchdog/main.js +1 -1
  30. package/build/src/third_party/THIRD_PARTY_NOTICES +13 -279
  31. package/build/src/third_party/bundled-packages.json +3 -5
  32. package/build/src/third_party/devtools-heap-snapshot-worker.js +81 -0
  33. package/build/src/third_party/index.js +2418 -2197
  34. package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +3082 -6343
  35. package/build/src/tools/emulation.js +2 -2
  36. package/build/src/tools/extensions.js +1 -1
  37. package/build/src/tools/input.js +17 -8
  38. package/build/src/tools/lighthouse.js +1 -1
  39. package/build/src/tools/memory.js +76 -6
  40. package/build/src/tools/network.js +4 -4
  41. package/build/src/tools/pages.js +21 -89
  42. package/build/src/tools/performance.js +2 -2
  43. package/build/src/tools/screencast.js +1 -2
  44. package/build/src/tools/script.js +6 -10
  45. package/build/src/tools/snapshot.js +2 -2
  46. package/build/src/tools/thirdPartyDeveloper.js +7 -7
  47. package/build/src/tools/webmcp.js +1 -1
  48. package/build/src/trace-processing/parse.js +1 -1
  49. package/build/src/utils/files.js +0 -4
  50. package/build/src/{logger.js → utils/logger.js} +1 -1
  51. package/build/src/{polyfill.js → utils/polyfill.js} +1 -1
  52. package/build/src/version.js +1 -1
  53. package/package.json +17 -5
  54. package/skills/memory-leak-debugging/SKILL.md +22 -14
  55. package/build/src/utils/types.js +0 -7
  56. /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 = [];
@@ -4,9 +4,14 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { zod } from '../third_party/index.js';
7
- import { ensureExtension } from '../utils/files.js';
8
7
  import { ToolCategory } from './categories.js';
9
8
  import { definePageTool, defineTool } from './ToolDefinition.js';
9
+ const HEAP_SNAPSHOT_FILTERS = [
10
+ 'objectsRetainedByDetachedDomNodes',
11
+ 'objectsRetainedByConsole',
12
+ 'objectsRetainedByEventHandlers',
13
+ 'objectsRetainedByContexts',
14
+ ];
10
15
  export const takeHeapSnapshot = definePageTool({
11
16
  name: 'take_heapsnapshot',
12
17
  description: `Capture a heap snapshot of the currently selected page. Use to analyze the memory distribution of JavaScript objects and debug memory leaks.`,
@@ -21,12 +26,13 @@ export const takeHeapSnapshot = definePageTool({
21
26
  },
22
27
  blockedByDialog: true,
23
28
  verifyFilesSchema: ['filePath'],
24
- handler: async (request, response) => {
29
+ handler: async (request, response, context) => {
25
30
  const page = request.page;
31
+ const snapshotPath = await context.ensureExtension(request.params.filePath, '.heapsnapshot');
26
32
  await page.pptrPage.captureHeapSnapshot({
27
- path: ensureExtension(request.params.filePath, '.heapsnapshot'),
33
+ path: snapshotPath,
28
34
  });
29
- response.appendResponseLine(`Heap snapshot saved to ${request.params.filePath}`);
35
+ response.appendResponseLine(`Heap snapshot saved to ${snapshotPath}`);
30
36
  },
31
37
  });
32
38
  export const getHeapSnapshotSummary = defineTool({
@@ -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,
@@ -224,4 +238,60 @@ export const getHeapSnapshotDominators = defineTool({
224
238
  response.setHeapSnapshotDominators(dominators);
225
239
  },
226
240
  });
241
+ export const compareHeapSnapshots = defineTool({
242
+ name: 'compare_heapsnapshots',
243
+ description: 'Loads two memory heapsnapshots and returns the comparison. If classIndex is provided, returns detailed diff for that class, otherwise returns summary diff.',
244
+ annotations: {
245
+ category: ToolCategory.MEMORY,
246
+ readOnlyHint: true,
247
+ conditions: ['memoryDebugging'],
248
+ },
249
+ verifyFilesSchema: ['baseFilePath', 'currentFilePath'],
250
+ schema: {
251
+ baseFilePath: zod
252
+ .string()
253
+ .describe('A path to the base .heapsnapshot file (earlier snapshot).'),
254
+ currentFilePath: zod
255
+ .string()
256
+ .describe('A path to the current .heapsnapshot file (later snapshot).'),
257
+ classIndex: zod
258
+ .number()
259
+ .optional()
260
+ .describe('Optional 0-based index of the class in the summary list to filter results, showing individual objects.'),
261
+ },
262
+ blockedByDialog: false,
263
+ handler: async (request, response, context) => {
264
+ if (request.params.classIndex !== undefined) {
265
+ const classDiffResult = await context.getHeapSnapshotDetailedClassDiff(request.params.baseFilePath, request.params.currentFilePath, request.params.classIndex);
266
+ response.setHeapSnapshotDetailedClassDiff(classDiffResult);
267
+ }
268
+ else {
269
+ const diff = await context.getHeapSnapshotClassDiffs(request.params.baseFilePath, request.params.currentFilePath);
270
+ response.setHeapSnapshotClassDiffs(diff);
271
+ }
272
+ },
273
+ });
274
+ export const getHeapSnapshotDuplicateStrings = defineTool({
275
+ name: 'get_heapsnapshot_duplicate_strings',
276
+ description: 'Loads a memory heapsnapshot and returns duplicate strings grouped by their value.',
277
+ annotations: {
278
+ category: ToolCategory.MEMORY,
279
+ readOnlyHint: true,
280
+ conditions: ['memoryDebugging'],
281
+ },
282
+ blockedByDialog: false,
283
+ verifyFilesSchema: ['filePath'],
284
+ schema: {
285
+ filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
286
+ pageIdx: zod.number().optional().describe('The page index for pagination.'),
287
+ pageSize: zod.number().optional().describe('The page size for pagination.'),
288
+ },
289
+ handler: async (request, response, context) => {
290
+ const duplicateStrings = await context.getHeapSnapshotDuplicateStrings(request.params.filePath);
291
+ response.setHeapSnapshotDuplicateStrings(duplicateStrings, {
292
+ pageIdx: request.params.pageIdx,
293
+ pageSize: request.params.pageSize,
294
+ });
295
+ },
296
+ });
227
297
  //# sourceMappingURL=memory.js.map
@@ -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, {
@@ -7,7 +7,6 @@ import fs from 'node:fs/promises';
7
7
  import os from 'node:os';
8
8
  import path from 'node:path';
9
9
  import { zod } from '../third_party/index.js';
10
- import { ensureExtension } from '../utils/files.js';
11
10
  import { ToolCategory } from './categories.js';
12
11
  import { definePageTool } from './ToolDefinition.js';
13
12
  async function generateTempFilePath() {
@@ -53,7 +52,7 @@ export const startScreencast = definePageTool(args => ({
53
52
  const enforcedExtension = matchedExtension ?? '.mp4';
54
53
  const format = (matchedExtension?.substring(1) ??
55
54
  'mp4');
56
- const resolvedPath = ensureExtension(path.resolve(filePath), enforcedExtension);
55
+ const resolvedPath = await context.ensureExtension(filePath, enforcedExtension);
57
56
  const page = request.page;
58
57
  let recorder;
59
58
  try {
@@ -9,8 +9,7 @@ import { defineTool, pageIdSchema } from './ToolDefinition.js';
9
9
  export const evaluateScript = defineTool(cliArgs => {
10
10
  return {
11
11
  name: 'evaluate_script',
12
- description: `Evaluate a JavaScript function inside the currently selected page${cliArgs?.categoryExtensions ? ' or service worker' : ''}. Returns the response as JSON,
13
- so returned values have to be JSON-serializable.`,
12
+ description: `Evaluate a JavaScript function inside the currently selected page${cliArgs?.categoryExtensions ? ' or service worker' : ''}. Returns the response as JSON, so returned values have to be JSON-serializable.`,
14
13
  annotations: {
15
14
  category: ToolCategory.DEBUGGING,
16
15
  readOnlyHint: false,
@@ -18,14 +17,8 @@ so returned values have to be JSON-serializable.`,
18
17
  schema: {
19
18
  ...(cliArgs?.experimentalPageIdRouting ? pageIdSchema : {}),
20
19
  function: zod.string().describe(`A JavaScript function declaration to be executed by the tool in the currently selected page.
21
- Example without arguments: \`() => {
22
- return document.title
23
- }\` or \`async () => {
24
- return await fetch("example.com")
25
- }\`.
26
- Example with arguments: \`(el) => {
27
- return el.innerText;
28
- }\`
20
+ Example without arguments: \`() => document.title\` or \`async () => await fetch("example.com")\`.
21
+ Example with arguments: \`(el) => el.innerText\`
29
22
  `),
30
23
  args: zod
31
24
  .array(zod
@@ -70,6 +63,9 @@ Example with arguments: \`(el) => {
70
63
  context,
71
64
  });
72
65
  }, { handleDialog: dialogAction ?? 'accept' });
66
+ if (result.dialogHandled) {
67
+ context.getSelectedMcpPage().clearDialog();
68
+ }
73
69
  response.attachWaitForResult(result);
74
70
  return;
75
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
  },
@@ -9,12 +9,12 @@ import { definePageTool } from './ToolDefinition.js';
9
9
  export const listThirdPartyDeveloperTools = definePageTool({
10
10
  name: 'list_3p_developer_tools',
11
11
  description: `Lists all third-party developer tools the page exposes for providing runtime information.
12
- Third-party developer tools can be called via the 'execute_3p_developer_tool()' MCP tool.
13
- Alternatively, third-party developer tools can be executed by calling 'evaluate_script' and adding the
14
- following command to the script:
15
- 'window.__dtmcp.executeTool(toolName, params)'
16
- This might be helpful when the third-party developer tools return non-serializable values or when composing
17
- third-party developer tools with additional functionality.`,
12
+ Third-party developer tools can be called via the 'execute_3p_developer_tool()' MCP tool.
13
+ Alternatively, third-party developer tools can be executed by calling 'evaluate_script' and adding the
14
+ following command to the script:
15
+ \`window.__dtmcp.executeTool(toolName, params)\`
16
+ This might be helpful when the third-party developer tools return non-serializable values or when composing
17
+ third-party developer tools with additional functionality.`,
18
18
  annotations: {
19
19
  category: ToolCategory.THIRD_PARTY,
20
20
  readOnlyHint: true,
@@ -22,7 +22,7 @@ export const listThirdPartyDeveloperTools = definePageTool({
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;
@@ -11,10 +11,6 @@ export async function getTempFilePath(filename) {
11
11
  const filepath = path.join(dir, filename);
12
12
  return filepath;
13
13
  }
14
- export function ensureExtension(filepath, extension) {
15
- const ext = path.extname(filepath);
16
- return filepath.slice(0, filepath.length - ext.length) + extension;
17
- }
18
14
  export async function resolveCanonicalPath(filePath) {
19
15
  const absolutePath = path.resolve(filePath);
20
16
  try {
@@ -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.4.0';
8
+ export const VERSION = '1.6.0';
9
9
  // x-release-please-end
10
10
  //# sourceMappingURL=version.js.map