chrome-devtools-mcp 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +72 -20
  2. package/build/src/BrowserManager.js +27 -18
  3. package/build/src/McpContext.js +435 -87
  4. package/build/src/McpPage.js +189 -59
  5. package/build/src/McpResponse.js +61 -44
  6. package/build/src/TextSnapshot.js +37 -18
  7. package/build/src/ToolHandler.js +256 -135
  8. package/build/src/bin/chrome-devtools-mcp-main.js +6 -4
  9. package/build/src/bin/chrome-devtools.js +4 -4
  10. package/build/src/collectors/PageCollector.js +13 -9
  11. package/build/src/collectors/ServiceWorkerCollector.js +2 -2
  12. package/build/src/collectors/constants.js +7 -0
  13. package/build/src/config/ConfigParser.js +44 -149
  14. package/build/src/config/ConfigWatcher.js +3 -2
  15. package/build/src/config/ServerConfig.js +251 -0
  16. package/build/src/config/browser-options.js +13 -4
  17. package/build/src/config/cli-options.js +35 -19
  18. package/build/src/config/mcp-options.js +61 -35
  19. package/build/src/config/puppeteer-options.js +4 -2
  20. package/build/src/daemon/client.js +3 -3
  21. package/build/src/daemon/daemon.js +7 -3
  22. package/build/src/daemon/utils.js +2 -1
  23. package/build/src/devtools/DevToolsCommentBridge.js +28 -5
  24. package/build/src/devtools/DevtoolsUtils.js +49 -12
  25. package/build/src/formatters/ConsoleFormatter.js +28 -1
  26. package/build/src/formatters/HeapSnapshotFormatter.js +14 -18
  27. package/build/src/formatters/NetworkFormatter.js +54 -15
  28. package/build/src/formatters/RemoteObjectFormatter.js +231 -0
  29. package/build/src/formatters/SnapshotFormatter.js +13 -3
  30. package/build/src/index.js +256 -104
  31. package/build/src/processors/HeapSnapshotManager.js +390 -128
  32. package/build/src/third_party/THIRD_PARTY_NOTICES +542 -445
  33. package/build/src/third_party/bundled-packages.json +2 -2
  34. package/build/src/third_party/cli.js +9239 -0
  35. package/build/src/third_party/devtools-formatter-worker.js +3089 -2438
  36. package/build/src/third_party/devtools-heap-snapshot-worker.js +172 -1
  37. package/build/src/third_party/index.js +52247 -55764
  38. package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +54576 -52174
  39. package/build/src/tools/ToolDefinition.js +90 -12
  40. package/build/src/tools/comments.js +42 -3
  41. package/build/src/tools/console.js +6 -4
  42. package/build/src/tools/css.js +1 -0
  43. package/build/src/tools/emulation.js +5 -4
  44. package/build/src/tools/extensions.js +5 -0
  45. package/build/src/tools/input.js +21 -6
  46. package/build/src/tools/lighthouse.js +24 -8
  47. package/build/src/tools/memory.js +59 -53
  48. package/build/src/tools/network.js +5 -4
  49. package/build/src/tools/pages.js +48 -6
  50. package/build/src/tools/performance.js +7 -4
  51. package/build/src/tools/pwa.js +7 -0
  52. package/build/src/tools/screencast.js +3 -1
  53. package/build/src/tools/screenshot.js +23 -7
  54. package/build/src/tools/script.js +38 -6
  55. package/build/src/tools/slim/tools.js +21 -5
  56. package/build/src/tools/snapshot.js +13 -3
  57. package/build/src/tools/thirdPartyDeveloper.js +3 -1
  58. package/build/src/tools/webmcp.js +2 -0
  59. package/build/src/utils/TaskRunner.js +136 -0
  60. package/build/src/utils/WaitForHelper.js +1 -1
  61. package/build/src/utils/bytes.js +2 -12
  62. package/build/src/utils/check-for-updates.js +1 -1
  63. package/build/src/utils/disclaimers.js +27 -0
  64. package/build/src/utils/keyboard.js +14 -2
  65. package/build/src/utils/logger.js +69 -0
  66. package/build/src/utils/resourceType.js +27 -0
  67. package/build/src/utils/text.js +29 -0
  68. package/build/src/utils/timeout.js +14 -0
  69. package/build/src/utils/url.js +41 -0
  70. package/build/src/version.js +1 -1
  71. package/package.json +5 -4
  72. package/skills/a11y-debugging/SKILL.md +3 -8
@@ -7,7 +7,7 @@ import { MAX_NAME_LENGTH } from '../formatters/HeapSnapshotFormatter.js';
7
7
  import { zod } from '../third_party/index.js';
