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.
- package/README.md +72 -20
- package/build/src/BrowserManager.js +27 -18
- package/build/src/McpContext.js +435 -87
- package/build/src/McpPage.js +189 -59
- package/build/src/McpResponse.js +61 -44
- package/build/src/TextSnapshot.js +37 -18
- package/build/src/ToolHandler.js +256 -135
- package/build/src/bin/chrome-devtools-mcp-main.js +6 -4
- package/build/src/bin/chrome-devtools.js +4 -4
- package/build/src/collectors/PageCollector.js +13 -9
- package/build/src/collectors/ServiceWorkerCollector.js +2 -2
- package/build/src/collectors/constants.js +7 -0
- package/build/src/config/ConfigParser.js +44 -149
- package/build/src/config/ConfigWatcher.js +3 -2
- package/build/src/config/ServerConfig.js +251 -0
- package/build/src/config/browser-options.js +13 -4
- package/build/src/config/cli-options.js +35 -19
- package/build/src/config/mcp-options.js +61 -35
- package/build/src/config/puppeteer-options.js +4 -2
- package/build/src/daemon/client.js +3 -3
- package/build/src/daemon/daemon.js +7 -3
- package/build/src/daemon/utils.js +2 -1
- package/build/src/devtools/DevToolsCommentBridge.js +28 -5
- package/build/src/devtools/DevtoolsUtils.js +49 -12
- package/build/src/formatters/ConsoleFormatter.js +28 -1
- package/build/src/formatters/HeapSnapshotFormatter.js +14 -18
- package/build/src/formatters/NetworkFormatter.js +54 -15
- package/build/src/formatters/RemoteObjectFormatter.js +231 -0
- package/build/src/formatters/SnapshotFormatter.js +13 -3
- package/build/src/index.js +256 -104
- package/build/src/processors/HeapSnapshotManager.js +390 -128
- package/build/src/third_party/THIRD_PARTY_NOTICES +542 -445
- package/build/src/third_party/bundled-packages.json +2 -2
- package/build/src/third_party/cli.js +9239 -0
- package/build/src/third_party/devtools-formatter-worker.js +3089 -2438
- package/build/src/third_party/devtools-heap-snapshot-worker.js +172 -1
- package/build/src/third_party/index.js +52247 -55764
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +54576 -52174
- package/build/src/tools/ToolDefinition.js +90 -12
- package/build/src/tools/comments.js +42 -3
- package/build/src/tools/console.js +6 -4
- package/build/src/tools/css.js +1 -0
- package/build/src/tools/emulation.js +5 -4
- package/build/src/tools/extensions.js +5 -0
- package/build/src/tools/input.js +21 -6
- package/build/src/tools/lighthouse.js +24 -8
- package/build/src/tools/memory.js +59 -53
- package/build/src/tools/network.js +5 -4
- package/build/src/tools/pages.js +48 -6
- package/build/src/tools/performance.js +7 -4
- package/build/src/tools/pwa.js +7 -0
- package/build/src/tools/screencast.js +3 -1
- package/build/src/tools/screenshot.js +23 -7
- package/build/src/tools/script.js +38 -6
- package/build/src/tools/slim/tools.js +21 -5
- package/build/src/tools/snapshot.js +13 -3
- package/build/src/tools/thirdPartyDeveloper.js +3 -1
- package/build/src/tools/webmcp.js +2 -0
- package/build/src/utils/TaskRunner.js +136 -0
- package/build/src/utils/WaitForHelper.js +1 -1
- package/build/src/utils/bytes.js +2 -12
- package/build/src/utils/check-for-updates.js +1 -1
- package/build/src/utils/disclaimers.js +27 -0
- package/build/src/utils/keyboard.js +14 -2
- package/build/src/utils/logger.js +69 -0
- package/build/src/utils/resourceType.js +27 -0
- package/build/src/utils/text.js +29 -0
- package/build/src/utils/timeout.js +14 -0
- package/build/src/utils/url.js +41 -0
- package/build/src/version.js +1 -1
- package/package.json +5 -4
- package/skills/a11y-debugging/SKILL.md +3 -8
|
@@ -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
|
}
|
|
@@ -20,42 +21,100 @@ export function definePageTool(definition) {
|
|
|
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
|
|
117
|
+
deviceScaleFactor,
|
|
59
118
|
isMobile,
|
|
60
119
|
isLandscape,
|
|
61
120
|
hasTouch,
|
|
@@ -65,10 +124,15 @@ 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
|
}
|
|
@@ -81,12 +145,26 @@ export function isSlimTool(tool) {
|
|
|
81
145
|
return Boolean(tool.annotations.conditions?.includes('slim'));
|
|
82
146
|
}
|
|
83
147
|
/**
|
|
84
|
-
* Slim mode replaces the regular tools with the slim tools.
|
|
85
|
-
* the current mode are registered, so a slim tool may share its name with a
|
|
86
|
-
* regular tool. `--slim` requires a restart, so the mode never changes while
|
|
87
|
-
* the server is running.
|
|
148
|
+
* Slim mode replaces the regular tools with the slim tools.
|
|
88
149
|
*/
|
|
89
150
|
export function isAvailableInMode(tool, serverArgs) {
|
|
90
151
|
return isSlimTool(tool) === Boolean(serverArgs.slim);
|
|
91
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
|
+
}
|
|
92
170
|
//# sourceMappingURL=ToolDefinition.js.map
|
|
@@ -17,6 +17,7 @@ export const openDevtools = definePageTool(() => ({
|
|
|
17
17
|
},
|
|
18
18
|
schema: {},
|
|
19
19
|
blockedByDialog: false,
|
|
20
|
+
concurrency: 'exclusive',
|
|
20
21
|
verifyFilesSchema: [],
|
|
21
22
|
handler: async (request, response) => {
|
|
22
23
|
const page = request.page;
|
|
@@ -31,16 +32,33 @@ export const openDevtools = definePageTool(() => ({
|
|
|
31
32
|
response.setIncludePages(true);
|
|
32
33
|
},
|
|
33
34
|
}));
|
|
35
|
+
const DEFAULT_COMMENT_WAIT_MS = 10_000;
|
|
36
|
+
const MAX_COMMENT_WAIT_MS = 30_000;
|
|
34
37
|
export const getDevtoolsComments = definePageTool(() => ({
|
|
35
38
|
name: 'get_devtools_comments',
|
|
36
|
-
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.',
|
|
37
42
|
annotations: {
|
|
38
43
|
category: ToolCategory.DEBUGGING,
|
|
39
44
|
readOnlyHint: true,
|
|
40
45
|
conditions: ['devtoolsComments'],
|
|
41
46
|
},
|
|
42
|
-
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
|
+
},
|
|
43
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',
|
|
44
62
|
verifyFilesSchema: {},
|
|
45
63
|
handler: async (request, response) => {
|
|
46
64
|
const page = request.page;
|
|
@@ -54,7 +72,26 @@ export const getDevtoolsComments = definePageTool(() => ({
|
|
|
54
72
|
response.appendResponseLine(DEVTOOLS_COMMENTS_UNAVAILABLE_MESSAGE);
|
|
55
73
|
return;
|
|
56
74
|
}
|
|
57
|
-
const
|
|
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
|
+
}
|
|
58
95
|
response.setDevToolsComments(threads);
|
|
59
96
|
},
|
|
60
97
|
}));
|
|
@@ -76,6 +113,7 @@ export const resolveDevtoolsComment = definePageTool(() => ({
|
|
|
76
113
|
.describe('Optional reply explanation from the AI agent to append to the resolved comment thread.'),
|
|
77
114
|
},
|
|
78
115
|
blockedByDialog: false,
|
|
116
|
+
concurrency: 'exclusive',
|
|
79
117
|
verifyFilesSchema: {},
|
|
80
118
|
handler: async (request, response) => {
|
|
81
119
|
const page = request.page;
|
|
@@ -126,6 +164,7 @@ export const revealInDevtools = definePageTool(() => ({
|
|
|
126
164
|
.describe('Optional network request ID to reveal in the Network panel.'),
|
|
127
165
|
},
|
|
128
166
|
blockedByDialog: false,
|
|
167
|
+
concurrency: 'exclusive',
|
|
129
168
|
verifyFilesSchema: {},
|
|
130
169
|
handler: async (request, response) => {
|
|
131
170
|
const page = request.page;
|
|
@@ -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
|
@@ -34,6 +34,7 @@ Results are paginated (10 rules per page by default); use pageIdx to page throug
|
|
|
34
34
|
.describe('Page number to return (0-based). Defaults to 0 (the first page).'),
|
|
35
35
|
},
|
|
36
36
|
blockedByDialog: true,
|
|
37
|
+
concurrency: 'page',
|
|
37
38
|
verifyFilesSchema: {},
|
|
38
39
|
handler: async (request, response) => {
|
|
39
40
|
const matchedStyles = await request.page.getMatchedStylesForUid(request.params.uid);
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { zod, PredefinedNetworkConditions } from '../third_party/index.js';
|
|
8
8
|
import { FORCED_COLORS_VALUES, PREFERS_CONTRAST_VALUES, PREFERS_REDUCED_MOTION_VALUES, } from '../types.js';
|
|
9
9
|
import { ToolCategory } from './categories.js';
|
|
10
|
-
import { definePageTool, geolocationTransform, viewportTransform, } from './ToolDefinition.js';
|
|
10
|
+
import { definePageTool, geolocationTransform, viewportTransform, zodTransform, } from './ToolDefinition.js';
|
|
11
11
|
function headerStringTransform(value) {
|
|
12
12
|
if (value === undefined) {
|
|
13
13
|
return undefined;
|
|
@@ -52,7 +52,7 @@ export const emulate = definePageTool(() => ({
|
|
|
52
52
|
.describe('Represents the CPU slowdown factor. Omit or set the rate to 1 to disable throttling'),
|
|
53
53
|
geolocation: zod
|
|
54
54
|
.string()
|
|
55
|
-
.transform(geolocationTransform)
|
|
55
|
+
.transform(zodTransform(geolocationTransform))
|
|
56
56
|
.optional()
|
|
57
57
|
.describe('Geolocation (`<latitude>,<longitude>`) to emulate. Latitude between -90 and 90. Longitude between -180 and 180. Omit to clear the geolocation override.'),
|
|
58
58
|
userAgent: zod
|
|
@@ -77,16 +77,17 @@ export const emulate = definePageTool(() => ({
|
|
|
77
77
|
.describe('Emulate the `prefers-reduced-motion` CSS media feature. Omit or set to "auto" to reset to the default.'),
|
|
78
78
|
viewport: zod
|
|
79
79
|
.string()
|
|
80
|
-
.transform(viewportTransform)
|
|
80
|
+
.transform(zodTransform(viewportTransform))
|
|
81
81
|
.optional()
|
|
82
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.`),
|
|
83
83
|
extraHttpHeaders: zod
|
|
84
84
|
.string()
|
|
85
|
-
.transform(headerStringTransform)
|
|
85
|
+
.transform(zodTransform(headerStringTransform))
|
|
86
86
|
.optional()
|
|
87
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.'),
|
|
88
88
|
},
|
|
89
89
|
blockedByDialog: true,
|
|
90
|
+
concurrency: 'exclusive',
|
|
90
91
|
verifyFilesSchema: {},
|
|
91
92
|
handler: async (request, response) => {
|
|
92
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: {
|
|
@@ -624,6 +638,7 @@ export const pressKey = definePageTool(() => ({
|
|
|
624
638
|
includeSnapshot: includeSnapshotSchema,
|
|
625
639
|
},
|
|
626
640
|
blockedByDialog: true,
|
|
641
|
+
concurrency: 'page',
|
|
627
642
|
verifyFilesSchema: {},
|
|
628
643
|
handler: async (request, response) => {
|
|
629
644
|
const page = request.page;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import path from 'node:path';
|
|
7
|
-
import {
|
|
7
|
+
import { generateReport, zod, } from '../third_party/index.js';
|
|
8
8
|
import { ToolCategory } from './categories.js';
|
|
9
9
|
import { startTrace } from './performance.js';
|
|
10
10
|
import { definePageTool, } from './ToolDefinition.js';
|
|
@@ -21,6 +21,12 @@ const MAX_NODES_PER_AUDIT = 10;
|
|
|
21
21
|
const isRecord = (value) => {
|
|
22
22
|
return typeof value === 'object' && value !== null;
|
|
23
23
|
};
|
|
24
|
+
// Lighthouse's navigation mode only accepts the URL schemes in
|
|
25
|
+
// `allowedProtocols` (core/lib/url-utils.js) and throws a bare `INVALID_URL`
|
|
26
|
+
// for anything else, such as file:// or about:blank.
|
|
27
|
+
const isInvalidUrlError = (error) => {
|
|
28
|
+
return isRecord(error) && error.code === 'INVALID_URL';
|
|
29
|
+
};
|
|
24
30
|
const getString = (value) => {
|
|
25
31
|
return typeof value === 'string' ? value : undefined;
|
|
26
32
|
};
|
|
@@ -144,6 +150,7 @@ export const lighthouseAudit = definePageTool((args) => ({
|
|
|
144
150
|
.describe('Directory for reports. If omitted, uses temporary files.'),
|
|
145
151
|
},
|
|
146
152
|
blockedByDialog: true,
|
|
153
|
+
concurrency: 'exclusive',
|
|
147
154
|
verifyFilesSchema: {
|
|
148
155
|
outputDirPath: true,
|
|
149
156
|
},
|
|
@@ -188,14 +195,19 @@ export const lighthouseAudit = definePageTool((args) => ({
|
|
|
188
195
|
let result;
|
|
189
196
|
try {
|
|
190
197
|
if (mode === 'navigation') {
|
|
191
|
-
|
|
192
|
-
flags
|
|
193
|
-
}
|
|
198
|
+
try {
|
|
199
|
+
result = await page.lighthouseNavigation(flags);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
if (isInvalidUrlError(error)) {
|
|
203
|
+
const url = page.pptrPage.url();
|
|
204
|
+
throw new Error(`Lighthouse "navigation" mode cannot audit ${url}: it only supports http:, https:, chrome: and chrome-extension: URLs. Use mode "snapshot" to audit the page in its current state.`, { cause: error });
|
|
205
|
+
}
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
194
208
|
}
|
|
195
209
|
else {
|
|
196
|
-
result = await
|
|
197
|
-
flags,
|
|
198
|
-
});
|
|
210
|
+
result = await page.lighthouseSnapshot(flags);
|
|
199
211
|
}
|
|
200
212
|
if (!result) {
|
|
201
213
|
throw new Error('Lighthouse audit failed.');
|
|
@@ -208,7 +220,7 @@ export const lighthouseAudit = definePageTool((args) => ({
|
|
|
208
220
|
const reportPaths = [];
|
|
209
221
|
const encoder = new TextEncoder();
|
|
210
222
|
const savePromises = formats.map(async (format) => {
|
|
211
|
-
const report = generateReport(lhr, format);
|
|
223
|
+
const report = await generateReport(lhr, format);
|
|
212
224
|
const data = encoder.encode(report);
|
|
213
225
|
if (outputDirPath) {
|
|
214
226
|
const reportPath = path.join(outputDirPath, `report`);
|
|
@@ -225,6 +237,10 @@ export const lighthouseAudit = definePageTool((args) => ({
|
|
|
225
237
|
}
|
|
226
238
|
reportPaths.push(res.value);
|
|
227
239
|
}
|
|
240
|
+
// Lighthouse sets runtimeError when it could not load the page; the categories are unscored.
|
|
241
|
+
if (lhr.runtimeError) {
|
|
242
|
+
throw new Error(`Lighthouse could not audit the page (${lhr.runtimeError.code}): ${lhr.runtimeError.message} Reports: ${reportPaths.join(', ')}`);
|
|
243
|
+
}
|
|
228
244
|
const categoryScores = Object.values(lhr.categories).map(c => ({
|
|
229
245
|
id: c.id,
|
|
230
246
|
title: c.title,
|