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
|
@@ -56,9 +56,9 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
56
56
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
57
57
|
});
|
|
58
58
|
import { pathToFileURL } from 'node:url';
|
|
59
|
-
import { zod } from '../third_party/index.js';
|
|
59
|
+
import { zod, } from '../third_party/index.js';
|
|
60
60
|
import { ToolCategory } from './categories.js';
|
|
61
|
-
import { defineTool, pageIdSchema } from './ToolDefinition.js';
|
|
61
|
+
import { defineTool, pageIdSchema, } from './ToolDefinition.js';
|
|
62
62
|
export const evaluateScript = defineTool((cliArgs) => {
|
|
63
63
|
return {
|
|
64
64
|
name: 'evaluate_script',
|
|
@@ -121,10 +121,13 @@ Example with arguments: \`(el) => el.innerText\`
|
|
|
121
121
|
}
|
|
122
122
|
: {}),
|
|
123
123
|
},
|
|
124
|
-
blockedByDialog:
|
|
124
|
+
blockedByDialog: false,
|
|
125
|
+
concurrency: 'exclusive',
|
|
125
126
|
verifyFilesSchema: {
|
|
126
127
|
filePath: true,
|
|
127
|
-
sourcePath:
|
|
128
|
+
// sourcePath may be an http(s): URL the server fetches, so allow URLs
|
|
129
|
+
// through; a file: path or plain path is still validated.
|
|
130
|
+
sourcePath: { local: true, remote: true, allowUrl: true },
|
|
128
131
|
},
|
|
129
132
|
handler: async (request, response, context) => {
|
|
130
133
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
@@ -164,7 +167,13 @@ Example with arguments: \`(el) => el.innerText\`
|
|
|
164
167
|
const mcpPage = cliArgs.pageIdRouting && request.params.pageId
|
|
165
168
|
? context.getPageById(request.params.pageId)
|
|
166
169
|
: context.getSelectedMcpPage();
|
|
167
|
-
await mcpPage.init();
|
|
170
|
+
await mcpPage.init({ emulateFocus: true });
|
|
171
|
+
// evaluate_script is not page-scoped, so ToolHandler does not run the
|
|
172
|
+
// blockedByDialog check for it. Without this, an evaluation started
|
|
173
|
+
// while a dialog is open waits until the protocol timeout.
|
|
174
|
+
// TODO: include the "# Open dialog ... Call handle_dialog" hint once
|
|
175
|
+
// Response can attach the page for non-page-scoped tools.
|
|
176
|
+
mcpPage.throwIfDialogOpen();
|
|
168
177
|
const page = mcpPage.pptrPage;
|
|
169
178
|
const args = [];
|
|
170
179
|
const stack = __addDisposableResource(env_1, new DisposableStack(), false);
|
|
@@ -222,8 +231,31 @@ const performEvaluation = async (evaluatable, source, format, args, response, op
|
|
|
222
231
|
try {
|
|
223
232
|
const functionSource = source.trimEnd().replace(/;$/, '');
|
|
224
233
|
const fn = __addDisposableResource(env_2, await evaluatable.evaluateHandle(`(\n${functionSource}\n)`), false);
|
|
234
|
+
// Normalize non-Error values inside the page callback (serialized by Puppeteer) so CDP preserves the message.
|
|
225
235
|
result = await evaluatable.evaluate(async (fn, ...args) => {
|
|
226
|
-
|
|
236
|
+
try {
|
|
237
|
+
return JSON.stringify(await fn(...args));
|
|
238
|
+
}
|
|
239
|
+
catch (err) {
|
|
240
|
+
if (err instanceof Error ||
|
|
241
|
+
(typeof err === 'object' &&
|
|
242
|
+
err !== null &&
|
|
243
|
+
'message' in err &&
|
|
244
|
+
typeof err.message === 'string')) {
|
|
245
|
+
throw err;
|
|
246
|
+
}
|
|
247
|
+
let message;
|
|
248
|
+
try {
|
|
249
|
+
message =
|
|
250
|
+
typeof err === 'object' && err !== null
|
|
251
|
+
? JSON.stringify(err)
|
|
252
|
+
: String(err);
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
message = String(err);
|
|
256
|
+
}
|
|
257
|
+
throw new Error(message);
|
|
258
|
+
}
|
|
227
259
|
}, fn, ...args);
|
|
228
260
|
}
|
|
229
261
|
catch (e_2) {
|
|
@@ -9,24 +9,38 @@ import { definePageTool } from '../ToolDefinition.js';
|
|
|
9
9
|
import { validateUrl } from '../../utils/url.js';
|
|
10
10
|
export const screenshot = definePageTool(() => ({
|
|
11
11
|
name: 'screenshot',
|
|
12
|
-
description: `Takes a screenshot`,
|
|
12
|
+
description: `Takes a png screenshot`,
|
|
13
13
|
annotations: {
|
|
14
14
|
category: ToolCategory.DEBUGGING,
|
|
15
15
|
// Not read-only due to filePath param.
|
|
16
16
|
readOnlyHint: false,
|
|
17
17
|
conditions: ['slim'],
|
|
18
18
|
},
|
|
19
|
-
schema: {
|
|
19
|
+
schema: {
|
|
20
|
+
filePath: zod
|
|
21
|
+
.string()
|
|
22
|
+
.optional()
|
|
23
|
+
.describe('The absolute path, or a path relative to the current working directory, to save the screenshot to instead of attaching it to the response.'),
|
|
24
|
+
},
|
|
20
25
|
blockedByDialog: true,
|
|
21
|
-
|
|
26
|
+
concurrency: 'page',
|
|
27
|
+
verifyFilesSchema: {
|
|
28
|
+
filePath: true,
|
|
29
|
+
},
|
|
22
30
|
handler: async (request, response, context) => {
|
|
23
31
|
const page = request.page;
|
|
24
32
|
const screenshot = await page.pptrPage.screenshot({
|
|
25
33
|
type: 'png',
|
|
26
34
|
optimizeForSpeed: true,
|
|
27
35
|
});
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
if (request.params.filePath) {
|
|
37
|
+
const result = await context.saveFile(screenshot, request.params.filePath, '.png');
|
|
38
|
+
response.appendResponseLine(result.filename);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const { filepath } = await context.saveTemporaryFile(screenshot, `screenshot.png`);
|
|
42
|
+
response.appendResponseLine(filepath);
|
|
43
|
+
}
|
|
30
44
|
},
|
|
31
45
|
}));
|
|
32
46
|
export const navigate = definePageTool((args) => {
|
|
@@ -42,6 +56,7 @@ export const navigate = definePageTool((args) => {
|
|
|
42
56
|
url: zod.string().describe('URL to navigate to'),
|
|
43
57
|
},
|
|
44
58
|
blockedByDialog: false,
|
|
59
|
+
concurrency: 'page',
|
|
45
60
|
verifyFilesSchema: {},
|
|
46
61
|
handler: async (request, response) => {
|
|
47
62
|
validateUrl(request.params.url, {
|
|
@@ -84,6 +99,7 @@ export const evaluate = definePageTool(() => ({
|
|
|
84
99
|
script: zod.string().describe(`JS script to run on the page`),
|
|
85
100
|
},
|
|
86
101
|
blockedByDialog: true,
|
|
102
|
+
concurrency: 'page',
|
|
87
103
|
verifyFilesSchema: {},
|
|
88
104
|
handler: async (request, response) => {
|
|
89
105
|
const page = request.page;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { zod } from '../third_party/index.js';
|
|
7
7
|
import { ToolCategory } from './categories.js';
|
|
8
|
-
import { definePageTool, timeoutSchema } from './ToolDefinition.js';
|
|
8
|
+
import { definePageTool, timeoutSchema, } from './ToolDefinition.js';
|
|
9
9
|
export const takeSnapshot = definePageTool(() => ({
|
|
10
10
|
name: 'take_snapshot',
|
|
11
11
|
description: `Take a text snapshot of the target page based on the a11y tree. The snapshot lists page elements along with a unique
|
|
@@ -27,6 +27,7 @@ in the DevTools Elements panel (if any).`,
|
|
|
27
27
|
.describe('The absolute path, or a path relative to the current working directory, to save the snapshot to instead of attaching it to the response.'),
|
|
28
28
|
},
|
|
29
29
|
blockedByDialog: true,
|
|
30
|
+
concurrency: 'page',
|
|
30
31
|
verifyFilesSchema: {
|
|
31
32
|
filePath: true,
|
|
32
33
|
},
|
|
@@ -39,7 +40,7 @@ in the DevTools Elements panel (if any).`,
|
|
|
39
40
|
}));
|
|
40
41
|
export const waitFor = definePageTool(() => ({
|
|
41
42
|
name: 'wait_for',
|
|
42
|
-
description: `Wait for the specified text to appear on the selected page.`,
|
|
43
|
+
description: `Wait for the specified text to appear on the selected page. By default, hidden text is also matched. Set visible to true to wait until the matched text is visible.`,
|
|
43
44
|
annotations: {
|
|
44
45
|
category: ToolCategory.NAVIGATION,
|
|
45
46
|
readOnlyHint: true,
|
|
@@ -50,12 +51,21 @@ export const waitFor = definePageTool(() => ({
|
|
|
50
51
|
.min(1)
|
|
51
52
|
.describe('Non-empty list of texts. Resolves when any value appears on the page.'),
|
|
52
53
|
...timeoutSchema,
|
|
54
|
+
visible: zod
|
|
55
|
+
.boolean()
|
|
56
|
+
.default(false)
|
|
57
|
+
.optional()
|
|
58
|
+
.describe('If true, wait until the matching text is visible. By default, hidden text also counts.'),
|
|
53
59
|
},
|
|
54
60
|
blockedByDialog: true,
|
|
61
|
+
concurrency: 'page',
|
|
55
62
|
verifyFilesSchema: {},
|
|
56
63
|
handler: async (request, response) => {
|
|
57
64
|
const page = request.page;
|
|
58
|
-
await page.waitForTextOnPage(request.params.text,
|
|
65
|
+
await page.waitForTextOnPage(request.params.text, {
|
|
66
|
+
timeout: request.params.timeout,
|
|
67
|
+
visible: request.params.visible,
|
|
68
|
+
});
|
|
59
69
|
response.appendResponseLine(`Element matching one of ${JSON.stringify(request.params.text)} found.`);
|
|
60
70
|
response.includeSnapshot();
|
|
61
71
|
},
|
|
@@ -21,6 +21,7 @@ third-party developer tools with additional functionality.`,
|
|
|
21
21
|
},
|
|
22
22
|
schema: {},
|
|
23
23
|
blockedByDialog: false,
|
|
24
|
+
concurrency: 'page',
|
|
24
25
|
verifyFilesSchema: {},
|
|
25
26
|
handler: async (_request, response) => {
|
|
26
27
|
response.setListThirdPartyDeveloperTools();
|
|
@@ -41,6 +42,7 @@ export const executeThirdPartyDeveloperTool = definePageTool(() => ({
|
|
|
41
42
|
.describe('The JSON-stringified parameters to pass to the tool'),
|
|
42
43
|
},
|
|
43
44
|
blockedByDialog: false,
|
|
45
|
+
concurrency: 'page',
|
|
44
46
|
verifyFilesSchema: {},
|
|
45
47
|
handler: async (request, response) => {
|
|
46
48
|
const toolName = request.params.toolName;
|
|
@@ -62,7 +64,7 @@ export const executeThirdPartyDeveloperTool = definePageTool(() => ({
|
|
|
62
64
|
throw new Error(`Failed to parse params as JSON: ${errorMessage}`);
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
|
-
const toolGroups = request.page.
|
|
67
|
+
const toolGroups = await request.page.discoverThirdPartyDeveloperTools();
|
|
66
68
|
let tool;
|
|
67
69
|
if (toolGroups) {
|
|
68
70
|
for (const group of toolGroups) {
|
|
@@ -15,6 +15,7 @@ export const listWebMcpTools = definePageTool(() => ({
|
|
|
15
15
|
},
|
|
16
16
|
schema: {},
|
|
17
17
|
blockedByDialog: false,
|
|
18
|
+
concurrency: 'page',
|
|
18
19
|
verifyFilesSchema: {},
|
|
19
20
|
handler: async (_request, response) => {
|
|
20
21
|
response.setListWebMcpTools();
|
|
@@ -35,6 +36,7 @@ export const executeWebMcpTool = definePageTool(() => ({
|
|
|
35
36
|
.describe('The JSON-stringified parameters to pass to the WebMCP tool'),
|
|
36
37
|
},
|
|
37
38
|
blockedByDialog: false,
|
|
39
|
+
concurrency: 'page',
|
|
38
40
|
verifyFilesSchema: {},
|
|
39
41
|
handler: async (request, response) => {
|
|
40
42
|
const toolName = request.params.toolName;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A queue that the {@link TaskRunner} created. Tasks on one queue run one
|
|
8
|
+
* at a time. Tasks on a queue and on its ancestors or descendants also run
|
|
9
|
+
* one at a time. Tasks on unrelated queues run at the same time.
|
|
10
|
+
*/
|
|
11
|
+
export class TaskQueue {
|
|
12
|
+
parent;
|
|
13
|
+
#hooks;
|
|
14
|
+
#disposed;
|
|
15
|
+
constructor(hooks, parent) {
|
|
16
|
+
this.#hooks = hooks;
|
|
17
|
+
this.parent = parent;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Schedules a task on this queue. Resolves when no earlier task on a
|
|
21
|
+
* related queue runs, with a guard that holds the queue until it is
|
|
22
|
+
* disposed. Rejects when the queue is disposed while the task waits. A
|
|
23
|
+
* second dispose of the guard throws.
|
|
24
|
+
*/
|
|
25
|
+
async scheduleTask() {
|
|
26
|
+
if (this.#disposed) {
|
|
27
|
+
throw this.#disposed;
|
|
28
|
+
}
|
|
29
|
+
return await this.#hooks.scheduleTask(this);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Rejects the callers that wait on this queue with `reason`, and rejects
|
|
33
|
+
* every later `scheduleTask()` call. The current holder keeps the queue.
|
|
34
|
+
*/
|
|
35
|
+
dispose(reason) {
|
|
36
|
+
this.#disposed = reason;
|
|
37
|
+
this.#hooks.cancel(this, reason);
|
|
38
|
+
}
|
|
39
|
+
/** True when `other` is this queue, an ancestor, or a descendant. */
|
|
40
|
+
isRelatedTo(other) {
|
|
41
|
+
return this.#isAncestorOrSelf(other) || other.#isAncestorOrSelf(this);
|
|
42
|
+
}
|
|
43
|
+
#isAncestorOrSelf(other) {
|
|
44
|
+
for (let queue = other; queue; queue = queue.parent) {
|
|
45
|
+
if (queue === this) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Runs every task of the server from one ordered list. Each task names the
|
|
54
|
+
* queue it runs on. A task starts when every earlier task on a related queue
|
|
55
|
+
* has finished. Waiting tasks count, so a waiting task blocks later related
|
|
56
|
+
* tasks and no task starves. `pause()` enters the list ahead of waiting tasks
|
|
57
|
+
* and relates to every queue.
|
|
58
|
+
*/
|
|
59
|
+
export class TaskRunner {
|
|
60
|
+
#hooks = {
|
|
61
|
+
scheduleTask: queue => this.#scheduleTask(queue),
|
|
62
|
+
cancel: (queue, reason) => this.#cancel(queue, reason),
|
|
63
|
+
};
|
|
64
|
+
#root = new TaskQueue(this.#hooks, undefined);
|
|
65
|
+
#entries = [];
|
|
66
|
+
/**
|
|
67
|
+
* Creates a queue. Tasks on the new queue and tasks on `parent` wait for
|
|
68
|
+
* each other. Without `parent`, the queue is a child of the root, so only
|
|
69
|
+
* `pause()` relates to it.
|
|
70
|
+
*/
|
|
71
|
+
createQueue(parent = this.#root) {
|
|
72
|
+
return new TaskQueue(this.#hooks, parent);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Stops new tasks on every queue. The pause goes ahead of waiting tasks and
|
|
76
|
+
* resolves when every running task has finished. Disposing the guard
|
|
77
|
+
* resumes the runner.
|
|
78
|
+
*/
|
|
79
|
+
async pause() {
|
|
80
|
+
return await this.#scheduleTask(this.#root, 'high');
|
|
81
|
+
}
|
|
82
|
+
async #scheduleTask(queue, priority = 'normal') {
|
|
83
|
+
const { guard, started } = this.#enter(queue, priority);
|
|
84
|
+
await started;
|
|
85
|
+
return guard;
|
|
86
|
+
}
|
|
87
|
+
#cancel(queue, reason) {
|
|
88
|
+
for (const entry of [...this.#entries]) {
|
|
89
|
+
if (entry.queue === queue && !entry.running) {
|
|
90
|
+
this.#leave(entry);
|
|
91
|
+
entry.reject(reason);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
#enter(queue, priority) {
|
|
96
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
97
|
+
const entry = { queue, priority, running: false, resolve, reject };
|
|
98
|
+
// A high-priority entry goes before the first waiting normal entry.
|
|
99
|
+
const index = priority === 'high'
|
|
100
|
+
? this.#entries.findIndex(e => !e.running && e.priority === 'normal')
|
|
101
|
+
: -1;
|
|
102
|
+
this.#entries.splice(index === -1 ? this.#entries.length : index, 0, entry);
|
|
103
|
+
this.#schedule();
|
|
104
|
+
return {
|
|
105
|
+
started: promise,
|
|
106
|
+
guard: {
|
|
107
|
+
[Symbol.dispose]: () => {
|
|
108
|
+
this.#leave(entry);
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
#leave(entry) {
|
|
114
|
+
const index = this.#entries.indexOf(entry);
|
|
115
|
+
if (index === -1) {
|
|
116
|
+
throw new Error('The guard was already disposed.');
|
|
117
|
+
}
|
|
118
|
+
this.#entries.splice(index, 1);
|
|
119
|
+
this.#schedule();
|
|
120
|
+
}
|
|
121
|
+
#schedule() {
|
|
122
|
+
for (const [index, entry] of this.#entries.entries()) {
|
|
123
|
+
if (entry.running) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const blocked = this.#entries
|
|
127
|
+
.slice(0, index)
|
|
128
|
+
.some(earlier => earlier.queue.isRelatedTo(entry.queue));
|
|
129
|
+
if (!blocked) {
|
|
130
|
+
entry.running = true;
|
|
131
|
+
entry.resolve();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=TaskRunner.js.map
|
|
@@ -88,7 +88,7 @@ export class WaitForHelper {
|
|
|
88
88
|
try {
|
|
89
89
|
// Bound the setup evaluation against the stable-DOM timeout. Without this
|
|
90
90
|
// cap a paused renderer (e.g. an open dialog) would make evaluateHandle
|
|
91
|
-
// hang until protocolTimeout (default 180s)
|
|
91
|
+
// hang until protocolTimeout (default 180s) inside the context queue.
|
|
92
92
|
const stableDomObserver = __addDisposableResource(env_1, await Promise.race([
|
|
93
93
|
this.#page.evaluateHandle(timeout => {
|
|
94
94
|
let timeoutId;
|
package/build/src/utils/bytes.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { zod } from '../third_party/index.js';
|
|
7
|
+
import { zodTransform } from '../tools/ToolDefinition.js';
|
|
7
8
|
const BYTE_UNITS = {
|
|
8
9
|
b: 1,
|
|
9
10
|
byte: 1,
|
|
@@ -88,18 +89,7 @@ export function parseByteSizeRange(value) {
|
|
|
88
89
|
export function byteSizeRangeSchema(description) {
|
|
89
90
|
return zod
|
|
90
91
|
.string()
|
|
91
|
-
.transform((
|
|
92
|
-
try {
|
|
93
|
-
return parseByteSizeRange(value);
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
context.addIssue({
|
|
97
|
-
code: zod.ZodIssueCode.custom,
|
|
98
|
-
message: error instanceof Error ? error.message : 'Invalid byte size range',
|
|
99
|
-
});
|
|
100
|
-
return zod.NEVER;
|
|
101
|
-
}
|
|
102
|
-
})
|
|
92
|
+
.transform(zodTransform(parseByteSizeRange))
|
|
103
93
|
.describe(description);
|
|
104
94
|
}
|
|
105
95
|
//# sourceMappingURL=bytes.js.map
|
|
@@ -8,7 +8,7 @@ import fs from 'node:fs/promises';
|
|
|
8
8
|
import os from 'node:os';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import process from 'node:process';
|
|
11
|
-
import { semver } from '../third_party/
|
|
11
|
+
import { semver } from '../third_party/cli.js';
|
|
12
12
|
import { VERSION } from '../version.js';
|
|
13
13
|
/**
|
|
14
14
|
* Notifies the user if an update is available.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export function logCruxDisclaimer(args) {
|
|
7
|
+
if (!args.slim && args.performanceCrux) {
|
|
8
|
+
console.error(`Performance tools may send trace URLs to the Google CrUX API to fetch real-user experience data. To disable, run with --no-performance-crux.`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Prints the privacy disclaimers to stderr. Both the server and the CLI
|
|
13
|
+
* client call it. The CLI must not load `src/index.ts`, so this function
|
|
14
|
+
* lives in its own module.
|
|
15
|
+
*/
|
|
16
|
+
export const logDisclaimers = (args) => {
|
|
17
|
+
console.error(`chrome-devtools-mcp exposes content of the browser instance to the MCP clients allowing them to inspect,
|
|
18
|
+
debug, and modify any data in the browser or DevTools.
|
|
19
|
+
Avoid sharing sensitive or personal information that you do not want to share with MCP clients.`);
|
|
20
|
+
logCruxDisclaimer(args);
|
|
21
|
+
if (!args.slim && args.usageStatistics) {
|
|
22
|
+
console.error(`
|
|
23
|
+
Google collects usage statistics to improve Chrome DevTools MCP. To opt-out, run with --no-usage-statistics.
|
|
24
|
+
For more details, visit: https://github.com/ChromeDevTools/chrome-devtools-mcp#usage-statistics`);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=disclaimers.js.map
|
|
@@ -261,11 +261,23 @@ const validKeys = new Set([
|
|
|
261
261
|
'VolumeDown',
|
|
262
262
|
'VolumeUp',
|
|
263
263
|
]);
|
|
264
|
+
/**
|
|
265
|
+
* Whether the string is a single valid key name (no `+` combinations).
|
|
266
|
+
*/
|
|
267
|
+
export function isValidKey(key) {
|
|
268
|
+
return validKeys.has(key);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Error message for a string that is not a valid key name.
|
|
272
|
+
*/
|
|
273
|
+
export function invalidKeyMessage(key) {
|
|
274
|
+
return `${key} is invalid. Valid keys are: ${Array.from(validKeys.values()).join(',')}.`;
|
|
275
|
+
}
|
|
264
276
|
function throwIfInvalidKey(key) {
|
|
265
|
-
if (
|
|
277
|
+
if (isValidKey(key)) {
|
|
266
278
|
return key;
|
|
267
279
|
}
|
|
268
|
-
throw new Error(
|
|
280
|
+
throw new Error(invalidKeyMessage(key));
|
|
269
281
|
}
|
|
270
282
|
/**
|
|
271
283
|
* Returns the primary key, followed by modifiers in original order.
|
|
@@ -36,6 +36,75 @@ export function flushLogs(logFile, timeoutMs = 2000) {
|
|
|
36
36
|
export function escapeForLog(value) {
|
|
37
37
|
return JSON.stringify(value).replace(/[\u007f-\u009f\u2028\u2029]/g, char => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`);
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Redact credentials from URLs used in connection and diagnostic logs.
|
|
41
|
+
* The URL passed to Puppeteer is never modified.
|
|
42
|
+
*/
|
|
43
|
+
export function redactUrlForLogging(value) {
|
|
44
|
+
try {
|
|
45
|
+
const url = new URL(value);
|
|
46
|
+
url.username = '';
|
|
47
|
+
url.password = '';
|
|
48
|
+
if (url.search) {
|
|
49
|
+
url.search = '?REDACTED';
|
|
50
|
+
}
|
|
51
|
+
return url.toString();
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// Unparseable URLs might still contain credentials. Fail closed.
|
|
55
|
+
return '[REDACTED]';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Return a redacted copy of the Puppeteer connection options for logging.
|
|
60
|
+
* Keep the actual headers and connection URLs intact for Puppeteer.
|
|
61
|
+
*/
|
|
62
|
+
export function redactConnectOptionsForLogging(options) {
|
|
63
|
+
return {
|
|
64
|
+
...options,
|
|
65
|
+
...(options.headers
|
|
66
|
+
? {
|
|
67
|
+
headers: Object.fromEntries(Object.keys(options.headers).map(name => [name, '[REDACTED]'])),
|
|
68
|
+
}
|
|
69
|
+
: {}),
|
|
70
|
+
...(options.browserWSEndpoint
|
|
71
|
+
? { browserWSEndpoint: redactUrlForLogging(options.browserWSEndpoint) }
|
|
72
|
+
: {}),
|
|
73
|
+
...(options.browserURL
|
|
74
|
+
? { browserURL: redactUrlForLogging(options.browserURL) }
|
|
75
|
+
: {}),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Filter sensitive CLI arguments in the daemon startup log only.
|
|
80
|
+
* Spawn still receives the original arguments unchanged.
|
|
81
|
+
*/
|
|
82
|
+
export function redactDaemonArgsForLogging(args) {
|
|
83
|
+
const headersFlag = /^--ws-?headers$/i;
|
|
84
|
+
const endpointFlag = /^--(?:ws-?endpoint|browser-?url)$/i;
|
|
85
|
+
return args.map((arg, index) => {
|
|
86
|
+
const previous = args[index - 1] ?? '';
|
|
87
|
+
if (headersFlag.test(previous)) {
|
|
88
|
+
return '[REDACTED]';
|
|
89
|
+
}
|
|
90
|
+
if (endpointFlag.test(previous)) {
|
|
91
|
+
return redactUrlForLogging(arg);
|
|
92
|
+
}
|
|
93
|
+
const equalsAt = arg.indexOf('=');
|
|
94
|
+
if (equalsAt === -1) {
|
|
95
|
+
return arg;
|
|
96
|
+
}
|
|
97
|
+
const flag = arg.slice(0, equalsAt);
|
|
98
|
+
const value = arg.slice(equalsAt + 1);
|
|
99
|
+
if (headersFlag.test(flag)) {
|
|
100
|
+
return `${flag}=[REDACTED]`;
|
|
101
|
+
}
|
|
102
|
+
if (endpointFlag.test(flag)) {
|
|
103
|
+
return `${flag}=${redactUrlForLogging(value)}`;
|
|
104
|
+
}
|
|
105
|
+
return arg;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
39
108
|
export const logger = (...args) => {
|
|
40
109
|
if (logFileStream) {
|
|
41
110
|
logFileStream.write(`${new Date().toISOString()} ${mcpDebugNamespace} ${util.format(...args)}\n`);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The resource type a request is filtered by. Chrome reports CORS preflights
|
|
8
|
+
* and `<link rel=prefetch>` requests as `Other`, so `resourceTypes: ['preflight']`
|
|
9
|
+
* and `['prefetch']` could never match. Those two are recognised from the
|
|
10
|
+
* headers Chrome sends with them; every other type is Chrome's own.
|
|
11
|
+
*/
|
|
12
|
+
export function getFilterableResourceType(request) {
|
|
13
|
+
const type = request.resourceType();
|
|
14
|
+
if (type !== 'other') {
|
|
15
|
+
return type;
|
|
16
|
+
}
|
|
17
|
+
const headers = request.headers();
|
|
18
|
+
if (request.method() === 'OPTIONS' &&
|
|
19
|
+
headers['access-control-request-method'] !== undefined) {
|
|
20
|
+
return 'preflight';
|
|
21
|
+
}
|
|
22
|
+
if (/^prefetch\b/i.test(headers['sec-purpose'] ?? '')) {
|
|
23
|
+
return 'prefetch';
|
|
24
|
+
}
|
|
25
|
+
return type;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=resourceType.js.map
|
package/build/src/utils/text.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { DevTools } from '../third_party/index.js';
|
|
7
|
+
const { StringUtilities } = DevTools.Platform;
|
|
6
8
|
const VALID_PLACEHOLDER_MATCH_PATTERN = /\{(PLACEHOLDER_[a-zA-Z][a-zA-Z0-9_]*)\}/g;
|
|
7
9
|
export function substitutePlaceholders(rawMarkdown, substitutions) {
|
|
8
10
|
if (!substitutions) {
|
|
@@ -12,4 +14,31 @@ export function substitutePlaceholders(rawMarkdown, substitutions) {
|
|
|
12
14
|
return substitutions.get(placeholder) ?? '';
|
|
13
15
|
});
|
|
14
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Truncates `text` to at most `maxLength` UTF-16 code units and appends
|
|
19
|
+
* `ellipsis` when anything was cut off. The cut uses devtools-frontend's
|
|
20
|
+
* `StringUtilities.truncateToCodeUnitLength`, which moves back to the last
|
|
21
|
+
* grapheme boundary at or before the limit, so surrogate pairs and emoji
|
|
22
|
+
* sequences stay whole and the result never contains a lone surrogate, which
|
|
23
|
+
* `JSON.stringify` serializes as an escape like `\ud83d` that strict JSON
|
|
24
|
+
* parsers (such as the one the Python MCP SDK uses) reject.
|
|
25
|
+
*
|
|
26
|
+
* With `includeEllipsisInLength`, the ellipsis counts toward `maxLength`.
|
|
27
|
+
*/
|
|
28
|
+
export function truncateText(text, maxLength, { ellipsis = '...', includeEllipsisInLength = false, } = {}) {
|
|
29
|
+
if (text.length <= maxLength) {
|
|
30
|
+
return text;
|
|
31
|
+
}
|
|
32
|
+
const keep = includeEllipsisInLength
|
|
33
|
+
? Math.max(0, maxLength - ellipsis.length)
|
|
34
|
+
: maxLength;
|
|
35
|
+
return StringUtilities.truncateToCodeUnitLength(text, keep) + ellipsis;
|
|
36
|
+
}
|
|
37
|
+
const URL_SIZE_LIMIT = 255;
|
|
38
|
+
/**
|
|
39
|
+
* Truncates a URL for tool output, such as a `data:` URL with a base64 payload.
|
|
40
|
+
*/
|
|
41
|
+
export function truncateUrl(url) {
|
|
42
|
+
return truncateText(url, URL_SIZE_LIMIT, { ellipsis: '... <truncated>' });
|
|
43
|
+
}
|
|
15
44
|
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Deferred } from '../third_party/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Rejects with a Puppeteer `TimeoutError` with `message` if `promise` does not
|
|
9
|
+
* settle within `timeout` ms. The timer is cleared when the race settles.
|
|
10
|
+
*/
|
|
11
|
+
export async function withTimeout(promise, options) {
|
|
12
|
+
return await Deferred.race([promise, Deferred.create(options)]);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=timeout.js.map
|