chrome-devtools-mcp 1.10.1 → 1.11.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/build/src/BrowserManager.js +132 -13
- package/build/src/McpContext.js +188 -138
- package/build/src/McpPage.js +348 -96
- package/build/src/McpResponse.js +234 -76
- package/build/src/McpWorker.js +66 -0
- package/build/src/SlimMcpResponse.js +5 -1
- package/build/src/TextSnapshot.js +3 -2
- package/build/src/ToolHandler.js +80 -42
- package/build/src/bin/chrome-devtools-mcp-main.js +8 -7
- package/build/src/bin/chrome-devtools-mcp.js +1 -1
- package/build/src/bin/chrome-devtools.js +31 -41
- package/build/src/collectors/ServiceWorkerCollector.js +18 -11
- package/build/src/config/ConfigLocator.js +70 -0
- package/build/src/config/ConfigParser.js +264 -0
- package/build/src/config/ConfigWatcher.js +93 -0
- package/build/src/config/browser-options.js +2 -13
- 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 +410 -43
- package/build/src/config/mcp-options.js +156 -234
- package/build/src/config/puppeteer-options.js +65 -0
- package/build/src/config/tool-options.js +60 -0
- package/build/src/daemon/client.js +81 -41
- package/build/src/daemon/daemon.js +55 -45
- package/build/src/daemon/utils.js +44 -11
- package/build/src/devtools/DevToolsCommentBridge.js +43 -6
- package/build/src/devtools/DevtoolsUtils.js +3 -3
- package/build/src/devtools/McpHostBindingAdapter.js +0 -1
- package/build/src/formatters/CommentFormatter.js +4 -13
- package/build/src/formatters/ConsoleFormatter.js +1 -1
- package/build/src/formatters/CssFormatter.js +3 -2
- package/build/src/formatters/HeapSnapshotFormatter.js +104 -46
- package/build/src/formatters/IssueFormatter.js +33 -32
- package/build/src/formatters/NetworkFormatter.js +12 -11
- package/build/src/formatters/SnapshotFormatter.js +31 -4
- package/build/src/index.js +54 -9
- package/build/src/processors/ChunkedTraceParser.js +11 -11
- package/build/src/processors/HeapSnapshotManager.js +121 -84
- 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 +10 -397
- package/build/src/third_party/bundled-packages.json +7 -8
- package/build/src/third_party/devtools-formatter-worker.js +1193 -62
- package/build/src/third_party/devtools-heap-snapshot-worker.js +1126 -21
- package/build/src/third_party/index.js +8087 -19419
- 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 +3 -3
- package/build/src/tools/ToolDefinition.js +16 -4
- package/build/src/tools/comments.js +20 -1
- package/build/src/tools/css.js +4 -2
- package/build/src/tools/emulation.js +17 -4
- package/build/src/tools/input.js +8 -3
- package/build/src/tools/lighthouse.js +112 -4
- package/build/src/tools/memory.js +129 -28
- package/build/src/tools/pages.js +5 -2
- package/build/src/tools/performance.js +21 -3
- package/build/src/tools/screencast.js +71 -32
- package/build/src/tools/screenshot.js +29 -14
- package/build/src/tools/script.js +90 -37
- package/build/src/tools/slim/tools.js +6 -8
- package/build/src/tools/thirdPartyDeveloper.js +6 -4
- package/build/src/tools/tools.js +35 -22
- package/build/src/tools/webmcp.js +9 -6
- package/build/src/types.js +11 -0
- package/build/src/utils/WaitForHelper.js +14 -1
- package/build/src/utils/check-for-updates.js +1 -1
- package/build/src/utils/errorHandling.js +20 -0
- package/build/src/utils/logger.js +15 -5
- package/build/src/utils/text.js +15 -0
- package/build/src/utils/url.js +99 -3
- package/build/src/version.js +1 -1
- package/package.json +14 -10
- package/skills/a11y-debugging/SKILL.md +4 -4
- 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
|
@@ -61,13 +61,24 @@ import { definePageTool } from './ToolDefinition.js';
|
|
|
61
61
|
async function getSourceBox(page, element, fullPage) {
|
|
62
62
|
if (element) {
|
|
63
63
|
const viewport = page.viewport();
|
|
64
|
-
const [box,
|
|
64
|
+
const [box, metrics] = await Promise.all([
|
|
65
65
|
element.boundingBox(),
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
:
|
|
66
|
+
page.evaluate(() => ({
|
|
67
|
+
x: window.scrollX,
|
|
68
|
+
y: window.scrollY,
|
|
69
|
+
devicePixelRatio: window.devicePixelRatio,
|
|
70
|
+
})),
|
|
69
71
|
]);
|
|
70
|
-
return box
|
|
72
|
+
return box
|
|
73
|
+
? {
|
|
74
|
+
...box,
|
|
75
|
+
x: box.x + metrics.x,
|
|
76
|
+
y: box.y + metrics.y,
|
|
77
|
+
devicePixelRatio: viewport
|
|
78
|
+
? (viewport.deviceScaleFactor ?? 1)
|
|
79
|
+
: metrics.devicePixelRatio,
|
|
80
|
+
}
|
|
81
|
+
: undefined;
|
|
71
82
|
}
|
|
72
83
|
if (fullPage) {
|
|
73
84
|
const dims = await page.evaluate(() => ({
|
|
@@ -87,10 +98,19 @@ async function getSourceBox(page, element, fullPage) {
|
|
|
87
98
|
};
|
|
88
99
|
}
|
|
89
100
|
const viewport = page.viewport();
|
|
101
|
+
// Clips use page coordinates. Read the scroll offset alongside the native
|
|
102
|
+
// dimensions used when no viewport is emulated.
|
|
103
|
+
const dims = await page.evaluate(() => ({
|
|
104
|
+
x: window.scrollX,
|
|
105
|
+
y: window.scrollY,
|
|
106
|
+
width: window.innerWidth,
|
|
107
|
+
height: window.innerHeight,
|
|
108
|
+
devicePixelRatio: window.devicePixelRatio,
|
|
109
|
+
}));
|
|
90
110
|
if (viewport) {
|
|
91
111
|
return {
|
|
92
|
-
x:
|
|
93
|
-
y:
|
|
112
|
+
x: dims.x,
|
|
113
|
+
y: dims.y,
|
|
94
114
|
width: viewport.width,
|
|
95
115
|
height: viewport.height,
|
|
96
116
|
devicePixelRatio: viewport.deviceScaleFactor ?? 1,
|
|
@@ -99,17 +119,12 @@ async function getSourceBox(page, element, fullPage) {
|
|
|
99
119
|
// The browser is launched and connected with `defaultViewport: null`, so
|
|
100
120
|
// `page.viewport()` stays null until something emulates one. Fall back to the
|
|
101
121
|
// window's own dimensions, which is the area a viewport screenshot captures.
|
|
102
|
-
const dims = await page.evaluate(() => ({
|
|
103
|
-
width: window.innerWidth,
|
|
104
|
-
height: window.innerHeight,
|
|
105
|
-
devicePixelRatio: window.devicePixelRatio,
|
|
106
|
-
}));
|
|
107
122
|
if (dims.width <= 0 || dims.height <= 0) {
|
|
108
123
|
return undefined;
|
|
109
124
|
}
|
|
110
125
|
return {
|
|
111
|
-
x:
|
|
112
|
-
y:
|
|
126
|
+
x: dims.x,
|
|
127
|
+
y: dims.y,
|
|
113
128
|
width: dims.width,
|
|
114
129
|
height: dims.height,
|
|
115
130
|
devicePixelRatio: dims.devicePixelRatio,
|
|
@@ -55,13 +55,14 @@ 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 { pathToFileURL } from 'node:url';
|
|
58
59
|
import { zod } from '../third_party/index.js';
|
|
59
60
|
import { ToolCategory } from './categories.js';
|
|
60
61
|
import { defineTool, pageIdSchema } from './ToolDefinition.js';
|
|
61
62
|
export const evaluateScript = defineTool((cliArgs) => {
|
|
62
63
|
return {
|
|
63
64
|
name: 'evaluate_script',
|
|
64
|
-
description: `Evaluate
|
|
65
|
+
description: `Evaluate JavaScript inside the target page${cliArgs.categoryExtensions ? ' or service worker' : ''}. The source can be provided inline or loaded from a local file. Returns the response as JSON, so returned values have to be JSON-serializable.`,
|
|
65
66
|
annotations: {
|
|
66
67
|
category: ToolCategory.DEBUGGING,
|
|
67
68
|
readOnlyHint: false,
|
|
@@ -78,16 +79,27 @@ export const evaluateScript = defineTool((cliArgs) => {
|
|
|
78
79
|
}
|
|
79
80
|
: pageIdSchema
|
|
80
81
|
: {}),
|
|
81
|
-
function: zod
|
|
82
|
+
function: zod
|
|
83
|
+
.string()
|
|
84
|
+
.optional()
|
|
85
|
+
.describe(`JavaScript source to execute in the target page. Provide either this or sourcePath, but not both. The source is interpreted according to format.
|
|
82
86
|
Example without arguments: \`() => document.title\` or \`async () => await fetch("example.com")\`.
|
|
83
87
|
Example with arguments: \`(el) => el.innerText\`
|
|
84
88
|
`),
|
|
89
|
+
sourcePath: zod
|
|
90
|
+
.string()
|
|
91
|
+
.optional()
|
|
92
|
+
.describe("The absolute or relative path to a JavaScript file on the MCP server's local filesystem. Provide either this or function, but not both."),
|
|
93
|
+
format: zod
|
|
94
|
+
.enum(['function', 'script'])
|
|
95
|
+
.optional()
|
|
96
|
+
.describe('How to interpret the source. "function" treats it as a function declaration and supports args. "script" evaluates it as classic JavaScript and does not support args. Defaults to "function". ECMAScript modules are not supported.'),
|
|
85
97
|
args: zod
|
|
86
98
|
.array(zod
|
|
87
99
|
.string()
|
|
88
100
|
.describe('The uid of an element on the page from the page content snapshot'))
|
|
89
101
|
.optional()
|
|
90
|
-
.describe(`An optional list of arguments to pass to the function.`),
|
|
102
|
+
.describe(`An optional list of arguments (element uids from the page content snapshot) to pass to the function.`),
|
|
91
103
|
filePath: zod
|
|
92
104
|
.string()
|
|
93
105
|
.optional()
|
|
@@ -112,11 +124,16 @@ Example with arguments: \`(el) => el.innerText\`
|
|
|
112
124
|
blockedByDialog: true,
|
|
113
125
|
verifyFilesSchema: {
|
|
114
126
|
filePath: true,
|
|
127
|
+
sourcePath: true,
|
|
115
128
|
},
|
|
116
129
|
handler: async (request, response, context) => {
|
|
117
130
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
118
131
|
try {
|
|
119
|
-
const { serviceWorkerId, args: uidArgs, function: fnString, pageId, dialogAction, filePath, waitForStableDom, } = request.params;
|
|
132
|
+
const { serviceWorkerId, args: uidArgs, function: fnString, sourcePath, format = 'function', pageId, dialogAction, filePath, waitForStableDom, } = request.params;
|
|
133
|
+
const source = await resolveScriptSource(fnString, sourcePath, context);
|
|
134
|
+
if (format === 'script' && uidArgs && uidArgs.length > 0) {
|
|
135
|
+
throw new Error('args cannot be used when format is "script".');
|
|
136
|
+
}
|
|
120
137
|
if (cliArgs.categoryExtensions && serviceWorkerId) {
|
|
121
138
|
if (uidArgs && uidArgs.length > 0) {
|
|
122
139
|
throw new Error('args (element uids) cannot be used when evaluating in a service worker.');
|
|
@@ -128,7 +145,7 @@ Example with arguments: \`(el) => el.innerText\`
|
|
|
128
145
|
const result = await context
|
|
129
146
|
.getSelectedMcpPage()
|
|
130
147
|
.waitForEventsAfterAction(async () => {
|
|
131
|
-
await performEvaluation(worker,
|
|
148
|
+
await performEvaluation(worker, source, format, [], response, {
|
|
132
149
|
filePath,
|
|
133
150
|
context,
|
|
134
151
|
});
|
|
@@ -147,6 +164,7 @@ Example with arguments: \`(el) => el.innerText\`
|
|
|
147
164
|
const mcpPage = cliArgs.pageIdRouting && request.params.pageId
|
|
148
165
|
? context.getPageById(request.params.pageId)
|
|
149
166
|
: context.getSelectedMcpPage();
|
|
167
|
+
await mcpPage.init();
|
|
150
168
|
const page = mcpPage.pptrPage;
|
|
151
169
|
const args = [];
|
|
152
170
|
const stack = __addDisposableResource(env_1, new DisposableStack(), false);
|
|
@@ -159,7 +177,7 @@ Example with arguments: \`(el) => el.innerText\`
|
|
|
159
177
|
}
|
|
160
178
|
const evaluatable = await getPageOrFrame(page, frames);
|
|
161
179
|
const result = await mcpPage.waitForEventsAfterAction(async () => {
|
|
162
|
-
await performEvaluation(evaluatable,
|
|
180
|
+
await performEvaluation(evaluatable, source, format, args, response, {
|
|
163
181
|
filePath,
|
|
164
182
|
context,
|
|
165
183
|
});
|
|
@@ -176,32 +194,70 @@ Example with arguments: \`(el) => el.innerText\`
|
|
|
176
194
|
},
|
|
177
195
|
};
|
|
178
196
|
});
|
|
179
|
-
const
|
|
180
|
-
|
|
197
|
+
const resolveScriptSource = async (inlineSource, sourcePath, context) => {
|
|
198
|
+
if (inlineSource !== undefined) {
|
|
199
|
+
if (sourcePath !== undefined) {
|
|
200
|
+
throw new Error('Specify exactly one of function or sourcePath.');
|
|
201
|
+
}
|
|
202
|
+
return inlineSource;
|
|
203
|
+
}
|
|
204
|
+
if (sourcePath === undefined) {
|
|
205
|
+
throw new Error('Specify exactly one of function or sourcePath.');
|
|
206
|
+
}
|
|
207
|
+
const resourceUrl = sourcePath.startsWith('file:')
|
|
208
|
+
? sourcePath
|
|
209
|
+
: pathToFileURL(sourcePath).href;
|
|
181
210
|
try {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
211
|
+
return await context.loadResource(resourceUrl);
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
215
|
+
throw new Error(`Unable to read script source from ${sourcePath}: ${errorMessage}`, { cause: error });
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
const performEvaluation = async (evaluatable, source, format, args, response, options) => {
|
|
219
|
+
let result;
|
|
220
|
+
if (format === 'function') {
|
|
221
|
+
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
222
|
+
try {
|
|
223
|
+
const functionSource = source.trimEnd().replace(/;$/, '');
|
|
224
|
+
const fn = __addDisposableResource(env_2, await evaluatable.evaluateHandle(`(\n${functionSource}\n)`), false);
|
|
225
|
+
result = await evaluatable.evaluate(async (fn, ...args) => {
|
|
226
|
+
return JSON.stringify(await fn(...args));
|
|
227
|
+
}, fn, ...args);
|
|
191
228
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
229
|
+
catch (e_2) {
|
|
230
|
+
env_2.error = e_2;
|
|
231
|
+
env_2.hasError = true;
|
|
232
|
+
}
|
|
233
|
+
finally {
|
|
234
|
+
__disposeResources(env_2);
|
|
197
235
|
}
|
|
198
236
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
237
|
+
else {
|
|
238
|
+
const env_3 = { stack: [], error: void 0, hasError: false };
|
|
239
|
+
try {
|
|
240
|
+
const value = __addDisposableResource(env_3, await evaluatable.evaluateHandle(source), false);
|
|
241
|
+
result = await evaluatable.evaluate(value => JSON.stringify(value), value);
|
|
242
|
+
}
|
|
243
|
+
catch (e_3) {
|
|
244
|
+
env_3.error = e_3;
|
|
245
|
+
env_3.hasError = true;
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
__disposeResources(env_3);
|
|
249
|
+
}
|
|
202
250
|
}
|
|
203
|
-
|
|
204
|
-
|
|
251
|
+
if (options.filePath) {
|
|
252
|
+
const data = new TextEncoder().encode(result ?? 'undefined');
|
|
253
|
+
const { filename } = await options.context.saveFile(data, options.filePath, '.json');
|
|
254
|
+
response.appendResponseLine(`Script ran on page. Output saved to ${filename}.`);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
response.appendResponseLine('Script ran on page and returned:');
|
|
258
|
+
response.appendResponseLine('```json');
|
|
259
|
+
response.appendResponseLine(`${result}`);
|
|
260
|
+
response.appendResponseLine('```');
|
|
205
261
|
}
|
|
206
262
|
};
|
|
207
263
|
const getPageOrFrame = async (page, frames) => {
|
|
@@ -216,17 +272,14 @@ const getPageOrFrame = async (page, frames) => {
|
|
|
216
272
|
return pageOrFrame;
|
|
217
273
|
};
|
|
218
274
|
const getWebWorker = async (context, serviceWorkerId) => {
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
if (serviceWorker && serviceWorker.target) {
|
|
222
|
-
const worker = await serviceWorker.target.worker();
|
|
223
|
-
if (!worker) {
|
|
224
|
-
throw new Error('Service worker target not found.');
|
|
225
|
-
}
|
|
226
|
-
return worker;
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
275
|
+
const serviceWorker = context.getWorkerById(serviceWorkerId);
|
|
276
|
+
if (!serviceWorker || serviceWorker.type !== 'service_worker') {
|
|
229
277
|
throw new Error('Service worker not found.');
|
|
230
278
|
}
|
|
279
|
+
const worker = await serviceWorker.worker();
|
|
280
|
+
if (!worker) {
|
|
281
|
+
throw new Error('Service worker target not found.');
|
|
282
|
+
}
|
|
283
|
+
return worker;
|
|
231
284
|
};
|
|
232
285
|
//# sourceMappingURL=script.js.map
|
|
@@ -14,6 +14,7 @@ export const screenshot = definePageTool(() => ({
|
|
|
14
14
|
category: ToolCategory.DEBUGGING,
|
|
15
15
|
// Not read-only due to filePath param.
|
|
16
16
|
readOnlyHint: false,
|
|
17
|
+
conditions: ['slim'],
|
|
17
18
|
},
|
|
18
19
|
schema: {},
|
|
19
20
|
blockedByDialog: true,
|
|
@@ -35,6 +36,7 @@ export const navigate = definePageTool((args) => {
|
|
|
35
36
|
annotations: {
|
|
36
37
|
category: ToolCategory.NAVIGATION,
|
|
37
38
|
readOnlyHint: false,
|
|
39
|
+
conditions: ['slim'],
|
|
38
40
|
},
|
|
39
41
|
schema: {
|
|
40
42
|
url: zod.string().describe('URL to navigate to'),
|
|
@@ -45,6 +47,7 @@ export const navigate = definePageTool((args) => {
|
|
|
45
47
|
validateUrl(request.params.url, {
|
|
46
48
|
javascriptEvaluation: args?.javascriptEvaluation,
|
|
47
49
|
categoryExtensions: args?.categoryExtensions,
|
|
50
|
+
fileNavigations: args?.fileNavigations,
|
|
48
51
|
});
|
|
49
52
|
const page = request.page;
|
|
50
53
|
const options = {
|
|
@@ -75,7 +78,7 @@ export const evaluate = definePageTool(() => ({
|
|
|
75
78
|
annotations: {
|
|
76
79
|
category: ToolCategory.DEBUGGING,
|
|
77
80
|
readOnlyHint: false,
|
|
78
|
-
conditions: ['javascriptEvaluation'],
|
|
81
|
+
conditions: ['slim', 'javascriptEvaluation'],
|
|
79
82
|
},
|
|
80
83
|
schema: {
|
|
81
84
|
script: zod.string().describe(`JS script to run on the page`),
|
|
@@ -84,13 +87,8 @@ export const evaluate = definePageTool(() => ({
|
|
|
84
87
|
verifyFilesSchema: {},
|
|
85
88
|
handler: async (request, response) => {
|
|
86
89
|
const page = request.page;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
response.appendResponseLine(JSON.stringify(result));
|
|
90
|
-
}
|
|
91
|
-
catch (err) {
|
|
92
|
-
response.appendResponseLine(String(err.message));
|
|
93
|
-
}
|
|
90
|
+
const result = await page.pptrPage.evaluate(request.params.script);
|
|
91
|
+
response.appendResponseLine(JSON.stringify(result));
|
|
94
92
|
},
|
|
95
93
|
}));
|
|
96
94
|
//# sourceMappingURL=tools.js.map
|
|
@@ -8,9 +8,9 @@ import { ToolCategory } from './categories.js';
|
|
|
8
8
|
import { definePageTool } from './ToolDefinition.js';
|
|
9
9
|
export const listThirdPartyDeveloperTools = definePageTool(() => ({
|
|
10
10
|
name: 'list_3p_developer_tools',
|
|
11
|
-
description: `Lists all third-party developer tools the page exposes for providing runtime information.
|
|
11
|
+
description: `Lists all third-party developer tools the page exposes for providing runtime information (including debugging WebMCP tools and tools exposed via the 'devtoolstooldiscovery' event).
|
|
12
12
|
Third-party developer tools can be called via the 'execute_3p_developer_tool()' MCP tool.
|
|
13
|
-
Alternatively, third-party developer tools can be executed by calling 'evaluate_script' and adding the
|
|
13
|
+
Alternatively, third-party developer tools exposed via the 'devtoolstooldiscovery' event can be executed by calling 'evaluate_script' and adding the
|
|
14
14
|
following command to the script:
|
|
15
15
|
\`window.__dtmcp.executeTool(toolName, params)\`
|
|
16
16
|
This might be helpful when the third-party developer tools return non-serializable values or when composing
|
|
@@ -28,7 +28,7 @@ third-party developer tools with additional functionality.`,
|
|
|
28
28
|
}));
|
|
29
29
|
export const executeThirdPartyDeveloperTool = definePageTool(() => ({
|
|
30
30
|
name: 'execute_3p_developer_tool',
|
|
31
|
-
description: `Executes a tool exposed by the page.`,
|
|
31
|
+
description: `Executes a third-party developer tool exposed by the page.`,
|
|
32
32
|
annotations: {
|
|
33
33
|
category: ToolCategory.THIRD_PARTY,
|
|
34
34
|
readOnlyHint: false,
|
|
@@ -48,7 +48,9 @@ export const executeThirdPartyDeveloperTool = definePageTool(() => ({
|
|
|
48
48
|
if (request.params.params) {
|
|
49
49
|
try {
|
|
50
50
|
const parsed = JSON.parse(request.params.params);
|
|
51
|
-
if (typeof parsed === 'object' &&
|
|
51
|
+
if (typeof parsed === 'object' &&
|
|
52
|
+
parsed !== null &&
|
|
53
|
+
!Array.isArray(parsed)) {
|
|
52
54
|
params = parsed;
|
|
53
55
|
}
|
|
54
56
|
else {
|
package/build/src/tools/tools.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { mcpOptions } from '../config/mcp-options.js';
|
|
6
7
|
import * as commentsTools from './comments.js';
|
|
7
8
|
import * as consoleTools from './console.js';
|
|
8
9
|
import * as cssTools from './css.js';
|
|
@@ -23,28 +24,27 @@ import * as snapshotTools from './snapshot.js';
|
|
|
23
24
|
import * as thirdPartyDeveloperTools from './thirdPartyDeveloper.js';
|
|
24
25
|
import * as webmcpTools from './webmcp.js';
|
|
25
26
|
export const createTools = (args) => {
|
|
26
|
-
const rawTools =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
];
|
|
27
|
+
const rawTools = [
|
|
28
|
+
...Object.values(commentsTools),
|
|
29
|
+
...Object.values(consoleTools),
|
|
30
|
+
...Object.values(cssTools),
|
|
31
|
+
...Object.values(emulationTools),
|
|
32
|
+
...Object.values(extensionTools),
|
|
33
|
+
...Object.values(inputTools),
|
|
34
|
+
...Object.values(lighthouseTools),
|
|
35
|
+
...Object.values(memoryTools),
|
|
36
|
+
...Object.values(networkTools),
|
|
37
|
+
...Object.values(pagesTools),
|
|
38
|
+
...Object.values(performanceTools),
|
|
39
|
+
...Object.values(pwaTools),
|
|
40
|
+
...Object.values(screencastTools),
|
|
41
|
+
...Object.values(screenshotTools),
|
|
42
|
+
...Object.values(scriptTools),
|
|
43
|
+
...Object.values(slimTools),
|
|
44
|
+
...Object.values(snapshotTools),
|
|
45
|
+
...Object.values(thirdPartyDeveloperTools),
|
|
46
|
+
...Object.values(webmcpTools),
|
|
47
|
+
];
|
|
48
48
|
const tools = [];
|
|
49
49
|
for (const tool of rawTools) {
|
|
50
50
|
tools.push(tool(args));
|
|
@@ -52,4 +52,17 @@ export const createTools = (args) => {
|
|
|
52
52
|
tools.sort((a, b) => a.name.localeCompare(b.name));
|
|
53
53
|
return tools;
|
|
54
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* Returns true if the tool is gated behind a hidden (internal) flag. Such
|
|
57
|
+
* tools are excluded from the generated documentation and CLI.
|
|
58
|
+
*/
|
|
59
|
+
export function requiresHiddenFlag(tool) {
|
|
60
|
+
for (const condition of tool.annotations.conditions ?? []) {
|
|
61
|
+
const option = mcpOptions[condition];
|
|
62
|
+
if (option.hidden) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
55
68
|
//# sourceMappingURL=tools.js.map
|
|
@@ -8,7 +8,7 @@ import { ToolCategory } from './categories.js';
|
|
|
8
8
|
import { definePageTool } from './ToolDefinition.js';
|
|
9
9
|
export const listWebMcpTools = definePageTool(() => ({
|
|
10
10
|
name: 'list_webmcp_tools',
|
|
11
|
-
description: `Lists all WebMCP tools the page exposes.`,
|
|
11
|
+
description: `Lists all WebMCP tools the page exposes (excluding debugging tools, which are exposed via 'list_3p_developer_tools').`,
|
|
12
12
|
annotations: {
|
|
13
13
|
category: ToolCategory.WEBMCP,
|
|
14
14
|
readOnlyHint: true,
|
|
@@ -22,7 +22,7 @@ export const listWebMcpTools = definePageTool(() => ({
|
|
|
22
22
|
}));
|
|
23
23
|
export const executeWebMcpTool = definePageTool(() => ({
|
|
24
24
|
name: 'execute_webmcp_tool',
|
|
25
|
-
description: `Executes a WebMCP tool exposed by the page.`,
|
|
25
|
+
description: `Executes a WebMCP tool exposed by the page (for debugging tools, use 'execute_3p_developer_tool').`,
|
|
26
26
|
annotations: {
|
|
27
27
|
category: ToolCategory.WEBMCP,
|
|
28
28
|
readOnlyHint: false,
|
|
@@ -42,7 +42,9 @@ export const executeWebMcpTool = definePageTool(() => ({
|
|
|
42
42
|
if (request.params.input) {
|
|
43
43
|
try {
|
|
44
44
|
const parsed = JSON.parse(request.params.input);
|
|
45
|
-
if (typeof parsed === 'object' &&
|
|
45
|
+
if (typeof parsed === 'object' &&
|
|
46
|
+
parsed !== null &&
|
|
47
|
+
!Array.isArray(parsed)) {
|
|
46
48
|
input = parsed;
|
|
47
49
|
}
|
|
48
50
|
else {
|
|
@@ -54,13 +56,14 @@ export const executeWebMcpTool = definePageTool(() => ({
|
|
|
54
56
|
throw new Error(`Failed to parse input as JSON: ${errorMessage}`);
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
|
-
const tools = request.page.
|
|
59
|
+
const tools = request.page.getWebMcpTools();
|
|
58
60
|
const tool = tools.find(t => t.name === toolName);
|
|
59
61
|
if (!tool) {
|
|
60
62
|
throw new Error(`Tool ${toolName} not found`);
|
|
61
63
|
}
|
|
62
|
-
const { status, output, errorText } = await tool.execute(input);
|
|
63
|
-
|
|
64
|
+
const { status, output, errorText, exception } = await tool.execute(input);
|
|
65
|
+
const error = exception?.description ?? exception?.value ?? errorText;
|
|
66
|
+
response.appendResponseLine(JSON.stringify({ status, output, error }, null, 2));
|
|
64
67
|
},
|
|
65
68
|
}));
|
|
66
69
|
//# sourceMappingURL=webmcp.js.map
|
package/build/src/types.js
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
export const FORCED_COLORS_VALUES = ['active', 'none'];
|
|
7
|
+
export const PREFERS_CONTRAST_VALUES = [
|
|
8
|
+
'more',
|
|
9
|
+
'less',
|
|
10
|
+
'custom',
|
|
11
|
+
'no-preference',
|
|
12
|
+
];
|
|
13
|
+
export const PREFERS_REDUCED_MOTION_VALUES = [
|
|
14
|
+
'reduce',
|
|
15
|
+
'no-preference',
|
|
16
|
+
];
|
|
6
17
|
export var CD4ABridgeEvents;
|
|
7
18
|
(function (CD4ABridgeEvents) {
|
|
8
19
|
CD4ABridgeEvents["COMMENT_THREADS_CHANGED"] = "CommentThreadsChanged";
|
|
@@ -59,6 +59,7 @@ import { logger } from './logger.js';
|
|
|
59
59
|
export class WaitForHelper {
|
|
60
60
|
#abortController = new AbortController();
|
|
61
61
|
#page;
|
|
62
|
+
#publicPage;
|
|
62
63
|
#stableDomTimeout;
|
|
63
64
|
#stableDomFor;
|
|
64
65
|
#expectNavigationIn;
|
|
@@ -67,12 +68,14 @@ export class WaitForHelper {
|
|
|
67
68
|
/** Track all dialogs as they pause the renderer. */
|
|
68
69
|
#dialogDetected = false;
|
|
69
70
|
#initialUrl;
|
|
71
|
+
#openedPages = new Set();
|
|
70
72
|
constructor(page, cpuTimeoutMultiplier, networkTimeoutMultiplier) {
|
|
71
73
|
this.#stableDomTimeout = 3000 * cpuTimeoutMultiplier;
|
|
72
74
|
this.#stableDomFor = 100 * cpuTimeoutMultiplier;
|
|
73
75
|
this.#expectNavigationIn = 100 * cpuTimeoutMultiplier;
|
|
74
76
|
this.#navigationTimeout = 3000 * networkTimeoutMultiplier;
|
|
75
77
|
this.#page = page;
|
|
78
|
+
this.#publicPage = page;
|
|
76
79
|
this.#initialUrl = page.url();
|
|
77
80
|
}
|
|
78
81
|
/**
|
|
@@ -126,7 +129,7 @@ export class WaitForHelper {
|
|
|
126
129
|
// Ignored cleanup errors
|
|
127
130
|
}
|
|
128
131
|
});
|
|
129
|
-
return Promise.race([
|
|
132
|
+
return await Promise.race([
|
|
130
133
|
stableDomObserver.evaluate(async (observer) => {
|
|
131
134
|
return await observer.resolver.promise;
|
|
132
135
|
}),
|
|
@@ -188,6 +191,15 @@ export class WaitForHelper {
|
|
|
188
191
|
this.#abortController.signal.addEventListener('abort', () => {
|
|
189
192
|
this.#page.off('dialog', dialogHandler);
|
|
190
193
|
});
|
|
194
|
+
const popupHandler = (page) => {
|
|
195
|
+
if (page) {
|
|
196
|
+
this.#openedPages.add(page.target());
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
this.#publicPage.on('popup', popupHandler);
|
|
200
|
+
this.#abortController.signal.addEventListener('abort', () => {
|
|
201
|
+
this.#publicPage.off('popup', popupHandler);
|
|
202
|
+
});
|
|
191
203
|
// A scoped AbortController used to clean up navigation probe listeners.
|
|
192
204
|
// When aborted (either after navigation detection finishes or if this.#abortController
|
|
193
205
|
// aborts), it removes CDP navigation probe listeners and automatically
|
|
@@ -296,6 +308,7 @@ export class WaitForHelper {
|
|
|
296
308
|
? { navigatedToUrl: urlAfterAction }
|
|
297
309
|
: {}),
|
|
298
310
|
dialogHandled: this.#dialogHandled,
|
|
311
|
+
...(this.#openedPages.size ? { openedPages: this.#openedPages } : {}),
|
|
299
312
|
};
|
|
300
313
|
}
|
|
301
314
|
}
|
|
@@ -15,7 +15,7 @@ import { VERSION } from '../version.js';
|
|
|
15
15
|
* @param message The message to display in the update notification.
|
|
16
16
|
*/
|
|
17
17
|
let isChecking = false;
|
|
18
|
-
/** @internal
|
|
18
|
+
/** @internal */
|
|
19
19
|
export function resetUpdateCheckFlagForTesting() {
|
|
20
20
|
isChecking = false;
|
|
21
21
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import process from 'node:process';
|
|
7
|
+
import { logger } from './logger.js';
|
|
8
|
+
export function getErrorMessage(err) {
|
|
9
|
+
return err instanceof Error ? err.message : String(err);
|
|
10
|
+
}
|
|
11
|
+
export function setupUnhandledRejectionHandler(onCrash) {
|
|
12
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
13
|
+
logger?.('Unhandled promise rejection:', promise, reason);
|
|
14
|
+
console.error('Unhandled promise rejection:', reason);
|
|
15
|
+
if (process.env['CHROME_DEVTOOLS_MCP_CRASH_ON_UNCAUGHT'] === 'true') {
|
|
16
|
+
onCrash();
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=errorHandling.js.map
|
|
@@ -7,7 +7,7 @@ import fs from 'node:fs';
|
|
|
7
7
|
import util from 'node:util';
|
|
8
8
|
const mcpDebugNamespace = 'mcp:log';
|
|
9
9
|
let logFileStream;
|
|
10
|
-
const
|
|
10
|
+
const debugLog = util.debuglog(mcpDebugNamespace);
|
|
11
11
|
export function saveLogsToFile(fileName) {
|
|
12
12
|
const logFile = fs.createWriteStream(fileName, { flags: 'a+' });
|
|
13
13
|
logFile.on('error', function (error) {
|
|
@@ -27,12 +27,21 @@ export function flushLogs(logFile, timeoutMs = 2000) {
|
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Encodes a value for interpolation into a one-line log or error message. The
|
|
32
|
+
* result is a JSON string literal that also escapes DEL, C1 controls and
|
|
33
|
+
* U+2028/U+2029, which JSON.stringify leaves raw but terminals and line
|
|
34
|
+
* readers act on.
|
|
35
|
+
*/
|
|
36
|
+
export function escapeForLog(value) {
|
|
37
|
+
return JSON.stringify(value).replace(/[\u007f-\u009f\u2028\u2029]/g, char => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`);
|
|
38
|
+
}
|
|
30
39
|
export const logger = (...args) => {
|
|
31
40
|
if (logFileStream) {
|
|
32
41
|
logFileStream.write(`${new Date().toISOString()} ${mcpDebugNamespace} ${util.format(...args)}\n`);
|
|
33
42
|
}
|
|
34
|
-
else if (
|
|
35
|
-
|
|
43
|
+
else if (debugLog.enabled) {
|
|
44
|
+
debugLog('%s %s', new Date().toISOString(), util.format(...args));
|
|
36
45
|
}
|
|
37
46
|
};
|
|
38
47
|
export const puppeteerLogger = (prefix) => {
|
|
@@ -40,9 +49,10 @@ export const puppeteerLogger = (prefix) => {
|
|
|
40
49
|
if (!dbg.enabled) {
|
|
41
50
|
return;
|
|
42
51
|
}
|
|
43
|
-
|
|
52
|
+
const stream = logFileStream;
|
|
53
|
+
if (stream) {
|
|
44
54
|
return (...args) => {
|
|
45
|
-
|
|
55
|
+
stream.write(`${new Date().toISOString()} ${prefix} ${util.format(...args)}\n`);
|
|
46
56
|
};
|
|
47
57
|
}
|
|
48
58
|
return (...args) => {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
const VALID_PLACEHOLDER_MATCH_PATTERN = /\{(PLACEHOLDER_[a-zA-Z][a-zA-Z0-9_]*)\}/g;
|
|
7
|
+
export function substitutePlaceholders(rawMarkdown, substitutions) {
|
|
8
|
+
if (!substitutions) {
|
|
9
|
+
return rawMarkdown;
|
|
10
|
+
}
|
|
11
|
+
return rawMarkdown.replace(VALID_PLACEHOLDER_MATCH_PATTERN, (_, placeholder) => {
|
|
12
|
+
return substitutions.get(placeholder) ?? '';
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=text.js.map
|