8
8
  import { byteSizeRangeSchema } from '../utils/bytes.js';
9
9
  import { ToolCategory } from './categories.js';
10
- import { definePageTool, defineTool } from './ToolDefinition.js';
10
+ import { defineBrowserlessTool, definePageTool, } from './ToolDefinition.js';
11
11
  const HEAP_SNAPSHOT_FILTERS = [
12
12
  'objectsRetainedByDetachedDomNodes',
13
13
  'objectsRetainedByConsole',
@@ -23,18 +23,19 @@ const maxNameLengthSchema = zod
23
23
  .min(1)
24
24
  .optional()
25
25
  .describe(`Maximum length of names before truncation. Defaults to ${MAX_NAME_LENGTH}.`);
26
+ const DEFAULT_HEAP_SNAPSHOT_PAGE_SIZE = 50;
26
27
  const pageIdxSchema = zod
27
28
  .number()
28
29
  .int()
29
30
  .nonnegative()
30
- .optional()
31
- .describe('The page index for pagination.');
31
+ .default(0)
32
+ .describe('The zero-based page index. Defaults to 0 (the first page).');
32
33
  const pageSizeSchema = zod
33
34
  .number()
34
35
  .int()
35
36
  .positive()
36
- .optional()
37
- .describe('The page size for pagination.');
37
+ .default(DEFAULT_HEAP_SNAPSHOT_PAGE_SIZE)
38
+ .describe(`The maximum number of items to return per page. Defaults to ${DEFAULT_HEAP_SNAPSHOT_PAGE_SIZE}.`);
38
39
  export const takeHeapSnapshot = definePageTool(() => ({
39
40
  name: 'take_heapsnapshot',
40
41
  description: `Capture a heap snapshot of the target page. Use to analyze the memory distribution of JavaScript objects and debug memory leaks.`,
@@ -48,6 +49,7 @@ export const takeHeapSnapshot = definePageTool(() => ({
48
49
  .describe('A path to a .heapsnapshot file to save the heapsnapshot to.'),
49
50
  },
50
51
  blockedByDialog: true,
52
+ concurrency: 'exclusive',
51
53
  verifyFilesSchema: {
52
54
  filePath: true,
53
55
  },
@@ -60,7 +62,7 @@ export const takeHeapSnapshot = definePageTool(() => ({
60
62
  response.appendResponseLine(`Heap snapshot saved to ${snapshotPath}`);
61
63
  },
62
64
  }));
63
- export const getHeapSnapshotSummary = defineTool(() => ({
65
+ export const getHeapSnapshotSummary = defineBrowserlessTool(() => ({
64
66
  name: 'get_heapsnapshot_summary',
65
67
  description: 'Loads and caches a memory heapsnapshot and returns snapshot summary stats, including native contexts and their sizes, and retained by context summary.',
66
68
  annotations: {
@@ -69,7 +71,9 @@ export const getHeapSnapshotSummary = defineTool(() => ({
69
71
  conditions: ['memoryDebugging'],
70
72
  },
71
73
  schema: {
72
- filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
74
+ filePath: zod
75
+ .string()
76
+ .describe('A path to a .heapsnapshot file to read.'),
73
77
  maxNameLength: maxNameLengthSchema,
74
78
  },
75
79
  blockedByDialog: false,
@@ -86,7 +90,7 @@ export const getHeapSnapshotSummary = defineTool(() => ({
86
90
  });
87
91
  },
88
92
  }));
89
- export const getHeapSnapshotDetails = defineTool(() => ({
93
+ export const getHeapSnapshotDetails = defineBrowserlessTool(() => ({
90
94
  name: 'get_heapsnapshot_details',
91
95
  description: 'Loads and caches a memory heapsnapshot and returns all available information including statistics, static data, and aggregated node information. Supports pagination for aggregates.',
92
96
  annotations: {
@@ -95,7 +99,9 @@ export const getHeapSnapshotDetails = defineTool(() => ({
95
99
  conditions: ['memoryDebugging'],
96
100
  },
97
101
  schema: {
98
- filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
102
+ filePath: zod
103
+ .string()
104
+ .describe('A path to a .heapsnapshot file to read.'),
99
105
  filterName: zod
100
106
  .enum(HEAP_SNAPSHOT_FILTERS)
101
107
  .optional()
@@ -105,18 +111,8 @@ export const getHeapSnapshotDetails = defineTool(() => ({
105
111
  .optional()
106
112
  .describe('The object ID (nodeId) of the specific native context to filter by when filterName is attributedToSpecificNativeContext.'),
107
113
  maxNameLength: maxNameLengthSchema,
108
- pageIdx: zod
109
- .number()
110
- .int()
111
- .nonnegative()
112
- .optional()
113
- .describe('The page index for pagination of aggregates.'),
114
- pageSize: zod
115
- .number()
116
- .int()
117
- .positive()
118
- .optional()
119
- .describe('The page size for pagination of aggregates.'),
114
+ pageIdx: pageIdxSchema,
115
+ pageSize: pageSizeSchema,
120
116
  },
121
117
  blockedByDialog: false,
122
118
  verifyFilesSchema: {
@@ -131,7 +127,7 @@ export const getHeapSnapshotDetails = defineTool(() => ({
131
127
  });
132
128
  },
133
129
  }));
134
- export const getHeapSnapshotClassNodes = defineTool(() => ({
130
+ export const getHeapSnapshotClassNodes = defineBrowserlessTool(() => ({
135
131
  name: 'get_heapsnapshot_class_nodes',
136
132
  description: 'Loads and caches a memory heapsnapshot and returns instances of a specific class with their IDs.',
137
133
  annotations: {
@@ -140,7 +136,9 @@ export const getHeapSnapshotClassNodes = defineTool(() => ({
140
136
  conditions: ['memoryDebugging'],
141
137
  },
142
138
  schema: {
143
- filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
139
+ filePath: zod
140
+ .string()
141
+ .describe('A path to a .heapsnapshot file to read.'),
144
142
  id: zod.number().describe('The ID for the class, obtained from details.'),
145
143
  filterName: zod
146
144
  .enum(HEAP_SNAPSHOT_FILTERS)
@@ -167,7 +165,7 @@ export const getHeapSnapshotClassNodes = defineTool(() => ({
167
165
  });
168
166
  },
169
167
  }));
170
- export const getHeapSnapshotRetainers = defineTool(() => ({
168
+ export const getHeapSnapshotRetainers = defineBrowserlessTool(() => ({
171
169
  name: 'get_heapsnapshot_retainers',
172
170
  description: 'Loads and caches a memory heapsnapshot and returns retainers for a specific node ID.',
173
171
  annotations: {
@@ -180,7 +178,9 @@ export const getHeapSnapshotRetainers = defineTool(() => ({
180
178
  filePath: true,
181
179
  },
182
180
  schema: {
183
- filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
181
+ filePath: zod
182
+ .string()
183
+ .describe('A path to a .heapsnapshot file to read.'),
184
184
  nodeId: zod.number().describe('The node ID to get retainers for.'),
185
185
  maxNameLength: maxNameLengthSchema,
186
186
  pageIdx: pageIdxSchema,
@@ -195,7 +195,7 @@ export const getHeapSnapshotRetainers = defineTool(() => ({
195
195
  });
196
196
  },
197
197
  }));
198
- export const closeHeapSnapshot = defineTool(() => ({
198
+ export const closeHeapSnapshot = defineBrowserlessTool(() => ({
199
199
  name: 'close_heapsnapshot',
200
200
  description: 'Closes a previously loaded and cached memory heapsnapshot, freeing its memory.',
201
201
  annotations: {
@@ -220,7 +220,7 @@ export const closeHeapSnapshot = defineTool(() => ({
220
220
  response.appendResponseLine(`Closed heap snapshot: ${request.params.filePath}`);
221
221
  },
222
222
  }));
223
- export const getHeapSnapshotRetainingPaths = defineTool(() => ({
223
+ export const getHeapSnapshotRetainingPaths = defineBrowserlessTool(() => ({
224
224
  name: 'get_heapsnapshot_retaining_paths',
225
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.',
226
226
  annotations: {
@@ -233,7 +233,9 @@ export const getHeapSnapshotRetainingPaths = defineTool(() => ({
233
233
  },
234
234
  blockedByDialog: false,
235
235
  schema: {
236
- filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
236
+ filePath: zod
237
+ .string()
238
+ .describe('A path to a .heapsnapshot file to read.'),
237
239
  nodeId: zod.number().describe('The node ID to get retaining paths for.'),
238
240
  maxDepth: zod
239
241
  .number()
@@ -256,7 +258,7 @@ export const getHeapSnapshotRetainingPaths = defineTool(() => ({
256
258
  });
257
259
  },
258
260
  }));
259
- export const getHeapSnapshotEdges = defineTool(() => ({
261
+ export const getHeapSnapshotEdges = defineBrowserlessTool(() => ({
260
262
  name: 'get_heapsnapshot_edges',
261
263
  description: 'Loads and caches a memory heapsnapshot and returns outgoing edges (references) for a specific node ID.',
262
264
  annotations: {
@@ -269,7 +271,9 @@ export const getHeapSnapshotEdges = defineTool(() => ({
269
271
  filePath: true,
270
272
  },
271
273
  schema: {
272
- filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
274
+ filePath: zod
275
+ .string()
276
+ .describe('A path to a .heapsnapshot file to read.'),
273
277
  nodeId: zod.number().describe('The node ID to get outgoing edges for.'),
274
278
  sortBy: zod
275
279
  .enum(['retainedSize', 'selfSize', 'name'])
@@ -298,7 +302,7 @@ export const getHeapSnapshotEdges = defineTool(() => ({
298
302
  });
299
303
  },
300
304
  }));
301
- export const getHeapSnapshotDominators = defineTool(() => ({
305
+ export const getHeapSnapshotDominators = defineBrowserlessTool(() => ({
302
306
  name: 'get_heapsnapshot_dominators',
303
307
  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.',
304
308
  annotations: {
@@ -311,7 +315,9 @@ export const getHeapSnapshotDominators = defineTool(() => ({
311
315
  filePath: true,
312
316
  },
313
317
  schema: {
314
- filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
318
+ filePath: zod
319
+ .string()
320
+ .describe('A path to a .heapsnapshot file to read.'),
315
321
  nodeId: zod
316
322
  .number()
317
323
  .describe('The node ID to get the dominator chain for.'),
@@ -324,7 +330,7 @@ export const getHeapSnapshotDominators = defineTool(() => ({
324
330
  });
325
331
  },
326
332
  }));
327
- export const compareHeapSnapshots = defineTool(() => ({
333
+ export const compareHeapSnapshots = defineBrowserlessTool(() => ({
328
334
  name: 'compare_heapsnapshots',
329
335
  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.',
330
336
  annotations: {
@@ -356,6 +362,8 @@ export const compareHeapSnapshots = defineTool(() => ({
356
362
  if (request.params.classIndex !== undefined) {
357
363
  const classDiffResult = await context.getHeapSnapshotDetailedClassDiff(request.params.baseFilePath, request.params.currentFilePath, request.params.classIndex);
358
364
  response.setHeapSnapshotDetailedClassDiff(classDiffResult, {
365
+ pageIdx: request.params.pageIdx,
366
+ pageSize: request.params.pageSize,
359
367
  maxNameLength: request.params.maxNameLength,
360
368
  });
361
369
  }
@@ -369,7 +377,7 @@ export const compareHeapSnapshots = defineTool(() => ({
369
377
  }
370
378
  },
371
379
  }));
372
- export const getHeapSnapshotDuplicateStrings = defineTool(() => ({
380
+ export const getHeapSnapshotDuplicateStrings = defineBrowserlessTool(() => ({
373
381
  name: 'get_heapsnapshot_duplicate_strings',
374
382
  description: 'Loads and caches a memory heapsnapshot and returns duplicate strings grouped by their value.',
375
383
  annotations: {
@@ -382,7 +390,9 @@ export const getHeapSnapshotDuplicateStrings = defineTool(() => ({
382
390
  filePath: true,
383
391
  },
384
392
  schema: {
385
- filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
393
+ filePath: zod
394
+ .string()
395
+ .describe('A path to a .heapsnapshot file to read.'),
386
396
  pageIdx: pageIdxSchema,
387
397
  pageSize: pageSizeSchema,
388
398
  maxNameLength: maxNameLengthSchema,
@@ -396,7 +406,7 @@ export const getHeapSnapshotDuplicateStrings = defineTool(() => ({
396
406
  });
397
407
  },
398
408
  }));
399
- export const getHeapSnapshotObjectDetails = defineTool(() => ({
409
+ export const getHeapSnapshotObjectDetails = defineBrowserlessTool(() => ({
400
410
  name: 'get_heapsnapshot_object_details',
401
411
  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.',
402
412
  annotations: {
@@ -409,7 +419,9 @@ export const getHeapSnapshotObjectDetails = defineTool(() => ({
409
419
  filePath: true,
410
420
  },
411
421
  schema: {
412
- filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
422
+ filePath: zod
423
+ .string()
424
+ .describe('A path to a .heapsnapshot file to read.'),
413
425
  nodeId: zod.number().describe('The node ID to get object details for.'),
414
426
  maxNameLength: maxNameLengthSchema,
415
427
  },
@@ -420,7 +432,7 @@ export const getHeapSnapshotObjectDetails = defineTool(() => ({
420
432
  });
421
433
  },
422
434
  }));
423
- export const queryHeapSnapshotObjects = defineTool(() => ({
435
+ export const queryHeapSnapshotObjects = defineBrowserlessTool(() => ({
424
436
  name: 'query_heapsnapshot_objects',
425
437
  description: 'Loads and caches a memory heapsnapshot and queries objects matching specific filters (className, propertyName, nodeType, retainedSize, selfSize, isDetached, sortBy).',
426
438
  annotations: {
@@ -431,7 +443,9 @@ export const queryHeapSnapshotObjects = defineTool(() => ({
431
443
  blockedByDialog: false,
432
444
  verifyFilesSchema: { filePath: true },
433
445
  schema: {
434
- filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
446
+ filePath: zod
447
+ .string()
448
+ .describe('A path to a .heapsnapshot file to read.'),
435
449
  className: zod
436
450
  .string()
437
451
  .optional()
@@ -477,7 +491,7 @@ export const queryHeapSnapshotObjects = defineTool(() => ({
477
491
  });
478
492
  },
479
493
  }));
480
- export const analyzeHeapSnapshotContexts = defineTool(() => ({
494
+ export const analyzeHeapSnapshotContexts = defineBrowserlessTool(() => ({
481
495
  name: 'analyze_heapsnapshot_contexts',
482
496
  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
497
  annotations: {
@@ -490,7 +504,9 @@ export const analyzeHeapSnapshotContexts = defineTool(() => ({
490
504
  filePath: true,
491
505
  },
492
506
  schema: {
493
- filePath: zod.string().describe('A path to a .heapsnapshot file to read.'),
507
+ filePath: zod
508
+ .string()
509
+ .describe('A path to a .heapsnapshot file to read.'),
494
510
  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
511
  scopeInfoNodeId: zod
496
512
  .number()
@@ -498,18 +514,8 @@ export const analyzeHeapSnapshotContexts = defineTool(() => ({
498
514
  .optional()
499
515
  .describe('Only return contexts declared by the scope with this ScopeInfo node id, as reported in the scope header of a previous call.'),
500
516
  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.'),
517
+ pageIdx: pageIdxSchema,
518
+ pageSize: pageSizeSchema,
513
519
  },
514
520
  handler: async (request, response, context) => {
515
521
  const analysis = await context.analyzeHeapSnapshotContexts(request.params.filePath);
@@ -18,7 +18,6 @@ const FILTERABLE_RESOURCE_TYPES = [
18
18
  'fetch',
19
19
  'prefetch',
20
20
  'eventsource',
21
- 'websocket',
22
21
  'manifest',
23
22
  'signedexchange',
24
23
  'ping',
@@ -27,7 +26,7 @@ const FILTERABLE_RESOURCE_TYPES = [
27
26
  'fedcm',
28
27
  'other',
29
28
  ];
30
- export const listNetworkRequests = definePageTool(() => ({
29
+ export const listNetworkRequests = definePageTool((args) => ({
31
30
  name: 'list_network_requests',
32
31
  description: `Lists the most recent requests for the target page since the last navigation.`,
33
32
  annotations: {
@@ -46,7 +45,7 @@ export const listNetworkRequests = definePageTool(() => ({
46
45
  .int()
47
46
  .min(0)
48
47
  .optional()
49
- .describe('Page number to return (0-based). When omitted, returns the first page.'),
48
+ .describe('Page number to return (0-based). When omitted, returns the first page. Ignored unless pageSize is set.'),
50
49
  resourceTypes: zod
51
50
  .array(zod.enum(FILTERABLE_RESOURCE_TYPES))
52
51
  .optional()
@@ -55,9 +54,10 @@ export const listNetworkRequests = definePageTool(() => ({
55
54
  .boolean()
56
55
  .default(false)
57
56
  .optional()
58
- .describe('Set to true to return the preserved requests over the last 3 navigations.'),
57
+ .describe(`Set to true to return the preserved requests over the last ${args.maxNavigationSaved} navigations.`),
59
58
  },
60
59
  blockedByDialog: false,
60
+ concurrency: 'page',
61
61
  verifyFilesSchema: {},
62
62
  handler: async (request, response) => {
63
63
  const data = await request.page.getDevToolsData();
@@ -96,6 +96,7 @@ export const getNetworkRequest = definePageTool(() => ({
96
96
  .describe('The absolute or relative path to a .network-response file to save the response body to. If omitted, the body is returned inline.'),
97
97
  },
98
98
  blockedByDialog: true,
99
+ concurrency: 'page',
99
100
  verifyFilesSchema: {
100
101
  requestFilePath: true,
101
102
  responseFilePath: true,
@@ -18,6 +18,7 @@ export const listPages = defineTool((args) => {
18
18
  },
19
19
  schema: {},
20
20
  blockedByDialog: false,
21
+ concurrency: 'exclusive',
21
22
  verifyFilesSchema: {},
22
23
  handler: async (_request, response) => {
23
24
  response.setIncludePages(true);
@@ -43,10 +44,11 @@ export const selectPage = defineTool((args) => ({
43
44
  .describe('Whether to focus the page and bring it to the top.'),
44
45
  },
45
46
  blockedByDialog: false,
47
+ concurrency: 'exclusive',
46
48
  verifyFilesSchema: {},
47
49
  handler: async (request, response, context) => {
48
50
  const page = context.getPageById(request.params.pageId);
49
- await page.init();
51
+ await page.init({ emulateFocus: true });
50
52
  context.selectPage(page);
51
53
  response.setIncludePages(true);
52
54
  response.setListThirdPartyDeveloperTools();
@@ -69,6 +71,7 @@ export const closePage = defineTool(() => ({
69
71
  .describe('The ID of the page to close. Call list_pages to list pages.'),
70
72
  },
71
73
  blockedByDialog: false,
74
+ concurrency: 'exclusive',
72
75
  verifyFilesSchema: {},
73
76
  handler: async (request, response, context) => {
74
77
  try {
@@ -109,6 +112,7 @@ export const newPage = defineTool((args) => {
109
112
  ...timeoutSchema,
110
113
  },
111
114
  blockedByDialog: false,
115
+ concurrency: 'exclusive',
112
116
  verifyFilesSchema: {},
113
117
  handler: async (request, response, context) => {
114
118
  validateUrl(request.params.url, {
@@ -116,12 +120,46 @@ export const newPage = defineTool((args) => {
116
120
  categoryExtensions: args?.categoryExtensions,
117
121
  fileNavigations: args?.fileNavigations,
118
122
  });
123
+ let previousPage;
124
+ try {
125
+ previousPage = context.getSelectedMcpPage();
126
+ }
127
+ catch {
128
+ // Nothing is selected, so there is no selection to restore on failure.
129
+ }
119
130
  const page = await context.newPage(request.params.background, request.params.isolatedContext);
120
- await page.waitForEventsAfterAction(async () => {
121
- await page.pptrPage.goto(request.params.url, {
122
- timeout: request.params.timeout,
123
- });
124
- }, { timeout: request.params.timeout });
131
+ try {
132
+ await page.waitForEventsAfterAction(async () => {
133
+ await page.pptrPage.goto(request.params.url, {
134
+ timeout: request.params.timeout,
135
+ });
136
+ }, { timeout: request.params.timeout });
137
+ }
138
+ catch (error) {
139
+ // A dialog-blocked load stays open for handle_dialog. Otherwise cleanup is
140
+ // best-effort: the navigation error is always what gets rethrown.
141
+ if (page.getDialog()) {
142
+ response.setIncludePages(true);
143
+ }
144
+ else {
145
+ try {
146
+ if (previousPage && !previousPage.isClosed()) {
147
+ context.selectPage(previousPage);
148
+ }
149
+ }
150
+ catch {
151
+ // Keep the new tab selected.
152
+ }
153
+ try {
154
+ await context.closePage(page.id);
155
+ }
156
+ catch {
157
+ // The tab survived, so list pages to tell the caller its pageId.
158
+ response.setIncludePages(true);
159
+ }
160
+ }
161
+ throw error;
162
+ }
125
163
  response.setIncludePages(true);
126
164
  response.setListThirdPartyDeveloperTools();
127
165
  },
@@ -160,6 +198,7 @@ export const navigatePage = definePageTool((args) => {
160
198
  ...timeoutSchema,
161
199
  },
162
200
  blockedByDialog: false,
201
+ concurrency: 'page',
163
202
  verifyFilesSchema: {},
164
203
  handler: async (request, response) => {
165
204
  const page = request.page;
@@ -267,6 +306,7 @@ export const resizePage = definePageTool(() => ({
267
306
  height: zod.number().int().positive().describe('Page height'),
268
307
  },
269
308
  blockedByDialog: false,
309
+ concurrency: 'exclusive',
270
310
  verifyFilesSchema: {},
271
311
  handler: async (request, response) => {
272
312
  const page = request.page;
@@ -310,6 +350,7 @@ export const handleDialog = definePageTool(() => ({
310
350
  .describe('Optional prompt text to enter into the dialog.'),
311
351
  },
312
352
  blockedByDialog: false,
353
+ concurrency: 'page',
313
354
  verifyFilesSchema: {},
314
355
  handler: async (request, response) => {
315
356
  const page = request.page;
@@ -355,6 +396,7 @@ export const getTabId = definePageTool(() => ({
355
396
  },
356
397
  schema: {},
357
398
  blockedByDialog: false,
399
+ concurrency: 'page',
358
400
  verifyFilesSchema: {},
359
401
  handler: async (request, response) => {
360
402
  const page = request.page;
@@ -8,7 +8,7 @@ import { zod, DevTools } from '../third_party/index.js';
8
8
  import { parseRawTraceBuffer, traceResultIsSuccess, } from '../processors/PerformanceTrace.js';
9
9
  import { logger } from '../utils/logger.js';
10
10
  import { ToolCategory } from './categories.js';
11
- import { definePageTool } from './ToolDefinition.js';
11
+ import { definePageTool, } from './ToolDefinition.js';
12
12
  const filePathSchema = zod
13
13
  .string()
14
14
  .optional()
@@ -36,6 +36,7 @@ export const startTrace = definePageTool(() => ({
36
36
  filePath: filePathSchema,
37
37
  },
38
38
  blockedByDialog: true,
39
+ concurrency: 'exclusive',
39
40
  verifyFilesSchema: {
40
41
  filePath: true,
41
42
  },
@@ -44,8 +45,8 @@ export const startTrace = definePageTool(() => ({
44
45
  response.appendResponseLine('Error: a performance trace is already running. Use performance_stop_trace to stop it. Only one trace can be running at any given time.');
45
46
  return;
46
47
  }
47
- context.setIsRunningPerformanceTrace(true);
48
48
  const page = request.page;
49
+ page.setIsRunningPerformanceTrace(true);
49
50
  const pageUrlForTracing = page.pptrPage.url();
50
51
  try {
51
52
  if (request.params.reload) {
@@ -106,7 +107,7 @@ export const startTrace = definePageTool(() => ({
106
107
  catch {
107
108
  // Tracing may not have started yet; ignore.
108
109
  }
109
- context.setIsRunningPerformanceTrace(false);
110
+ page.setIsRunningPerformanceTrace(false);
110
111
  }
111
112
  throw error;
112
113
  }
@@ -123,6 +124,7 @@ export const stopTrace = definePageTool(() => ({
123
124
  filePath: filePathSchema,
124
125
  },
125
126
  blockedByDialog: true,
127
+ concurrency: 'exclusive',
126
128
  verifyFilesSchema: {
127
129
  filePath: true,
128
130
  },
@@ -151,6 +153,7 @@ export const analyzeInsight = definePageTool(() => ({
151
153
  .describe('The name of the Insight you want more information on. For example: "DocumentLatency" or "LCPBreakdown"'),
152
154
  },
153
155
  blockedByDialog: false,
156
+ concurrency: 'exclusive',
154
157
  verifyFilesSchema: {},
155
158
  handler: async (request, response, context) => {
156
159
  const lastRecording = context.recordedTraces().at(-1);
@@ -198,7 +201,7 @@ async function stopTracingAndAppendOutput(page, response, context, filePath) {
198
201
  }
199
202
  }
200
203
  finally {
201
- context.setIsRunningPerformanceTrace(false);
204
+ page.setIsRunningPerformanceTrace(false);
202
205
  }
203
206
  }
204
207
  /** We tell CrUXManager to fetch data so it's available when DevTools.PerformanceTraceFormatter is invoked */
@@ -38,12 +38,16 @@ export const installPwa = defineTool(() => ({
38
38
  displayMode: displayModeSchema,
39
39
  },
40
40
  blockedByDialog: false,
41
+ concurrency: 'exclusive',
41
42
  // We do not validate file paths for remote browser instances
42
43
  // because they are on the remote host and not accessed by the MCP server.
43
44
  verifyFilesSchema: {
44
45
  installUrlOrBundleUrl: {
45
46
  local: true,
46
47
  remote: false,
48
+ // May be an http(s):// or file:// signed web bundle URL handed to the
49
+ // browser, so allow URLs through; a plain path is still validated.
50
+ allowUrl: true,
47
51
  },
48
52
  },
49
53
  handler: async (request, response, context) => {
@@ -71,6 +75,7 @@ export const uninstallPwa = defineTool(() => ({
71
75
  manifestId: manifestIdSchema,
72
76
  },
73
77
  blockedByDialog: false,
78
+ concurrency: 'exclusive',
74
79
  verifyFilesSchema: {},
75
80
  handler: async (request, response, context) => {
76
81
  const { manifestId } = request.params;
@@ -96,6 +101,7 @@ export const launchPwa = defineTool(() => ({
96
101
  .describe('Optional URL within the app to open instead of the default start URL.'),
97
102
  },
98
103
  blockedByDialog: false,
104
+ concurrency: 'exclusive',
99
105
  verifyFilesSchema: {},
100
106
  handler: async (request, response, context) => {
101
107
  const { manifestId, url } = request.params;
@@ -116,6 +122,7 @@ export const getOsAppState = defineTool(() => ({
116
122
  manifestId: manifestIdSchema,
117
123
  },
118
124
  blockedByDialog: false,
125
+ concurrency: 'exclusive',
119
126
  verifyFilesSchema: {},
120
127
  handler: async (request, response, context) => {
121
128
  const { manifestId } = request.params;
@@ -6,7 +6,7 @@
6
6
  import fs from 'node:fs/promises';
7
7
  import os from 'node:os';
8
8
  import path from 'node:path';
9
- import { zod } from '../third_party/index.js';
9
+ import { zod, } from '../third_party/index.js';
10
10
  import { ToolCategory } from './categories.js';
11
11
  import { definePageTool } from './ToolDefinition.js';
12
12
  async function generateTempFilePath() {
@@ -62,6 +62,7 @@ export const startScreencast = definePageTool((args) => ({
62
62
  : 'Output file path (.mp4). Uses mkdtemp to generate a unique path if not provided.'),
63
63
  },
64
64
  blockedByDialog: false,
65
+ concurrency: 'exclusive',
65
66
  verifyFilesSchema: {
66
67
  filePath: true,
67
68
  },
@@ -138,6 +139,7 @@ export const stopScreencast = definePageTool(() => ({
138
139
  },
139
140
  schema: {},
140
141
  blockedByDialog: false,
142
+ concurrency: 'exclusive',
141
143
  verifyFilesSchema: {},
142
144
  handler: async (request, response) => {
143
145
  const page = request.page;
@@ -55,9 +55,10 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
55
55
  var e = new Error(message);
56
56
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
57
57
  });
58
- import { zod } from '../third_party/index.js';
58
+ import { zod, } from '../third_party/index.js';
59
59
  import { ToolCategory } from './categories.js';
60
60
  import { definePageTool } from './ToolDefinition.js';
61
+ const MAX_CHROMIUM_SCREENSHOT_DIMENSION = 16384;
61
62
  async function getSourceBox(page, element, fullPage) {
62
63
  if (element) {
63
64
  const viewport = page.viewport();
@@ -190,6 +191,7 @@ export const screenshot = definePageTool((args) => {
190
191
  .describe('The absolute path, or a path relative to the current working directory, to save the screenshot to instead of attaching it to the response.'),
191
192
  },
192
193
  blockedByDialog: true,
194
+ concurrency: 'page',
193
195
  verifyFilesSchema: {
194
196
  filePath: true,
195
197
  },
@@ -217,12 +219,17 @@ export const screenshot = definePageTool((args) => {
217
219
  // The smaller scale factor wins so both bounds are respected while
218
220
  // preserving aspect ratio.
219
221
  let clip;
220
- if (screenshotMaxWidth !== undefined ||
221
- screenshotMaxHeight !== undefined) {
222
- const box = await getSourceBox(page, element, fullPage);
223
- if (box) {
224
- clip = computeDownscaleClip(box, screenshotMaxWidth, screenshotMaxHeight);
225
- }
222
+ const shouldInspectBox = fullPage ||
223
+ element !== undefined ||
224
+ screenshotMaxWidth !== undefined ||
225
+ screenshotMaxHeight !== undefined;
226
+ const box = shouldInspectBox
227
+ ? await getSourceBox(page, element, fullPage)
228
+ : undefined;
229
+ if (box &&
230
+ (screenshotMaxWidth !== undefined ||
231
+ screenshotMaxHeight !== undefined)) {
232
+ clip = computeDownscaleClip(box, screenshotMaxWidth, screenshotMaxHeight);
226
233
  }
227
234
  if (clip) {
228
235
  // page.screenshot with clip lets the CDP scale param downscale the
@@ -278,6 +285,15 @@ export const screenshot = definePageTool((args) => {
278
285
  data: Buffer.from(screenshot).toString('base64'),
279
286
  });
280
287
  }
288
+ if (box) {
289
+ const effectiveScale = clip?.scale ?? 1;
290
+ const effectiveWidth = box.width * box.devicePixelRatio * effectiveScale;
291
+ const effectiveHeight = box.height * box.devicePixelRatio * effectiveScale;
292
+ if (effectiveWidth > MAX_CHROMIUM_SCREENSHOT_DIMENSION ||
293
+ effectiveHeight > MAX_CHROMIUM_SCREENSHOT_DIMENSION) {
294
+ response.appendResponseLine(`Warning: Screenshot dimensions exceed the maximum capturable dimension of ${MAX_CHROMIUM_SCREENSHOT_DIMENSION}px. Content beyond 16384px may repeat or be corrupted due to browser texture limits. Set --screenshotMaxHeight or --screenshotMaxWidth to downscale.`);
295
+ }
296
+ }
281
297
  }
282
298
  catch (e_1) {
283
299
  env_1.error = e_1;