chrome-devtools-mcp 1.7.0 → 1.8.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 (67) hide show
  1. package/README.md +48 -14
  2. package/build/src/McpContext.js +60 -24
  3. package/build/src/McpPage.js +5 -3
  4. package/build/src/McpResponse.js +22 -4
  5. package/build/src/ToolHandler.js +66 -12
  6. package/build/src/bin/chrome-devtools-mcp-main.js +2 -2
  7. package/build/src/bin/chrome-devtools.js +29 -30
  8. package/build/src/browser.js +3 -1
  9. package/build/src/{PageCollector.js → collectors/PageCollector.js} +7 -7
  10. package/build/src/{ServiceWorkerCollector.js → collectors/ServiceWorkerCollector.js} +1 -1
  11. package/build/src/{bin/chrome-devtools-cli-options.js → config/cli-options.js} +378 -23
  12. package/build/src/{bin/chrome-devtools-mcp-cli-options.js → config/mcp-options.js} +73 -8
  13. package/build/src/daemon/client.js +11 -2
  14. package/build/src/daemon/daemon.js +2 -2
  15. package/build/src/devtools/DevtoolsUtils.js +2 -14
  16. package/build/src/formatters/ConsoleFormatter.js +43 -10
  17. package/build/src/formatters/HeapSnapshotFormatter.js +10 -2
  18. package/build/src/formatters/IssueFormatter.js +1 -1
  19. package/build/src/formatters/NetworkFormatter.js +7 -7
  20. package/build/src/index.js +33 -5
  21. package/build/src/{HeapSnapshotManager.js → processors/HeapSnapshotManager.js} +21 -5
  22. package/build/src/{trace-processing/parse.js → processors/PerformanceTrace.js} +1 -1
  23. package/build/src/telemetry/ClearcutLogger.js +13 -1
  24. package/build/src/telemetry/flagUtils.js +4 -3
  25. package/build/src/telemetry/types.js +4 -0
  26. package/build/src/third_party/THIRD_PARTY_NOTICES +6 -63
  27. package/build/src/third_party/bundled-packages.json +4 -4
  28. package/build/src/third_party/devtools-heap-snapshot-worker.js +274 -42
  29. package/build/src/third_party/index.js +35378 -35538
  30. package/build/src/third_party/issue-descriptions/connectionAllowlistEmbeddingRequirementNotSatisfied.md +26 -0
  31. package/build/src/third_party/issue-descriptions/connectionAllowlistIFrameAttributeLoosensEmbeddingRequirement.md +19 -0
  32. package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidAllowConnectionAllowlistFrom.md +21 -0
  33. package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsBlockedByConnectionAllowlist.md +1 -0
  34. package/build/src/third_party/issue-descriptions/federatedAuthRequestConfigBlockedByConnectionAllowlist.md +1 -0
  35. package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenBlockedByConnectionAllowlist.md +1 -0
  36. package/build/src/third_party/issue-descriptions/federatedAuthRequestWellKnownBlockedByConnectionAllowlist.md +1 -0
  37. package/build/src/tools/categories.js +3 -0
  38. package/build/src/tools/console.js +9 -3
  39. package/build/src/tools/emulation.js +2 -2
  40. package/build/src/tools/extensions.js +7 -5
  41. package/build/src/tools/input.js +26 -16
  42. package/build/src/tools/lighthouse.js +3 -1
  43. package/build/src/tools/memory.js +112 -16
  44. package/build/src/tools/network.js +6 -3
  45. package/build/src/tools/pages.js +12 -16
  46. package/build/src/tools/performance.js +15 -25
  47. package/build/src/tools/pwa.js +128 -0
  48. package/build/src/tools/screencast.js +6 -4
  49. package/build/src/tools/screenshot.js +42 -9
  50. package/build/src/tools/script.js +28 -8
  51. package/build/src/tools/slim/tools.js +3 -3
  52. package/build/src/tools/snapshot.js +5 -3
  53. package/build/src/tools/thirdPartyDeveloper.js +2 -2
  54. package/build/src/tools/tools.js +2 -0
  55. package/build/src/tools/webmcp.js +2 -2
  56. package/build/src/{WaitForHelper.js → utils/WaitForHelper.js} +63 -38
  57. package/build/src/utils/bytes.js +105 -0
  58. package/build/src/utils/logger.js +25 -11
  59. package/build/src/version.js +1 -1
  60. package/package.json +20 -12
  61. package/skills/a11y-debugging/SKILL.md +2 -0
  62. package/skills/chrome-devtools/SKILL.md +5 -4
  63. package/skills/chrome-devtools-cli/SKILL.md +109 -64
  64. package/skills/debug-optimize-lcp/SKILL.md +9 -9
  65. package/skills/memory-leak-debugging/SKILL.md +2 -2
  66. package/skills/troubleshooting/SKILL.md +1 -0
  67. package/build/src/utils/string.js +0 -37
