chrome-devtools-mcp 1.10.1 → 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.
- package/README.md +72 -20
- package/build/src/BrowserManager.js +155 -27
- package/build/src/McpContext.js +598 -200
- package/build/src/McpPage.js +513 -131
- package/build/src/McpResponse.js +291 -116
- package/build/src/McpWorker.js +66 -0
- package/build/src/SlimMcpResponse.js +5 -1
- package/build/src/TextSnapshot.js +40 -20
- package/build/src/ToolHandler.js +306 -147
- package/build/src/bin/chrome-devtools-mcp-main.js +13 -10
- package/build/src/bin/chrome-devtools-mcp.js +1 -1
- package/build/src/bin/chrome-devtools.js +34 -44
- package/build/src/collectors/PageCollector.js +13 -9
- package/build/src/collectors/ServiceWorkerCollector.js +20 -13
- package/build/src/collectors/constants.js +7 -0
- package/build/src/config/ConfigLocator.js +70 -0
- package/build/src/config/ConfigParser.js +159 -0
- package/build/src/config/ConfigWatcher.js +94 -0
- package/build/src/config/ServerConfig.js +251 -0
- package/build/src/config/browser-options.js +15 -17
- package/build/src/config/category-options.js +15 -30
- package/build/src/config/cli-commands.js +165 -5
- package/build/src/config/cli-options.js +441 -58
- package/build/src/config/mcp-options.js +212 -264
- package/build/src/config/puppeteer-options.js +67 -0
- package/build/src/config/tool-options.js +60 -0
- package/build/src/daemon/client.js +84 -44
- package/build/src/daemon/daemon.js +59 -45
- package/build/src/daemon/utils.js +46 -12
- package/build/src/devtools/DevToolsCommentBridge.js +71 -11
- package/build/src/devtools/DevtoolsUtils.js +52 -15
- package/build/src/devtools/McpHostBindingAdapter.js +0 -1
- package/build/src/formatters/CommentFormatter.js +4 -13
- package/build/src/formatters/ConsoleFormatter.js +29 -2
- package/build/src/formatters/CssFormatter.js +3 -2
- package/build/src/formatters/HeapSnapshotFormatter.js +111 -57
- package/build/src/formatters/IssueFormatter.js +33 -32
- package/build/src/formatters/NetworkFormatter.js +62 -22
- package/build/src/formatters/RemoteObjectFormatter.js +231 -0
- package/build/src/formatters/SnapshotFormatter.js +44 -7
- package/build/src/index.js +285 -88
- package/build/src/processors/ChunkedTraceParser.js +11 -11
- package/build/src/processors/HeapSnapshotManager.js +455 -156
- package/build/src/processors/PerformanceTrace.js +9 -9
- package/build/src/telemetry/ClearcutLogger.js +1 -1
- package/build/src/telemetry/transformation.js +7 -11
- package/build/src/telemetry/watchdog/main.js +1 -1
- package/build/src/third_party/THIRD_PARTY_NOTICES +399 -689
- package/build/src/third_party/bundled-packages.json +7 -8
- package/build/src/third_party/cli.js +9239 -0
- package/build/src/third_party/devtools-formatter-worker.js +4299 -2517
- package/build/src/third_party/devtools-heap-snapshot-worker.js +1298 -22
- package/build/src/third_party/index.js +132003 -146852
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantRead.md +0 -1
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantReadOptOut.md +5 -0
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSet.md +0 -1
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSetOptOut.md +5 -0
- package/build/src/third_party/issue-descriptions/deprecation.md +1 -1
- package/build/src/third_party/issue-descriptions/genericGeolocationPromptWithoutUserGesture.md +5 -0
- package/build/src/third_party/issue-descriptions/sriValidationFailedIntegrityMismatch.md +2 -0
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +54576 -52174
- package/build/src/tools/ToolDefinition.js +102 -12
- package/build/src/tools/comments.js +62 -4
- package/build/src/tools/console.js +6 -4
- package/build/src/tools/css.js +5 -2
- package/build/src/tools/emulation.js +22 -8
- package/build/src/tools/extensions.js +5 -0
- package/build/src/tools/input.js +29 -9
- package/build/src/tools/lighthouse.js +136 -12
- package/build/src/tools/memory.js +166 -59
- package/build/src/tools/network.js +5 -4
- package/build/src/tools/pages.js +52 -7
- package/build/src/tools/performance.js +28 -7
- package/build/src/tools/pwa.js +7 -0
- package/build/src/tools/screencast.js +74 -33
- package/build/src/tools/screenshot.js +52 -21
- package/build/src/tools/script.js +125 -40
- package/build/src/tools/slim/tools.js +27 -13
- package/build/src/tools/snapshot.js +13 -3
- package/build/src/tools/thirdPartyDeveloper.js +9 -5
- package/build/src/tools/tools.js +35 -22
- package/build/src/tools/webmcp.js +11 -6
- package/build/src/types.js +11 -0
- package/build/src/utils/TaskRunner.js +136 -0
- package/build/src/utils/WaitForHelper.js +15 -2
- package/build/src/utils/bytes.js +2 -12
- package/build/src/utils/check-for-updates.js +2 -2
- package/build/src/utils/disclaimers.js +27 -0
- package/build/src/utils/errorHandling.js +20 -0
- package/build/src/utils/keyboard.js +14 -2
- package/build/src/utils/logger.js +84 -5
- package/build/src/utils/resourceType.js +27 -0
- package/build/src/utils/text.js +44 -0
- package/build/src/utils/timeout.js +14 -0
- package/build/src/utils/url.js +140 -3
- package/build/src/version.js +1 -1
- package/package.json +16 -11
- package/skills/a11y-debugging/SKILL.md +7 -12
- package/skills/chrome-devtools/SKILL.md +2 -2
- package/skills/chrome-devtools-cli/SKILL.md +18 -15
- package/skills/cookie-debugging/SKILL.md +8 -5
- package/skills/debug-optimize-lcp/SKILL.md +1 -1
- package/skills/troubleshooting/SKILL.md +5 -6
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { categoryToFlagName } from '../config/category-options.js';
|
|
7
|
+
import { zod, } from '../third_party/index.js';
|
|
7
8
|
export function defineTool(definition) {
|
|
8
9
|
return definition;
|
|
9
10
|
}
|
|
@@ -13,62 +14,125 @@ export function definePageTool(definition) {
|
|
|
13
14
|
return {
|
|
14
15
|
...tool,
|
|
15
16
|
schema: {
|
|
16
|
-
...(args.pageIdRouting && !
|
|
17
|
+
...(args.pageIdRouting && !isSlimTool(tool) ? pageIdSchema : {}),
|
|
17
18
|
...tool.schema,
|
|
18
19
|
},
|
|
19
20
|
pageScoped: true,
|
|
20
21
|
};
|
|
21
22
|
};
|
|
22
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Defines a tool that does not need a browser connection, e.g. a tool that only
|
|
26
|
+
* analyzes local files. Its handler only receives a {@link BrowserlessContext}.
|
|
27
|
+
* Such a tool runs without the context queue (`concurrency: 'none'`) unless
|
|
28
|
+
* the definition sets another value.
|
|
29
|
+
*/
|
|
30
|
+
export function defineBrowserlessTool(definition) {
|
|
31
|
+
return (args) => {
|
|
32
|
+
return {
|
|
33
|
+
concurrency: 'none',
|
|
34
|
+
...definition(args),
|
|
35
|
+
browserless: true,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function isPageScopedTool(tool) {
|
|
40
|
+
return 'pageScoped' in tool && tool.pageScoped === true;
|
|
41
|
+
}
|
|
42
|
+
export function isBrowserlessTool(tool) {
|
|
43
|
+
return 'browserless' in tool && tool.browserless === true;
|
|
44
|
+
}
|
|
23
45
|
export const CLOSE_PAGE_ERROR = 'The last open page cannot be closed. It is fine to keep it open.';
|
|
24
46
|
export const pageIdSchema = {
|
|
25
47
|
pageId: zod.number().describe('Targets a specific page by ID.'),
|
|
26
48
|
};
|
|
49
|
+
export function zodTransform(transform) {
|
|
50
|
+
return (arg, ctx) => {
|
|
51
|
+
try {
|
|
52
|
+
return transform(arg);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
ctx.addIssue({
|
|
56
|
+
code: 'custom',
|
|
57
|
+
message: error instanceof Error ? error.message : String(error),
|
|
58
|
+
});
|
|
59
|
+
return zod.NEVER;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
27
63
|
export const timeoutSchema = {
|
|
28
64
|
timeout: zod
|
|
29
65
|
.number()
|
|
30
66
|
.int()
|
|
31
|
-
.transform(value => {
|
|
67
|
+
.transform(zodTransform(value => {
|
|
32
68
|
return value <= 0 ? undefined : value;
|
|
33
|
-
})
|
|
69
|
+
}))
|
|
34
70
|
.optional()
|
|
35
71
|
.describe(`Maximum wait time in milliseconds. If set to 0, the default timeout will be used.`),
|
|
36
72
|
};
|
|
73
|
+
const DECIMAL = /^[+-]?(\d+(\.\d*)?|\.\d+)$/;
|
|
74
|
+
const VALID_VIEWPORT_TAGS = new Set(['mobile', 'touch', 'landscape']);
|
|
75
|
+
function parseDecimal(part, name) {
|
|
76
|
+
if (part === undefined || !DECIMAL.test(part)) {
|
|
77
|
+
throw new Error(`Invalid ${name} "${part ?? ''}". Expected a decimal number.`);
|
|
78
|
+
}
|
|
79
|
+
return Number(part);
|
|
80
|
+
}
|
|
37
81
|
export function viewportTransform(arg) {
|
|
38
82
|
if (!arg) {
|
|
39
83
|
return undefined;
|
|
40
84
|
}
|
|
41
85
|
const [dimensions, ...tags] = arg.split(',');
|
|
86
|
+
for (const tag of tags) {
|
|
87
|
+
if (!VALID_VIEWPORT_TAGS.has(tag)) {
|
|
88
|
+
throw new Error(`Invalid viewport tag "${tag}". Expected format '<width>x<height>x<devicePixelRatio>[,mobile][,touch][,landscape]'.`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
42
91
|
const isMobile = tags.includes('mobile');
|
|
43
92
|
const hasTouch = tags.includes('touch');
|
|
44
93
|
const isLandscape = tags.includes('landscape');
|
|
45
|
-
const
|
|
94
|
+
const dimParts = dimensions.split('x');
|
|
95
|
+
if (dimParts.length !== 2 && dimParts.length !== 3) {
|
|
96
|
+
throw new Error(`Invalid viewport dimensions "${dimensions}". Expected format '<width>x<height>x<devicePixelRatio>[,mobile][,touch][,landscape]'.`);
|
|
97
|
+
}
|
|
98
|
+
const width = parseDecimal(dimParts[0], 'viewport width');
|
|
46
99
|
if (!Number.isFinite(width) || width <= 0) {
|
|
47
100
|
throw new Error(`Invalid viewport width "${width}". Expected format '<width>x<height>x<devicePixelRatio>[,mobile][,touch][,landscape]' with a positive width.`);
|
|
48
101
|
}
|
|
102
|
+
const height = parseDecimal(dimParts[1], 'viewport height');
|
|
49
103
|
if (!Number.isFinite(height) || height <= 0) {
|
|
50
104
|
throw new Error(`Invalid viewport height "${height}". Expected format '<width>x<height>x<devicePixelRatio>[,mobile][,touch][,landscape]' with a positive height.`);
|
|
51
105
|
}
|
|
52
|
-
|
|
53
|
-
|
|
106
|
+
let deviceScaleFactor;
|
|
107
|
+
if (dimParts.length === 3) {
|
|
108
|
+
const dpr = parseDecimal(dimParts[2], 'devicePixelRatio');
|
|
109
|
+
if (!Number.isFinite(dpr) || dpr <= 0) {
|
|
110
|
+
throw new Error(`Invalid devicePixelRatio "${dpr}". Expected a positive number.`);
|
|
111
|
+
}
|
|
112
|
+
deviceScaleFactor = dpr;
|
|
54
113
|
}
|
|
55
114
|
return {
|
|
56
115
|
width,
|
|
57
116
|
height,
|
|
58
|
-
deviceScaleFactor
|
|
59
|
-
isMobile
|
|
60
|
-
isLandscape
|
|
61
|
-
hasTouch
|
|
117
|
+
deviceScaleFactor,
|
|
118
|
+
isMobile,
|
|
119
|
+
isLandscape,
|
|
120
|
+
hasTouch,
|
|
62
121
|
};
|
|
63
122
|
}
|
|
64
123
|
export function geolocationTransform(arg) {
|
|
65
124
|
if (!arg) {
|
|
66
125
|
return undefined;
|
|
67
126
|
}
|
|
68
|
-
const
|
|
127
|
+
const parts = arg.split(',');
|
|
128
|
+
if (parts.length !== 2) {
|
|
129
|
+
throw new Error(`Invalid geolocation "${arg}". Expected '<latitude>,<longitude>'.`);
|
|
130
|
+
}
|
|
131
|
+
const latitude = parseDecimal(parts[0], 'latitude');
|
|
69
132
|
if (!Number.isFinite(latitude) || latitude < -90 || latitude > 90) {
|
|
70
133
|
throw new Error(`Invalid latitude "${latitude}". Latitude must be a number between -90 and 90.`);
|
|
71
134
|
}
|
|
135
|
+
const longitude = parseDecimal(parts[1], 'longitude');
|
|
72
136
|
if (!Number.isFinite(longitude) || longitude < -180 || longitude > 180) {
|
|
73
137
|
throw new Error(`Invalid longitude "${longitude}". Longitude must be a number between -180 and 180.`);
|
|
74
138
|
}
|
|
@@ -77,4 +141,30 @@ export function geolocationTransform(arg) {
|
|
|
77
141
|
longitude,
|
|
78
142
|
};
|
|
79
143
|
}
|
|
144
|
+
export function isSlimTool(tool) {
|
|
145
|
+
return Boolean(tool.annotations.conditions?.includes('slim'));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Slim mode replaces the regular tools with the slim tools.
|
|
149
|
+
*/
|
|
150
|
+
export function isAvailableInMode(tool, serverArgs) {
|
|
151
|
+
return isSlimTool(tool) === Boolean(serverArgs.slim);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Returns whether a capability gate is enabled under the given arguments.
|
|
155
|
+
*/
|
|
156
|
+
export function isCapabilityEnabled(gate, serverArgs) {
|
|
157
|
+
if (Boolean(gate.conditions?.includes('slim')) !== Boolean(serverArgs.slim)) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
if (gate.category && !serverArgs[categoryToFlagName(gate.category)]) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
for (const condition of gate.conditions ?? []) {
|
|
164
|
+
if (!serverArgs[condition]) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
80
170
|
//# sourceMappingURL=ToolDefinition.js.map
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { zod } from '../third_party/index.js';
|
|
7
7
|
import { ToolCategory } from './categories.js';
|
|
8
8
|
import { definePageTool } from './ToolDefinition.js';
|
|
9
|
+
const DEVTOOLS_COMMENTS_UNAVAILABLE_MESSAGE = 'DevTools comments are not working right now. Possible reasons: the connected Chrome version does not support DevTools comments, the feature is disabled, or the DevTools window has not finished loading. Try again later, or continue without DevTools comments.';
|
|
9
10
|
export const openDevtools = definePageTool(() => ({
|
|
10
11
|
name: 'open_devtools',
|
|
11
12
|
description: 'Open a DevTools window for the selected page.',
|
|
@@ -16,6 +17,7 @@ export const openDevtools = definePageTool(() => ({
|
|
|
16
17
|
},
|
|
17
18
|
schema: {},
|
|
18
19
|
blockedByDialog: false,
|
|
20
|
+
concurrency: 'exclusive',
|
|
19
21
|
verifyFilesSchema: [],
|
|
20
22
|
handler: async (request, response) => {
|
|
21
23
|
const page = request.page;
|
|
@@ -30,16 +32,33 @@ export const openDevtools = definePageTool(() => ({
|
|
|
30
32
|
response.setIncludePages(true);
|
|
31
33
|
},
|
|
32
34
|
}));
|
|
35
|
+
const DEFAULT_COMMENT_WAIT_MS = 10_000;
|
|
36
|
+
const MAX_COMMENT_WAIT_MS = 30_000;
|
|
33
37
|
export const getDevtoolsComments = definePageTool(() => ({
|
|
34
38
|
name: 'get_devtools_comments',
|
|
35
|
-
description: 'Retrieve user comments from the DevTools window for the page.'
|
|
39
|
+
description: 'Retrieve user comments from the DevTools window for the page. ' +
|
|
40
|
+
'If no comment is pending, waits up to `timeout` ms for the user to send one, then returns. ' +
|
|
41
|
+
'Call it again to keep waiting.',
|
|
36
42
|
annotations: {
|
|
37
43
|
category: ToolCategory.DEBUGGING,
|
|
38
44
|
readOnlyHint: true,
|
|
39
45
|
conditions: ['devtoolsComments'],
|
|
40
46
|
},
|
|
41
|
-
schema: {
|
|
47
|
+
schema: {
|
|
48
|
+
timeout: zod
|
|
49
|
+
.number()
|
|
50
|
+
.int()
|
|
51
|
+
.min(0)
|
|
52
|
+
.max(MAX_COMMENT_WAIT_MS)
|
|
53
|
+
.optional()
|
|
54
|
+
.describe(`Maximum time in milliseconds to wait for a new comment when none is pending. ` +
|
|
55
|
+
`Defaults to ${DEFAULT_COMMENT_WAIT_MS}, maximum ${MAX_COMMENT_WAIT_MS}. ` +
|
|
56
|
+
`Set to 0 to return immediately without waiting.`),
|
|
57
|
+
},
|
|
42
58
|
blockedByDialog: false,
|
|
59
|
+
// The handler only reads page state and waits for comment events, so it
|
|
60
|
+
// runs outside the task runner and other tools run during the wait.
|
|
61
|
+
concurrency: 'none',
|
|
43
62
|
verifyFilesSchema: {},
|
|
44
63
|
handler: async (request, response) => {
|
|
45
64
|
const page = request.page;
|
|
@@ -49,7 +68,30 @@ export const getDevtoolsComments = definePageTool(() => ({
|
|
|
49
68
|
return;
|
|
50
69
|
}
|
|
51
70
|
const bridge = await page.ensureDevToolsCommentBridge(devtoolsPage);
|
|
52
|
-
|
|
71
|
+
if (!bridge) {
|
|
72
|
+
response.appendResponseLine(DEVTOOLS_COMMENTS_UNAVAILABLE_MESSAGE);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const timeout = request.params.timeout ?? DEFAULT_COMMENT_WAIT_MS;
|
|
76
|
+
const start = Date.now();
|
|
77
|
+
const deadline = start + timeout;
|
|
78
|
+
let threads = await bridge.getComments(devtoolsPage);
|
|
79
|
+
while (threads.length === 0) {
|
|
80
|
+
const remaining = deadline - Date.now();
|
|
81
|
+
if (remaining <= 0) {
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
const changed = await bridge.waitForCommentEvent(remaining);
|
|
85
|
+
if (!changed) {
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
// Another tool may have changed state during the wait, so fetch again.
|
|
89
|
+
threads = await bridge.getComments(devtoolsPage);
|
|
90
|
+
}
|
|
91
|
+
if (threads.length === 0 && timeout > 0) {
|
|
92
|
+
response.appendResponseLine(`Waited ${Date.now() - start}ms for new DevTools comments. Call get_devtools_comments again to keep waiting.`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
53
95
|
response.setDevToolsComments(threads);
|
|
54
96
|
},
|
|
55
97
|
}));
|
|
@@ -71,6 +113,7 @@ export const resolveDevtoolsComment = definePageTool(() => ({
|
|
|
71
113
|
.describe('Optional reply explanation from the AI agent to append to the resolved comment thread.'),
|
|
72
114
|
},
|
|
73
115
|
blockedByDialog: false,
|
|
116
|
+
concurrency: 'exclusive',
|
|
74
117
|
verifyFilesSchema: {},
|
|
75
118
|
handler: async (request, response) => {
|
|
76
119
|
const page = request.page;
|
|
@@ -79,6 +122,10 @@ export const resolveDevtoolsComment = definePageTool(() => ({
|
|
|
79
122
|
response.appendResponseLine('DevTools window is not open for this page. Call open_devtools first to open DevTools.');
|
|
80
123
|
return;
|
|
81
124
|
}
|
|
125
|
+
if (!(await page.ensureDevToolsCommentBridge(devtoolsPage))) {
|
|
126
|
+
response.appendResponseLine(DEVTOOLS_COMMENTS_UNAVAILABLE_MESSAGE);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
82
129
|
const { threadId, replyText } = request.params;
|
|
83
130
|
const success = await devtoolsPage.evaluate((id, reply) => {
|
|
84
131
|
return (window.universe?.cd4aBridge?.resolveCommentThread(id, reply) ?? false);
|
|
@@ -117,6 +164,7 @@ export const revealInDevtools = definePageTool(() => ({
|
|
|
117
164
|
.describe('Optional network request ID to reveal in the Network panel.'),
|
|
118
165
|
},
|
|
119
166
|
blockedByDialog: false,
|
|
167
|
+
concurrency: 'exclusive',
|
|
120
168
|
verifyFilesSchema: {},
|
|
121
169
|
handler: async (request, response) => {
|
|
122
170
|
const page = request.page;
|
|
@@ -125,6 +173,10 @@ export const revealInDevtools = definePageTool(() => ({
|
|
|
125
173
|
response.appendResponseLine('DevTools window is not open for this page. Call open_devtools first to open DevTools.');
|
|
126
174
|
return;
|
|
127
175
|
}
|
|
176
|
+
if (!(await page.ensureDevToolsCommentBridge(devtoolsPage))) {
|
|
177
|
+
response.appendResponseLine(DEVTOOLS_COMMENTS_UNAVAILABLE_MESSAGE);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
128
180
|
const { panelName, uid, reqid } = request.params;
|
|
129
181
|
let backendNodeId;
|
|
130
182
|
let targetId;
|
|
@@ -148,9 +200,15 @@ export const revealInDevtools = definePageTool(() => ({
|
|
|
148
200
|
response.appendResponseLine(`Warning: Could not resolve network request ID ${reqid} to a CDP request ID.`);
|
|
149
201
|
}
|
|
150
202
|
}
|
|
203
|
+
const revealTarget = {
|
|
204
|
+
networkRequestId,
|
|
205
|
+
...(backendNodeId !== undefined
|
|
206
|
+
? { node: { backendNodeId, targetId: targetId ?? '' } }
|
|
207
|
+
: {}),
|
|
208
|
+
};
|
|
151
209
|
await devtoolsPage.evaluate(async (panel, target) => {
|
|
152
210
|
await window.universe?.cd4aBridge?.reveal(panel, target);
|
|
153
|
-
}, panelName
|
|
211
|
+
}, panelName ?? '', revealTarget);
|
|
154
212
|
let targetDesc = '';
|
|
155
213
|
if (uid && backendNodeId !== undefined) {
|
|
156
214
|
targetDesc = ` (revealing element ${uid} [backend node ${backendNodeId}])`;
|
|
@@ -32,7 +32,7 @@ const LIST_CONSOLE_MESSAGES_TOOL_NAME = 'list_console_messages';
|
|
|
32
32
|
export const listConsoleMessages = definePageTool((cliArgs) => {
|
|
33
33
|
return {
|
|
34
34
|
name: LIST_CONSOLE_MESSAGES_TOOL_NAME,
|
|
35
|
-
description: `List all console messages for the target page since the last navigation.${cliArgs
|
|
35
|
+
description: `List all console messages for the target page since the last navigation.${cliArgs.categoryExtensions ? ' This includes console messages originating from extensions content scripts.' : ''}`,
|
|
36
36
|
annotations: {
|
|
37
37
|
category: ToolCategory.DEBUGGING,
|
|
38
38
|
readOnlyHint: true,
|
|
@@ -49,7 +49,7 @@ export const listConsoleMessages = definePageTool((cliArgs) => {
|
|
|
49
49
|
.int()
|
|
50
50
|
.min(0)
|
|
51
51
|
.optional()
|
|
52
|
-
.describe('Page number to return (0-based). When omitted, returns the first page.'),
|
|
52
|
+
.describe('Page number to return (0-based). When omitted, returns the first page. Ignored unless pageSize is set.'),
|
|
53
53
|
types: zod
|
|
54
54
|
.array(zod.enum(FILTERABLE_MESSAGE_TYPES))
|
|
55
55
|
.optional()
|
|
@@ -58,7 +58,7 @@ export const listConsoleMessages = definePageTool((cliArgs) => {
|
|
|
58
58
|
.boolean()
|
|
59
59
|
.default(false)
|
|
60
60
|
.optional()
|
|
61
|
-
.describe(
|
|
61
|
+
.describe(`Set to true to return the preserved messages over the last ${cliArgs.maxNavigationSaved} navigations.`),
|
|
62
62
|
includeStackTraces: zod
|
|
63
63
|
.boolean()
|
|
64
64
|
.default(false)
|
|
@@ -67,9 +67,10 @@ export const listConsoleMessages = definePageTool((cliArgs) => {
|
|
|
67
67
|
serviceWorkerId: zod
|
|
68
68
|
.string()
|
|
69
69
|
.optional()
|
|
70
|
-
.describe('Filter messages
|
|
70
|
+
.describe('Filter messages by the service worker ID shown by list_pages (sw-N).'),
|
|
71
71
|
},
|
|
72
72
|
blockedByDialog: false,
|
|
73
|
+
concurrency: 'page',
|
|
73
74
|
verifyFilesSchema: {},
|
|
74
75
|
handler: async (request, response) => {
|
|
75
76
|
response.setIncludeConsoleData(true, {
|
|
@@ -96,6 +97,7 @@ export const getConsoleMessage = definePageTool(() => ({
|
|
|
96
97
|
.describe('The msgid of a console message on the page from the listed console messages'),
|
|
97
98
|
},
|
|
98
99
|
blockedByDialog: false,
|
|
100
|
+
concurrency: 'page',
|
|
99
101
|
verifyFilesSchema: {},
|
|
100
102
|
handler: async (request, response) => {
|
|
101
103
|
response.attachConsoleMessage(request.params.msgid);
|
package/build/src/tools/css.js
CHANGED
|
@@ -8,8 +8,10 @@ import { ToolCategory } from './categories.js';
|
|
|
8
8
|
import { definePageTool } from './ToolDefinition.js';
|
|
9
9
|
export const getCssStyles = definePageTool(() => ({
|
|
10
10
|
name: 'get_css_styles',
|
|
11
|
-
description: `Retrieve matched CSS rules, inline styles, inherited styles, and cascade
|
|
12
|
-
|
|
11
|
+
description: `Retrieve matched CSS rules, inline styles (element.style), inherited styles, custom properties, and cascade wrappers (@layer, @media, @container, @scope) for an element identified by its UID.
|
|
12
|
+
Rules are ordered from highest to lowest cascade precedence and include source line numbers (e.g. index:196). Active (winning) declarations have no prefix tag, while (losing) overridden declarations are prefixed with [overloaded].
|
|
13
|
+
Treat the output as authoritative and complete.
|
|
14
|
+
Results are paginated (10 rules per page by default); use pageIdx to page through the remaining rules. Requires a UID from take_snapshot.`,
|
|
13
15
|
annotations: {
|
|
14
16
|
category: ToolCategory.DEBUGGING,
|
|
15
17
|
readOnlyHint: true,
|
|
@@ -32,6 +34,7 @@ Use this tool to debug why specific CSS properties are applied, overridden, or c
|
|
|
32
34
|
.describe('Page number to return (0-based). Defaults to 0 (the first page).'),
|
|
33
35
|
},
|
|
34
36
|
blockedByDialog: true,
|
|
37
|
+
concurrency: 'page',
|
|
35
38
|
verifyFilesSchema: {},
|
|
36
39
|
handler: async (request, response) => {
|
|
37
40
|
const matchedStyles = await request.page.getMatchedStylesForUid(request.params.uid);
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
import { zod, PredefinedNetworkConditions } from '../third_party/index.js';
|
|
8
|
+
import { FORCED_COLORS_VALUES, PREFERS_CONTRAST_VALUES, PREFERS_REDUCED_MOTION_VALUES, } from '../types.js';
|
|
8
9
|
import { ToolCategory } from './categories.js';
|
|
9
|
-
import { definePageTool, geolocationTransform, viewportTransform, } from './ToolDefinition.js';
|
|
10
|
+
import { definePageTool, geolocationTransform, viewportTransform, zodTransform, } from './ToolDefinition.js';
|
|
10
11
|
function headerStringTransform(value) {
|
|
11
12
|
if (value === undefined) {
|
|
12
13
|
return undefined;
|
|
@@ -33,7 +34,7 @@ const throttlingOptions = [
|
|
|
33
34
|
];
|
|
34
35
|
export const emulate = definePageTool(() => ({
|
|
35
36
|
name: 'emulate',
|
|
36
|
-
description: `Emulates various features on the target page.`,
|
|
37
|
+
description: `Emulates various features on the target page. Each call replaces all emulation settings (except extraHttpHeaders), so pass all desired settings in a single call.`,
|
|
37
38
|
annotations: {
|
|
38
39
|
category: ToolCategory.EMULATION,
|
|
39
40
|
readOnlyHint: false,
|
|
@@ -51,29 +52,42 @@ export const emulate = definePageTool(() => ({
|
|
|
51
52
|
.describe('Represents the CPU slowdown factor. Omit or set the rate to 1 to disable throttling'),
|
|
52
53
|
geolocation: zod
|
|
53
54
|
.string()
|
|
54
|
-
.transform(geolocationTransform)
|
|
55
|
+
.transform(zodTransform(geolocationTransform))
|
|
55
56
|
.optional()
|
|
56
57
|
.describe('Geolocation (`<latitude>,<longitude>`) to emulate. Latitude between -90 and 90. Longitude between -180 and 180. Omit to clear the geolocation override.'),
|
|
57
58
|
userAgent: zod
|
|
58
59
|
.string()
|
|
59
60
|
.optional()
|
|
60
|
-
.describe('User agent to emulate.
|
|
61
|
+
.describe('User agent to emulate. Omit or set to empty string to clear the user agent override.'),
|
|
61
62
|
colorScheme: zod
|
|
62
63
|
.enum(['dark', 'light', 'auto'])
|
|
63
64
|
.optional()
|
|
64
|
-
.describe('Emulate the dark or the light mode.
|
|
65
|
+
.describe('Emulate the dark or the light mode. Omit or set to "auto" to reset to the default.'),
|
|
66
|
+
forcedColors: zod
|
|
67
|
+
.enum([...FORCED_COLORS_VALUES, 'auto'])
|
|
68
|
+
.optional()
|
|
69
|
+
.describe('Emulate the `forced-colors` CSS media feature. Omit or set to "auto" to reset to the default.'),
|
|
70
|
+
prefersContrast: zod
|
|
71
|
+
.enum([...PREFERS_CONTRAST_VALUES, 'auto'])
|
|
72
|
+
.optional()
|
|
73
|
+
.describe('Emulate the `prefers-contrast` CSS media feature. Omit or set to "auto" to reset to the default.'),
|
|
74
|
+
prefersReducedMotion: zod
|
|
75
|
+
.enum([...PREFERS_REDUCED_MOTION_VALUES, 'auto'])
|
|
76
|
+
.optional()
|
|
77
|
+
.describe('Emulate the `prefers-reduced-motion` CSS media feature. Omit or set to "auto" to reset to the default.'),
|
|
65
78
|
viewport: zod
|
|
66
79
|
.string()
|
|
67
|
-
.transform(viewportTransform)
|
|
80
|
+
.transform(zodTransform(viewportTransform))
|
|
68
81
|
.optional()
|
|
69
|
-
.describe(`Emulate device viewports '<width>x<height>x<devicePixelRatio>[,mobile][,touch][,landscape]'. 'touch' and 'mobile' to emulate mobile devices. 'landscape' to emulate landscape mode.`),
|
|
82
|
+
.describe(`Emulate device viewports '<width>x<height>x<devicePixelRatio>[,mobile][,touch][,landscape]'. 'touch' and 'mobile' to emulate mobile devices. 'landscape' to emulate landscape mode. Omit to clear the viewport override.`),
|
|
70
83
|
extraHttpHeaders: zod
|
|
71
84
|
.string()
|
|
72
|
-
.transform(headerStringTransform)
|
|
85
|
+
.transform(zodTransform(headerStringTransform))
|
|
73
86
|
.optional()
|
|
74
87
|
.describe('Extra HTTP headers as a JSON string object, e.g. {"X-Custom": "value", "Authorization": "Bearer token"}. Headers are included into every HTTP request originating from the page and persist across navigations until cleared. Pass an empty string to clear all extra headers.'),
|
|
75
88
|
},
|
|
76
89
|
blockedByDialog: true,
|
|
90
|
+
concurrency: 'exclusive',
|
|
77
91
|
verifyFilesSchema: {},
|
|
78
92
|
handler: async (request, response) => {
|
|
79
93
|
const page = request.page;
|
|
@@ -19,6 +19,7 @@ export const installExtension = defineTool(() => ({
|
|
|
19
19
|
.describe('Absolute path to the unpacked extension folder.'),
|
|
20
20
|
},
|
|
21
21
|
blockedByDialog: false,
|
|
22
|
+
concurrency: 'exclusive',
|
|
22
23
|
verifyFilesSchema: {
|
|
23
24
|
path: { local: true },
|
|
24
25
|
},
|
|
@@ -39,6 +40,7 @@ export const uninstallExtension = defineTool(() => ({
|
|
|
39
40
|
id: zod.string().describe('ID of the extension to uninstall.'),
|
|
40
41
|
},
|
|
41
42
|
blockedByDialog: false,
|
|
43
|
+
concurrency: 'exclusive',
|
|
42
44
|
verifyFilesSchema: {},
|
|
43
45
|
handler: async (request, response, context) => {
|
|
44
46
|
const { id } = request.params;
|
|
@@ -55,6 +57,7 @@ export const listExtensions = defineTool(() => ({
|
|
|
55
57
|
},
|
|
56
58
|
schema: {},
|
|
57
59
|
blockedByDialog: false,
|
|
60
|
+
concurrency: 'exclusive',
|
|
58
61
|
verifyFilesSchema: {},
|
|
59
62
|
handler: async (_request, response) => {
|
|
60
63
|
response.setListExtensions();
|
|
@@ -71,6 +74,7 @@ export const reloadExtension = defineTool(() => ({
|
|
|
71
74
|
id: zod.string().describe('ID of the extension to reload.'),
|
|
72
75
|
},
|
|
73
76
|
blockedByDialog: false,
|
|
77
|
+
concurrency: 'exclusive',
|
|
74
78
|
verifyFilesSchema: {},
|
|
75
79
|
handler: async (request, response, context) => {
|
|
76
80
|
const { id } = request.params;
|
|
@@ -93,6 +97,7 @@ export const triggerExtensionAction = defineTool(() => ({
|
|
|
93
97
|
id: zod.string().describe('ID of the extension to trigger the action for.'),
|
|
94
98
|
},
|
|
95
99
|
blockedByDialog: false,
|
|
100
|
+
concurrency: 'exclusive',
|
|
96
101
|
verifyFilesSchema: {},
|
|
97
102
|
handler: async (request, response, context) => {
|
|
98
103
|
const { id } = request.params;
|
package/build/src/tools/input.js
CHANGED
|
@@ -55,11 +55,11 @@ 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 { TimeoutError, zod } from '../third_party/index.js';
|
|
59
|
-
import { parseKey } from '../utils/keyboard.js';
|
|
58
|
+
import { TimeoutError, zod, } from '../third_party/index.js';
|
|
59
|
+
import { invalidKeyMessage, isValidKey, parseKey } from '../utils/keyboard.js';
|
|
60
60
|
import { logger } from '../utils/logger.js';
|
|
61
61
|
import { ToolCategory } from './categories.js';
|
|
62
|
-
import { definePageTool } from './ToolDefinition.js';
|
|
62
|
+
import { definePageTool, } from './ToolDefinition.js';
|
|
63
63
|
const dblClickSchema = zod
|
|
64
64
|
.boolean()
|
|
65
65
|
.optional()
|
|
@@ -70,6 +70,10 @@ const includeSnapshotSchema = zod
|
|
|
70
70
|
.describe('Whether to include a snapshot in the response. Default is false.');
|
|
71
71
|
const submitKeySchema = zod
|
|
72
72
|
.string()
|
|
73
|
+
// An empty string means no submit key, as before.
|
|
74
|
+
.refine((key) => key === '' || isValidKey(key), {
|
|
75
|
+
error: issue => invalidKeyMessage(String(issue.input)),
|
|
76
|
+
})
|
|
73
77
|
.optional()
|
|
74
78
|
.describe('Optional key to press after typing. E.g., "Enter", "Tab", "Escape"');
|
|
75
79
|
/**
|
|
@@ -146,6 +150,7 @@ export const click = definePageTool(() => ({
|
|
|
146
150
|
includeSnapshot: includeSnapshotSchema,
|
|
147
151
|
},
|
|
148
152
|
blockedByDialog: true,
|
|
153
|
+
concurrency: 'page',
|
|
149
154
|
verifyFilesSchema: {},
|
|
150
155
|
handler: async (request, response) => {
|
|
151
156
|
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
@@ -204,6 +209,7 @@ export const clickAt = definePageTool(() => ({
|
|
|
204
209
|
includeSnapshot: includeSnapshotSchema,
|
|
205
210
|
},
|
|
206
211
|
blockedByDialog: true,
|
|
212
|
+
concurrency: 'page',
|
|
207
213
|
verifyFilesSchema: {},
|
|
208
214
|
handler: async (request, response) => {
|
|
209
215
|
const page = request.page;
|
|
@@ -235,6 +241,7 @@ export const hover = definePageTool(() => ({
|
|
|
235
241
|
includeSnapshot: includeSnapshotSchema,
|
|
236
242
|
},
|
|
237
243
|
blockedByDialog: true,
|
|
244
|
+
concurrency: 'page',
|
|
238
245
|
verifyFilesSchema: {},
|
|
239
246
|
handler: async (request, response) => {
|
|
240
247
|
const env_3 = { stack: [], error: void 0, hasError: false };
|
|
@@ -422,6 +429,7 @@ export const fill = definePageTool(() => ({
|
|
|
422
429
|
includeSnapshot: includeSnapshotSchema,
|
|
423
430
|
},
|
|
424
431
|
blockedByDialog: true,
|
|
432
|
+
concurrency: 'page',
|
|
425
433
|
verifyFilesSchema: {},
|
|
426
434
|
handler: async (request, response) => {
|
|
427
435
|
const { result } = await fillFormElements([{ uid: request.params.uid, value: request.params.value }], request.page);
|
|
@@ -448,16 +456,19 @@ export const typeText = definePageTool(() => ({
|
|
|
448
456
|
submitKey: submitKeySchema,
|
|
449
457
|
},
|
|
450
458
|
blockedByDialog: true,
|
|
459
|
+
concurrency: 'page',
|
|
451
460
|
verifyFilesSchema: {},
|
|
452
461
|
handler: async (request, response) => {
|
|
453
462
|
const page = request.page;
|
|
463
|
+
const submitKey = request.params.submitKey;
|
|
454
464
|
const result = await page.waitForEventsAfterAction(async () => {
|
|
455
465
|
await page.pptrPage.keyboard.type(request.params.text);
|
|
456
|
-
|
|
457
|
-
|
|
466
|
+
// submitKeySchema has already validated the key; isValidKey narrows the type.
|
|
467
|
+
if (submitKey && isValidKey(submitKey)) {
|
|
468
|
+
await page.pptrPage.keyboard.press(submitKey);
|
|
458
469
|
}
|
|
459
470
|
});
|
|
460
|
-
response.appendResponseLine(`Typed text "${request.params.text}${
|
|
471
|
+
response.appendResponseLine(`Typed text "${request.params.text}${submitKey ? ` + ${submitKey}` : ''}"`);
|
|
461
472
|
response.attachWaitForResult(result);
|
|
462
473
|
},
|
|
463
474
|
}));
|
|
@@ -474,6 +485,7 @@ export const drag = definePageTool(() => ({
|
|
|
474
485
|
includeSnapshot: includeSnapshotSchema,
|
|
475
486
|
},
|
|
476
487
|
blockedByDialog: true,
|
|
488
|
+
concurrency: 'page',
|
|
477
489
|
verifyFilesSchema: {},
|
|
478
490
|
handler: async (request, response) => {
|
|
479
491
|
const env_7 = { stack: [], error: void 0, hasError: false };
|
|
@@ -523,6 +535,7 @@ export const fillForm = definePageTool(() => ({
|
|
|
523
535
|
includeSnapshot: includeSnapshotSchema,
|
|
524
536
|
},
|
|
525
537
|
blockedByDialog: true,
|
|
538
|
+
concurrency: 'page',
|
|
526
539
|
verifyFilesSchema: {},
|
|
527
540
|
handler: async (request, response) => {
|
|
528
541
|
const { result, interruptedUid } = await fillFormElements(request.params.elements, request.page);
|
|
@@ -560,6 +573,7 @@ export const uploadFile = definePageTool(() => ({
|
|
|
560
573
|
includeSnapshot: includeSnapshotSchema,
|
|
561
574
|
},
|
|
562
575
|
blockedByDialog: true,
|
|
576
|
+
concurrency: 'page',
|
|
563
577
|
// We do not validate file paths for remote browser instances
|
|
564
578
|
// because they are on the remote host and not accessed by the MCP server.
|
|
565
579
|
verifyFilesSchema: {
|
|
@@ -576,20 +590,25 @@ export const uploadFile = definePageTool(() => ({
|
|
|
576
590
|
try {
|
|
577
591
|
await handle.uploadFile(...filePaths);
|
|
578
592
|
}
|
|
579
|
-
catch {
|
|
593
|
+
catch (err) {
|
|
594
|
+
if (err instanceof Error &&
|
|
595
|
+
err.message.includes('Multiple file uploads')) {
|
|
596
|
+
throw err;
|
|
597
|
+
}
|
|
580
598
|
// Some sites use a proxy element to trigger file upload instead of
|
|
581
599
|
// a type=file element. In this case, we want to default to
|
|
582
600
|
// Page.waitForFileChooser() and upload the file this way.
|
|
601
|
+
let fileChooser;
|
|
583
602
|
try {
|
|
584
|
-
|
|
603
|
+
[fileChooser] = await Promise.all([
|
|
585
604
|
request.page.pptrPage.waitForFileChooser({ timeout: 3000 }),
|
|
586
605
|
handle.asLocator().click(),
|
|
587
606
|
]);
|
|
588
|
-
await fileChooser.accept(filePaths);
|
|
589
607
|
}
|
|
590
608
|
catch {
|
|
591
609
|
throw new Error(`Failed to upload file. The element could not accept the file directly, and clicking it did not trigger a file chooser.`);
|
|
592
610
|
}
|
|
611
|
+
await fileChooser.accept(filePaths);
|
|
593
612
|
}
|
|
594
613
|
if (request.params.includeSnapshot) {
|
|
595
614
|
response.includeSnapshot();
|
|
@@ -619,6 +638,7 @@ export const pressKey = definePageTool(() => ({
|
|
|
619
638
|
includeSnapshot: includeSnapshotSchema,
|
|
620
639
|
},
|
|
621
640
|
blockedByDialog: true,
|
|
641
|
+
concurrency: 'page',
|
|
622
642
|
verifyFilesSchema: {},
|
|
623
643
|
handler: async (request, response) => {
|
|
624
644
|
const page = request.page;
|