chrome-devtools-mcp 1.10.1 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -20
- package/build/src/BrowserManager.js +155 -27
- package/build/src/McpContext.js +598 -200
- package/build/src/McpPage.js +513 -131
- package/build/src/McpResponse.js +291 -116
- package/build/src/McpWorker.js +66 -0
- package/build/src/SlimMcpResponse.js +5 -1
- package/build/src/TextSnapshot.js +40 -20
- package/build/src/ToolHandler.js +306 -147
- package/build/src/bin/chrome-devtools-mcp-main.js +13 -10
- package/build/src/bin/chrome-devtools-mcp.js +1 -1
- package/build/src/bin/chrome-devtools.js +34 -44
- package/build/src/collectors/PageCollector.js +13 -9
- package/build/src/collectors/ServiceWorkerCollector.js +20 -13
- package/build/src/collectors/constants.js +7 -0
- package/build/src/config/ConfigLocator.js +70 -0
- package/build/src/config/ConfigParser.js +159 -0
- package/build/src/config/ConfigWatcher.js +94 -0
- package/build/src/config/ServerConfig.js +251 -0
- package/build/src/config/browser-options.js +15 -17
- package/build/src/config/category-options.js +15 -30
- package/build/src/config/cli-commands.js +165 -5
- package/build/src/config/cli-options.js +441 -58
- package/build/src/config/mcp-options.js +212 -264
- package/build/src/config/puppeteer-options.js +67 -0
- package/build/src/config/tool-options.js +60 -0
- package/build/src/daemon/client.js +84 -44
- package/build/src/daemon/daemon.js +59 -45
- package/build/src/daemon/utils.js +46 -12
- package/build/src/devtools/DevToolsCommentBridge.js +71 -11
- package/build/src/devtools/DevtoolsUtils.js +52 -15
- package/build/src/devtools/McpHostBindingAdapter.js +0 -1
- package/build/src/formatters/CommentFormatter.js +4 -13
- package/build/src/formatters/ConsoleFormatter.js +29 -2
- package/build/src/formatters/CssFormatter.js +3 -2
- package/build/src/formatters/HeapSnapshotFormatter.js +111 -57
- package/build/src/formatters/IssueFormatter.js +33 -32
- package/build/src/formatters/NetworkFormatter.js +62 -22
- package/build/src/formatters/RemoteObjectFormatter.js +231 -0
- package/build/src/formatters/SnapshotFormatter.js +44 -7
- package/build/src/index.js +285 -88
- package/build/src/processors/ChunkedTraceParser.js +11 -11
- package/build/src/processors/HeapSnapshotManager.js +455 -156
- package/build/src/processors/PerformanceTrace.js +9 -9
- package/build/src/telemetry/ClearcutLogger.js +1 -1
- package/build/src/telemetry/transformation.js +7 -11
- package/build/src/telemetry/watchdog/main.js +1 -1
- package/build/src/third_party/THIRD_PARTY_NOTICES +399 -689
- package/build/src/third_party/bundled-packages.json +7 -8
- package/build/src/third_party/cli.js +9239 -0
- package/build/src/third_party/devtools-formatter-worker.js +4299 -2517
- package/build/src/third_party/devtools-heap-snapshot-worker.js +1298 -22
- package/build/src/third_party/index.js +132003 -146852
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantRead.md +0 -1
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantReadOptOut.md +5 -0
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSet.md +0 -1
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSetOptOut.md +5 -0
- package/build/src/third_party/issue-descriptions/deprecation.md +1 -1
- package/build/src/third_party/issue-descriptions/genericGeolocationPromptWithoutUserGesture.md +5 -0
- package/build/src/third_party/issue-descriptions/sriValidationFailedIntegrityMismatch.md +2 -0
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +54576 -52174
- package/build/src/tools/ToolDefinition.js +102 -12
- package/build/src/tools/comments.js +62 -4
- package/build/src/tools/console.js +6 -4
- package/build/src/tools/css.js +5 -2
- package/build/src/tools/emulation.js +22 -8
- package/build/src/tools/extensions.js +5 -0
- package/build/src/tools/input.js +29 -9
- package/build/src/tools/lighthouse.js +136 -12
- package/build/src/tools/memory.js +166 -59
- package/build/src/tools/network.js +5 -4
- package/build/src/tools/pages.js +52 -7
- package/build/src/tools/performance.js +28 -7
- package/build/src/tools/pwa.js +7 -0
- package/build/src/tools/screencast.js +74 -33
- package/build/src/tools/screenshot.js +52 -21
- package/build/src/tools/script.js +125 -40
- package/build/src/tools/slim/tools.js +27 -13
- package/build/src/tools/snapshot.js +13 -3
- package/build/src/tools/thirdPartyDeveloper.js +9 -5
- package/build/src/tools/tools.js +35 -22
- package/build/src/tools/webmcp.js +11 -6
- package/build/src/types.js +11 -0
- package/build/src/utils/TaskRunner.js +136 -0
- package/build/src/utils/WaitForHelper.js +15 -2
- package/build/src/utils/bytes.js +2 -12
- package/build/src/utils/check-for-updates.js +2 -2
- package/build/src/utils/disclaimers.js +27 -0
- package/build/src/utils/errorHandling.js +20 -0
- package/build/src/utils/keyboard.js +14 -2
- package/build/src/utils/logger.js +84 -5
- package/build/src/utils/resourceType.js +27 -0
- package/build/src/utils/text.js +44 -0
- package/build/src/utils/timeout.js +14 -0
- package/build/src/utils/url.js +140 -3
- package/build/src/version.js +1 -1
- package/package.json +16 -11
- package/skills/a11y-debugging/SKILL.md +7 -12
- package/skills/chrome-devtools/SKILL.md +2 -2
- package/skills/chrome-devtools-cli/SKILL.md +18 -15
- package/skills/cookie-debugging/SKILL.md +8 -5
- package/skills/debug-optimize-lcp/SKILL.md +1 -1
- package/skills/troubleshooting/SKILL.md +5 -6
|
@@ -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
|
|
@@ -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
|
/**
|
|
@@ -85,7 +88,7 @@ export class WaitForHelper {
|
|
|
85
88
|
try {
|
|
86
89
|
// Bound the setup evaluation against the stable-DOM timeout. Without this
|
|
87
90
|
// cap a paused renderer (e.g. an open dialog) would make evaluateHandle
|
|
88
|
-
// hang until protocolTimeout (default 180s)
|
|
91
|
+
// hang until protocolTimeout (default 180s) inside the context queue.
|
|
89
92
|
const stableDomObserver = __addDisposableResource(env_1, await Promise.race([
|
|
90
93
|
this.#page.evaluateHandle(timeout => {
|
|
91
94
|
let timeoutId;
|
|
@@ -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
|
}
|
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,14 +8,14 @@ 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.
|
|
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,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
|
|
@@ -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
|
|
@@ -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.
|
|
@@ -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,90 @@ 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
|
+
}
|
|
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
|
+
}
|
|
30
108
|
export const logger = (...args) => {
|
|
31
109
|
if (logFileStream) {
|
|
32
110
|
logFileStream.write(`${new Date().toISOString()} ${mcpDebugNamespace} ${util.format(...args)}\n`);
|
|
33
111
|
}
|
|
34
|
-
else if (
|
|
35
|
-
|
|
112
|
+
else if (debugLog.enabled) {
|
|
113
|
+
debugLog('%s %s', new Date().toISOString(), util.format(...args));
|
|
36
114
|
}
|
|
37
115
|
};
|
|
38
116
|
export const puppeteerLogger = (prefix) => {
|
|
@@ -40,9 +118,10 @@ export const puppeteerLogger = (prefix) => {
|
|
|
40
118
|
if (!dbg.enabled) {
|
|
41
119
|
return;
|
|
42
120
|
}
|
|
43
|
-
|
|
121
|
+
const stream = logFileStream;
|
|
122
|
+
if (stream) {
|
|
44
123
|
return (...args) => {
|
|
45
|
-
|
|
124
|
+
stream.write(`${new Date().toISOString()} ${prefix} ${util.format(...args)}\n`);
|
|
46
125
|
};
|
|
47
126
|
}
|
|
48
127
|
return (...args) => {
|
|
@@ -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
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { DevTools } from '../third_party/index.js';
|
|
7
|
+
const { StringUtilities } = DevTools.Platform;
|
|
8
|
+
const VALID_PLACEHOLDER_MATCH_PATTERN = /\{(PLACEHOLDER_[a-zA-Z][a-zA-Z0-9_]*)\}/g;
|
|
9
|
+
export function substitutePlaceholders(rawMarkdown, substitutions) {
|
|
10
|
+
if (!substitutions) {
|
|
11
|
+
return rawMarkdown;
|
|
12
|
+
}
|
|
13
|
+
return rawMarkdown.replace(VALID_PLACEHOLDER_MATCH_PATTERN, (_, placeholder) => {
|
|
14
|
+
return substitutions.get(placeholder) ?? '';
|
|
15
|
+
});
|
|
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
|
+
}
|
|
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
|