@@ -17,7 +17,7 @@ export const listPages = defineTool(args => {
17
17
  },
18
18
  schema: {},
19
19
  blockedByDialog: false,
20
- verifyFilesSchema: [],
20
+ verifyFilesSchema: {},
21
21
  handler: async (_request, response) => {
22
22
  response.setIncludePages(true);
23
23
  response.setListThirdPartyDeveloperTools();
@@ -42,7 +42,7 @@ export const selectPage = defineTool({
42
42
  .describe('Whether to focus the page and bring it to the top.'),
43
43
  },
44
44
  blockedByDialog: false,
45
- verifyFilesSchema: [],
45
+ verifyFilesSchema: {},
46
46
  handler: async (request, response, context) => {
47
47
  const page = context.getPageById(request.params.pageId);
48
48
  context.selectPage(page);
@@ -67,7 +67,7 @@ export const closePage = defineTool({
67
67
  .describe('The ID of the page to close. Call list_pages to list pages.'),
68
68
  },
69
69
  blockedByDialog: false,
70
- verifyFilesSchema: [],
70
+ verifyFilesSchema: {},
71
71
  handler: async (request, response, context) => {
72
72
  try {
73
73
  await context.closePage(request.params.pageId);
@@ -107,7 +107,7 @@ export const newPage = defineTool(() => {
107
107
  ...timeoutSchema,
108
108
  },
109
109
  blockedByDialog: false,
110
- verifyFilesSchema: [],
110
+ verifyFilesSchema: {},
111
111
  handler: async (request, response, context) => {
112
112
  const page = await context.newPage(request.params.background, request.params.isolatedContext);
113
113
  await page.waitForEventsAfterAction(async () => {
@@ -149,7 +149,7 @@ export const navigatePage = definePageTool(() => {
149
149
  ...timeoutSchema,
150
150
  },
151
151
  blockedByDialog: false,
152
- verifyFilesSchema: [],
152
+ verifyFilesSchema: {},
153
153
  handler: async (request, response) => {
154
154
  const page = request.page;
155
155
  const options = {
@@ -239,7 +239,7 @@ export const navigatePage = definePageTool(() => {
239
239
  });
240
240
  export const resizePage = definePageTool({
241
241
  name: 'resize_page',
242
- description: `Resizes the selected page's window so that the page has specified dimension`,
242
+ description: `Resizes the page's window so that the page has specified dimension`,
243
243
  annotations: {
244
244
  category: ToolCategory.EMULATION,
245
245
  readOnlyHint: false,
@@ -249,7 +249,7 @@ export const resizePage = definePageTool({
249
249
  height: zod.number().describe('Page height'),
250
250
  },
251
251
  blockedByDialog: false,
252
- verifyFilesSchema: [],
252
+ verifyFilesSchema: {},
253
253
  handler: async (request, response) => {
254
254
  const page = request.page;
255
255
  try {
@@ -292,7 +292,7 @@ export const handleDialog = definePageTool({
292
292
  .describe('Optional prompt text to enter into the dialog.'),
293
293
  },
294
294
  blockedByDialog: false,
295
- verifyFilesSchema: [],
295
+ verifyFilesSchema: {},
296
296
  handler: async (request, response) => {
297
297
  const page = request.page;
298
298
  const dialog = page.getDialog();
@@ -335,15 +335,11 @@ export const getTabId = definePageTool({
335
335
  readOnlyHint: true,
336
336
  conditions: ['experimentalInteropTools'],
337
337
  },
338
- schema: {
339
- pageId: zod
340
- .number()
341
- .describe(`The ID of the page to get the tab ID for. Call ${listPages().name} to get available pages.`),
342
- },
338
+ schema: {},
343
339
  blockedByDialog: false,
344
- verifyFilesSchema: [],
345
- handler: async (request, response, context) => {
346
- const page = context.getPageById(request.params.pageId);
340
+ verifyFilesSchema: {},
341
+ handler: async (request, response) => {
342
+ const page = request.page;
347
343
  const tabId = page.pptrPage._tabId;
348
344
  response.setTabId(tabId);
349
345
  response.appendResponseLine(`Tab ID: ${tabId}`);
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import zlib from 'node:zlib';
7
7
  import { zod, DevTools } from '../third_party/index.js';
8
- import { parseRawTraceBuffer, traceResultIsSuccess, } from '../trace-processing/parse.js';
8
+ import { parseRawTraceBuffer, traceResultIsSuccess, } from '../processors/PerformanceTrace.js';
9
9
  import { logger } from '../utils/logger.js';
10
10
  import { ToolCategory } from './categories.js';
11
11
  import { definePageTool } from './ToolDefinition.js';
@@ -15,7 +15,7 @@ const filePathSchema = zod
15
15
  .describe('The absolute file path, or a file path relative to the current working directory, to save the raw trace data. For example, trace.json.gz (compressed) or trace.json (uncompressed).');
16
16
  export const startTrace = definePageTool({
17
17
  name: 'performance_start_trace',
18
- description: `Start a performance trace on the selected webpage. Use to find frontend performance issues, Core Web Vitals (LCP, INP, CLS), and improve page load speed.`,
18
+ description: `Start a performance trace on the target webpage. Use to find frontend performance issues, Core Web Vitals (LCP, INP, CLS), and improve page load speed.`,
19
19
  annotations: {
20
20
  category: ToolCategory.PERFORMANCE,
21
21
  readOnlyHint: false,
@@ -24,7 +24,7 @@ export const startTrace = definePageTool({
24
24
  reload: zod
25
25
  .boolean()
26
26
  .default(true)
27
- .describe('Determines if, once tracing has started, the current selected page should be automatically reloaded. Navigate the page to the right URL using the navigate_page tool BEFORE starting the trace if reload or autoStop is set to true.'),
27
+ .describe('Determines if, once tracing has started, the target page should be automatically reloaded. Navigate the page to the right URL using the navigate_page tool BEFORE starting the trace if reload or autoStop is set to true.'),
28
28
  autoStop: zod
29
29
  .boolean()
30
30
  .default(true)
@@ -32,7 +32,9 @@ export const startTrace = definePageTool({
32
32
  filePath: filePathSchema,
33
33
  },
34
34
  blockedByDialog: true,
35
- verifyFilesSchema: ['filePath'],
35
+ verifyFilesSchema: {
36
+ filePath: true,
37
+ },
36
38
  handler: async (request, response, context) => {
37
39
  if (context.isRunningPerformanceTrace()) {
38
40
  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.');
@@ -49,26 +51,12 @@ export const startTrace = definePageTool({
49
51
  waitUntil: 'load',
50
52
  });
51
53
  }
52
- // Keep in sync with the categories arrays in:
53
- // https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/panels/timeline/TimelineController.ts
54
- // https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/gather/gatherers/trace.js
55
54
  const categories = [
56
55
  '-*',
57
- 'blink.console',
58
- 'blink.user_timing',
59
- 'devtools.timeline',
60
- 'disabled-by-default-devtools.screenshot',
61
- 'disabled-by-default-devtools.timeline',
62
- 'disabled-by-default-devtools.timeline.invalidationTracking',
63
- 'disabled-by-default-devtools.timeline.frame',
64
- 'disabled-by-default-devtools.timeline.stack',
65
- 'disabled-by-default-v8.cpu_profiler',
66
- 'disabled-by-default-v8.cpu_profiler.hires',
67
- 'latencyInfo',
68
- 'loading',
69
- 'disabled-by-default-lighthouse',
70
- 'v8.execute',
71
- 'v8',
56
+ ...DevTools.TracingDefaultCategories,
57
+ // These categories are optional in DevTools, but enabled by default in the DevTools UI, so we enable them here too.
58
+ ...DevTools.TracingOptionalCategories.JsSampling,
59
+ ...DevTools.TracingOptionalCategories.Screenshot,
72
60
  ];
73
61
  await page.pptrPage.tracing.start({
74
62
  categories,
@@ -108,7 +96,7 @@ export const startTrace = definePageTool({
108
96
  });
109
97
  export const stopTrace = definePageTool({
110
98
  name: 'performance_stop_trace',
111
- description: 'Stop the active performance trace recording on the selected webpage.',
99
+ description: 'Stop the active performance trace recording on the target webpage.',
112
100
  annotations: {
113
101
  category: ToolCategory.PERFORMANCE,
114
102
  readOnlyHint: false,
@@ -117,7 +105,9 @@ export const stopTrace = definePageTool({
117
105
  filePath: filePathSchema,
118
106
  },
119
107
  blockedByDialog: true,
120
- verifyFilesSchema: ['filePath'],
108
+ verifyFilesSchema: {
109
+ filePath: true,
110
+ },
121
111
  handler: async (request, response, context) => {
122
112
  if (!context.isRunningPerformanceTrace()) {
123
113
  return;
@@ -142,7 +132,7 @@ export const analyzeInsight = definePageTool({
142
132
  .describe('The name of the Insight you want more information on. For example: "DocumentLatency" or "LCPBreakdown"'),
143
133
  },
144
134
  blockedByDialog: false,
145
- verifyFilesSchema: [],
135
+ verifyFilesSchema: {},
146
136
  handler: async (request, response, context) => {
147
137
  const lastRecording = context.recordedTraces().at(-1);
148
138
  if (!lastRecording) {
@@ -0,0 +1,128 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { zod } from '../third_party/index.js';
7
+ import { ToolCategory } from './categories.js';
8
+ import { defineTool } from './ToolDefinition.js';
9
+ const manifestIdSchema = zod
10
+ .string()
11
+ .describe('The manifest ID of the web app: the resolved `id` member of its manifest. ' +
12
+ 'If `id` is omitted, it defaults to the resolved `start_url` ' +
13
+ '(e.g. "https://example.com/"). See https://w3c.github.io/manifest/#id-member.');
14
+ const displayModeSchema = zod
15
+ .enum(['standalone', 'browser'])
16
+ .optional()
17
+ .describe('Optional user display mode preference applied after install. ' +
18
+ '"standalone" opens the app in its own window; "browser" opens it as a ' +
19
+ 'tab. Installs via the PWA CDP domain default to "browser" because they ' +
20
+ 'do not simulate the install dialog, so pass "standalone" to get an ' +
21
+ 'app-window experience.');
22
+ export const installPwa = defineTool({
23
+ name: 'install_pwa',
24
+ description: 'Installs a Progressive Web App (PWA) identified by its manifest ID. ' +
25
+ 'This installs through the PWA CDP domain without a user gesture or install ' +
26
+ 'dialog. DevTools installs default to browser display mode.',
27
+ annotations: {
28
+ category: ToolCategory.PWA,
29
+ readOnlyHint: false,
30
+ },
31
+ schema: {
32
+ manifestId: manifestIdSchema,
33
+ installUrlOrBundleUrl: zod
34
+ .string()
35
+ .describe('The location of the app or bundle. For a normal site this is the page ' +
36
+ 'URL; for an Isolated Web App it can be a file:// or http(s):// ' +
37
+ 'signed web bundle.'),
38
+ displayMode: displayModeSchema,
39
+ },
40
+ blockedByDialog: false,
41
+ // We do not validate file paths for remote browser instances
42
+ // because they are on the remote host and not accessed by the MCP server.
43
+ verifyFilesSchema: {
44
+ installUrlOrBundleUrl: {
45
+ local: true,
46
+ remote: false,
47
+ },
48
+ },
49
+ handler: async (request, response, context) => {
50
+ const { manifestId, installUrlOrBundleUrl, displayMode } = request.params;
51
+ await context.installPWA({
52
+ manifestId,
53
+ installUrlOrBundleUrl,
54
+ displayMode,
55
+ });
56
+ response.appendResponseLine(`Installed PWA with manifest ID: ${manifestId}`);
57
+ if (displayMode) {
58
+ response.appendResponseLine(`Display mode set to: ${displayMode}`);
59
+ }
60
+ },
61
+ });
62
+ export const uninstallPwa = defineTool({
63
+ name: 'uninstall_pwa',
64
+ description: 'Uninstalls a Progressive Web App identified by its manifest ID and ' +
65
+ 'closes any open app windows.',
66
+ annotations: {
67
+ category: ToolCategory.PWA,
68
+ readOnlyHint: false,
69
+ },
70
+ schema: {
71
+ manifestId: manifestIdSchema,
72
+ },
73
+ blockedByDialog: false,
74
+ verifyFilesSchema: {},
75
+ handler: async (request, response, context) => {
76
+ const { manifestId } = request.params;
77
+ await context.uninstallPWA({ manifestId });
78
+ response.appendResponseLine(`Uninstalled PWA with manifest ID: ${manifestId}`);
79
+ response.setIncludePages(true);
80
+ },
81
+ });
82
+ export const launchPwa = defineTool({
83
+ name: 'launch_pwa',
84
+ description: 'Launches an installed Progressive Web App using its saved display mode. ' +
85
+ 'Optionally opens a specific URL within the same app instead of the default ' +
86
+ 'start URL.',
87
+ annotations: {
88
+ category: ToolCategory.PWA,
89
+ readOnlyHint: false,
90
+ },
91
+ schema: {
92
+ manifestId: manifestIdSchema,
93
+ url: zod
94
+ .string()
95
+ .optional()
96
+ .describe('Optional URL within the app to open instead of the default start URL.'),
97
+ },
98
+ blockedByDialog: false,
99
+ verifyFilesSchema: {},
100
+ handler: async (request, response, context) => {
101
+ const { manifestId, url } = request.params;
102
+ const page = await context.launchPWA({ manifestId, url });
103
+ response.appendResponseLine(`Launched PWA with manifest ID: ${manifestId} (${page.url()})`);
104
+ response.setIncludePages(true);
105
+ },
106
+ });
107
+ export const getOsAppState = defineTool({
108
+ name: 'get_os_app_state',
109
+ description: 'Returns the OS integration state (badge count and registered file ' +
110
+ 'handlers) for an installed web app, identified by its manifest ID.',
111
+ annotations: {
112
+ category: ToolCategory.PWA,
113
+ readOnlyHint: true,
114
+ },
115
+ schema: {
116
+ manifestId: manifestIdSchema,
117
+ },
118
+ blockedByDialog: false,
119
+ verifyFilesSchema: {},
120
+ handler: async (request, response, context) => {
121
+ const { manifestId } = request.params;
122
+ const state = await context.getPWAState({ manifestId });
123
+ response.appendResponseLine(`OS app state for manifest ID: ${manifestId}`);
124
+ response.appendResponseLine(`Badge count: ${state.badgeCount}`);
125
+ response.appendResponseLine(`File handlers: ${JSON.stringify(state.fileHandlers)}`);
126
+ },
127
+ });
128
+ //# sourceMappingURL=pwa.js.map
@@ -16,7 +16,7 @@ async function generateTempFilePath() {
16
16
  const supportedExtensions = ['.webm', '.mp4'];
17
17
  export const startScreencast = definePageTool(args => ({
18
18
  name: 'screencast_start',
19
- description: `Starts recording a screencast (video) of the selected page in specified format.`,
19
+ description: `Starts recording a screencast (video) of the target page in specified format.`,
20
20
  annotations: {
21
21
  category: ToolCategory.DEBUGGING,
22
22
  readOnlyHint: false,
@@ -29,7 +29,9 @@ export const startScreencast = definePageTool(args => ({
29
29
  .describe(`Output file path (${supportedExtensions.join(',')} are supported). Uses mkdtemp to generate a unique path if not provided.`),
30
30
  },
31
31
  blockedByDialog: false,
32
- verifyFilesSchema: ['filePath'],
32
+ verifyFilesSchema: {
33
+ filePath: true,
34
+ },
33
35
  handler: async (request, response, context) => {
34
36
  if (context.getScreenRecorder() !== null) {
35
37
  response.appendResponseLine('Error: a screencast recording is already in progress. Use screencast_stop to stop it before starting a new one.');
@@ -89,7 +91,7 @@ export const startScreencast = definePageTool(args => ({
89
91
  }));
90
92
  export const stopScreencast = definePageTool({
91
93
  name: 'screencast_stop',
92
- description: 'Stops the active screencast recording on the selected page.',
94
+ description: 'Stops the active screencast recording on the target page.',
93
95
  annotations: {
94
96
  category: ToolCategory.DEBUGGING,
95
97
  readOnlyHint: false,
@@ -97,7 +99,7 @@ export const stopScreencast = definePageTool({
97
99
  },
98
100
  schema: {},
99
101
  blockedByDialog: false,
100
- verifyFilesSchema: [],
102
+ verifyFilesSchema: {},
101
103
  handler: async (_request, response, context) => {
102
104
  const data = context.getScreenRecorder();
103
105
  if (!data) {
@@ -60,22 +60,41 @@ import { ToolCategory } from './categories.js';
60
60
  import { definePageTool } from './ToolDefinition.js';
61
61
  async function getSourceBox(page, element, fullPage) {
62
62
  if (element) {
63
- const box = await element.boundingBox();
64
- return box ?? undefined;
63
+ const viewport = page.viewport();
64
+ const [box, devicePixelRatio] = await Promise.all([
65
+ element.boundingBox(),
66
+ viewport
67
+ ? (viewport.deviceScaleFactor ?? 1)
68
+ : page.evaluate(() => window.devicePixelRatio),
69
+ ]);
70
+ return box ? { ...box, devicePixelRatio } : undefined;
65
71
  }
66
72
  if (fullPage) {
67
73
  const dims = await page.evaluate(() => ({
68
74
  width: Math.max(document.documentElement.scrollWidth, document.body?.scrollWidth ?? 0),
69
75
  height: Math.max(document.documentElement.scrollHeight, document.body?.scrollHeight ?? 0),
76
+ devicePixelRatio: window.devicePixelRatio,
70
77
  }));
71
78
  if (dims.width <= 0 || dims.height <= 0) {
72
79
  return undefined;
73
80
  }
74
- return { x: 0, y: 0, width: dims.width, height: dims.height };
81
+ return {
82
+ x: 0,
83
+ y: 0,
84
+ width: dims.width,
85
+ height: dims.height,
86
+ devicePixelRatio: dims.devicePixelRatio,
87
+ };
75
88
  }
76
89
  const viewport = page.viewport();
77
90
  if (viewport) {
78
- return { x: 0, y: 0, width: viewport.width, height: viewport.height };
91
+ return {
92
+ x: 0,
93
+ y: 0,
94
+ width: viewport.width,
95
+ height: viewport.height,
96
+ devicePixelRatio: viewport.deviceScaleFactor ?? 1,
97
+ };
79
98
  }
80
99
  // The browser is launched and connected with `defaultViewport: null`, so
81
100
  // `page.viewport()` stays null until something emulates one. Fall back to the
@@ -83,21 +102,33 @@ async function getSourceBox(page, element, fullPage) {
83
102
  const dims = await page.evaluate(() => ({
84
103
  width: window.innerWidth,
85
104
  height: window.innerHeight,
105
+ devicePixelRatio: window.devicePixelRatio,
86
106
  }));
87
107
  if (dims.width <= 0 || dims.height <= 0) {
88
108
  return undefined;
89
109
  }
90
- return { x: 0, y: 0, width: dims.width, height: dims.height };
110
+ return {
111
+ x: 0,
112
+ y: 0,
113
+ width: dims.width,
114
+ height: dims.height,
115
+ devicePixelRatio: dims.devicePixelRatio,
116
+ };
91
117
  }
92
118
  function computeDownscaleClip(box, maxWidth, maxHeight) {
93
- const widthScale = maxWidth !== undefined ? Math.min(1, maxWidth / box.width) : 1;
94
- const heightScale = maxHeight !== undefined ? Math.min(1, maxHeight / box.height) : 1;
119
+ const widthScale = maxWidth !== undefined
120
+ ? Math.min(1, maxWidth / (box.width * box.devicePixelRatio))
121
+ : 1;
122
+ const heightScale = maxHeight !== undefined
123
+ ? Math.min(1, maxHeight / (box.height * box.devicePixelRatio))
124
+ : 1;
95
125
  const scale = Math.min(widthScale, heightScale);
96
126
  if (scale >= 1) {
97
127
  return undefined;
98
128
  }
99
129
  // Skip degenerate sub-pixel results.
100
- if (Math.round(box.width * scale) < 1 || Math.round(box.height * scale) < 1) {
130
+ if (Math.round(box.width * box.devicePixelRatio * scale) < 1 ||
131
+ Math.round(box.height * box.devicePixelRatio * scale) < 1) {
101
132
  return undefined;
102
133
  }
103
134
  return {
@@ -144,7 +175,9 @@ export const screenshot = definePageTool(args => {
144
175
  .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.'),
145
176
  },
146
177
  blockedByDialog: true,
147
- verifyFilesSchema: ['filePath'],
178
+ verifyFilesSchema: {
179
+ filePath: true,
180
+ },
148
181
  handler: async (request, response, context) => {
149
182
  const env_1 = { stack: [], error: void 0, hasError: false };
150
183
  try {
@@ -61,14 +61,23 @@ import { defineTool, pageIdSchema } from './ToolDefinition.js';
61
61
  export const evaluateScript = defineTool(cliArgs => {
62
62
  return {
63
63
  name: 'evaluate_script',
64
- 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.`,
64
+ description: `Evaluate a JavaScript function inside the target page${cliArgs?.categoryExtensions ? ' or service worker' : ''}. Returns the response as JSON, so returned values have to be JSON-serializable.`,
65
65
  annotations: {
66
66
  category: ToolCategory.DEBUGGING,
67
67
  readOnlyHint: false,
68
68
  },
69
69
  schema: {
70
- ...(cliArgs?.experimentalPageIdRouting ? pageIdSchema : {}),
71
- function: zod.string().describe(`A JavaScript function declaration to be executed by the tool in the currently selected page.
70
+ ...(cliArgs?.pageIdRouting
71
+ ? cliArgs.categoryExtensions
72
+ ? {
73
+ pageId: zod
74
+ .number()
75
+ .optional()
76
+ .describe('Targets a specific page by ID. Required when not evaluating in a service worker.'),
77
+ }
78
+ : pageIdSchema
79
+ : {}),
80
+ function: zod.string().describe(`A JavaScript function declaration to be executed by the tool in the target page.
72
81
  Example without arguments: \`() => document.title\` or \`async () => await fetch("example.com")\`.
73
82
  Example with arguments: \`(el) => el.innerText\`
74
83
  `),
@@ -86,6 +95,10 @@ Example with arguments: \`(el) => el.innerText\`
86
95
  .string()
87
96
  .optional()
88
97
  .describe('Handle dialogs while execution. "accept", "dismiss", or string for response of window.prompt. Defaults to accept.'),
98
+ waitForStableDom: zod
99
+ .boolean()
100
+ .optional()
101
+ .describe('Whether to wait for the DOM to settle. Pass false if the script only reads data. Defaults to true.'),
89
102
  ...(cliArgs?.categoryExtensions
90
103
  ? {
91
104
  serviceWorkerId: zod
@@ -96,11 +109,13 @@ Example with arguments: \`(el) => el.innerText\`
96
109
  : {}),
97
110
  },
98
111
  blockedByDialog: true,
99
- verifyFilesSchema: ['filePath'],
112
+ verifyFilesSchema: {
113
+ filePath: true,
114
+ },
100
115
  handler: async (request, response, context) => {
101
116
  const env_1 = { stack: [], error: void 0, hasError: false };
102
117
  try {
103
- const { serviceWorkerId, args: uidArgs, function: fnString, pageId, dialogAction, filePath, } = request.params;
118
+ const { serviceWorkerId, args: uidArgs, function: fnString, pageId, dialogAction, filePath, waitForStableDom, } = request.params;
104
119
  if (cliArgs?.categoryExtensions && serviceWorkerId) {
105
120
  if (uidArgs && uidArgs.length > 0) {
106
121
  throw new Error('args (element uids) cannot be used when evaluating in a service worker.');
@@ -116,14 +131,19 @@ Example with arguments: \`(el) => el.innerText\`
116
131
  filePath,
117
132
  context,
118
133
  });
119
- }, { handleDialog: dialogAction ?? 'accept' });
134
+ },
135
+ // Service workers cannot interact with the DOM, so never wait for it.
136
+ { handleDialog: dialogAction ?? 'accept', waitForStableDom: false });
120
137
  if (result.dialogHandled) {
121
138
  context.getSelectedMcpPage().clearDialog();
122
139
  }
123
140
  response.attachWaitForResult(result);
124
141
  return;
125
142
  }
126
- const mcpPage = cliArgs?.experimentalPageIdRouting
143
+ if (cliArgs?.categoryExtensions && cliArgs?.pageIdRouting && !pageId) {
144
+ throw new Error('specify either a pageId or a serviceWorkerId.');
145
+ }
146
+ const mcpPage = cliArgs?.pageIdRouting && request.params.pageId
127
147
  ? context.getPageById(request.params.pageId)
128
148
  : context.getSelectedMcpPage();
129
149
  const page = mcpPage.pptrPage;
@@ -142,7 +162,7 @@ Example with arguments: \`(el) => el.innerText\`
142
162
  filePath,
143
163
  context,
144
164
  });
145
- }, { handleDialog: dialogAction ?? 'accept' });
165
+ }, { handleDialog: dialogAction ?? 'accept', waitForStableDom });
146
166
  response.attachWaitForResult(result);
147
167
  }
148
168
  catch (e_1) {
@@ -16,7 +16,7 @@ export const screenshot = definePageTool({
16
16
  },
17
17
  schema: {},
18
18
  blockedByDialog: true,
19
- verifyFilesSchema: [],
19
+ verifyFilesSchema: {},
20
20
  handler: async (request, response, context) => {
21
21
  const page = request.page;
22
22
  const screenshot = await page.pptrPage.screenshot({
@@ -38,7 +38,7 @@ export const navigate = definePageTool({
38
38
  url: zod.string().describe('URL to navigate to'),
39
39
  },
40
40
  blockedByDialog: false,
41
- verifyFilesSchema: [],
41
+ verifyFilesSchema: {},
42
42
  handler: async (request, response) => {
43
43
  const page = request.page;
44
44
  const options = {
@@ -73,7 +73,7 @@ export const evaluate = definePageTool({
73
73
  script: zod.string().describe(`JS script to run on the page`),
74
74
  },
75
75
  blockedByDialog: true,
76
- verifyFilesSchema: [],
76
+ verifyFilesSchema: {},
77
77
  handler: async (request, response) => {
78
78
  const page = request.page;
79
79
  try {
@@ -8,7 +8,7 @@ import { ToolCategory } from './categories.js';
8
8
  import { definePageTool, timeoutSchema } from './ToolDefinition.js';
9
9
  export const takeSnapshot = definePageTool({
10
10
  name: 'take_snapshot',
11
- description: `Take a text snapshot of the currently selected page based on the a11y tree. The snapshot lists page elements along with a unique
11
+ description: `Take a text snapshot of the target page based on the a11y tree. The snapshot lists page elements along with a unique
12
12
  identifier (uid). Always use the latest snapshot. Prefer taking a snapshot over taking a screenshot. The snapshot indicates the element selected
13
13
  in the DevTools Elements panel (if any).`,
14
14
  annotations: {
@@ -27,7 +27,9 @@ in the DevTools Elements panel (if any).`,
27
27
  .describe('The absolute path, or a path relative to the current working directory, to save the snapshot to instead of attaching it to the response.'),
28
28
  },
29
29
  blockedByDialog: true,
30
- verifyFilesSchema: ['filePath'],
30
+ verifyFilesSchema: {
31
+ filePath: true,
32
+ },
31
33
  handler: async (request, response) => {
32
34
  response.includeSnapshot({
33
35
  verbose: request.params.verbose ?? false,
@@ -50,7 +52,7 @@ export const waitFor = definePageTool({
50
52
  ...timeoutSchema,
51
53
  },
52
54
  blockedByDialog: true,
53
- verifyFilesSchema: [],
55
+ verifyFilesSchema: {},
54
56
  handler: async (request, response) => {
55
57
  const page = request.page;
56
58
  await page.waitForTextOnPage(request.params.text, request.params.timeout);
@@ -21,7 +21,7 @@ third-party developer tools with additional functionality.`,
21
21
  },
22
22
  schema: {},
23
23
  blockedByDialog: false,
24
- verifyFilesSchema: [],
24
+ verifyFilesSchema: {},
25
25
  handler: async (_request, response) => {
26
26
  response.setListThirdPartyDeveloperTools();
27
27
  },
@@ -41,7 +41,7 @@ export const executeThirdPartyDeveloperTool = definePageTool({
41
41
  .describe('The JSON-stringified parameters to pass to the tool'),
42
42
  },
43
43
  blockedByDialog: false,
44
- verifyFilesSchema: [],
44
+ verifyFilesSchema: {},
45
45
  handler: async (request, response) => {
46
46
  const toolName = request.params.toolName;
47
47
  let params = {};
@@ -12,6 +12,7 @@ import * as memoryTools from './memory.js';
12
12
  import * as networkTools from './network.js';
13
13
  import * as pagesTools from './pages.js';
14
14
  import * as performanceTools from './performance.js';
15
+ import * as pwaTools from './pwa.js';
15
16
  import * as screencastTools from './screencast.js';
16
17
  import * as screenshotTools from './screenshot.js';
17
18
  import * as scriptTools from './script.js';
@@ -32,6 +33,7 @@ export const createTools = (args) => {
32
33
  ...Object.values(networkTools),
33
34
  ...Object.values(pagesTools),
34
35
  ...Object.values(performanceTools),
36
+ ...Object.values(pwaTools),
35
37
  ...Object.values(screencastTools),
36
38
  ...Object.values(screenshotTools),
37
39
  ...Object.values(scriptTools),
@@ -15,7 +15,7 @@ export const listWebMcpTools = definePageTool({
15
15
  },
16
16
  schema: {},
17
17
  blockedByDialog: false,
18
- verifyFilesSchema: [],
18
+ verifyFilesSchema: {},
19
19
  handler: async (_request, response) => {
20
20
  response.setListWebMcpTools();
21
21
  },
@@ -35,7 +35,7 @@ export const executeWebMcpTool = definePageTool({
35
35
  .describe('The JSON-stringified parameters to pass to the WebMCP tool'),
36
36
  },
37
37
  blockedByDialog: false,
38
- verifyFilesSchema: [],
38
+ verifyFilesSchema: {},
39
39
  handler: async (request, response) => {
40
40
  const toolName = request.params.toolName;
41
41
  let input = {};