chrome-devtools-mcp 1.7.0 → 1.9.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 +20 -874
- package/build/src/McpContext.js +98 -45
- package/build/src/McpPage.js +10 -4
- package/build/src/McpResponse.js +22 -4
- package/build/src/ToolHandler.js +81 -57
- package/build/src/bin/chrome-devtools-mcp-main.js +4 -4
- package/build/src/bin/chrome-devtools.js +29 -30
- package/build/src/browser.js +8 -17
- package/build/src/{PageCollector.js → collectors/PageCollector.js} +7 -7
- package/build/src/{ServiceWorkerCollector.js → collectors/ServiceWorkerCollector.js} +1 -1
- package/build/src/config/browser-options.js +123 -0
- package/build/src/config/category-options.js +80 -0
- package/build/src/{bin/chrome-devtools-cli-options.js → config/cli-options.js} +380 -25
- package/build/src/{bin/chrome-devtools-mcp-cli-options.js → config/mcp-options.js} +113 -148
- package/build/src/daemon/client.js +11 -2
- package/build/src/daemon/daemon.js +2 -2
- package/build/src/daemon/utils.js +6 -0
- package/build/src/devtools/DevtoolsUtils.js +29 -35
- package/build/src/formatters/ConsoleFormatter.js +43 -10
- package/build/src/formatters/HeapSnapshotFormatter.js +10 -2
- package/build/src/formatters/IssueFormatter.js +1 -1
- package/build/src/formatters/NetworkFormatter.js +12 -9
- package/build/src/index.js +185 -91
- package/build/src/{HeapSnapshotManager.js → processors/HeapSnapshotManager.js} +21 -5
- package/build/src/{trace-processing/parse.js → processors/PerformanceTrace.js} +1 -1
- package/build/src/telemetry/ClearcutLogger.js +18 -5
- package/build/src/telemetry/flagUtils.js +4 -3
- package/build/src/telemetry/types.js +4 -0
- package/build/src/third_party/THIRD_PARTY_NOTICES +8 -65
- package/build/src/third_party/bundled-packages.json +4 -4
- package/build/src/third_party/devtools-formatter-worker.js +22 -0
- package/build/src/third_party/devtools-heap-snapshot-worker.js +296 -42
- package/build/src/third_party/index.js +38728 -37176
- package/build/src/third_party/issue-descriptions/connectionAllowlistEmbeddingRequirementNotSatisfied.md +26 -0
- package/build/src/third_party/issue-descriptions/connectionAllowlistIFrameAttributeLoosensEmbeddingRequirement.md +19 -0
- package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidAllowConnectionAllowlistFrom.md +21 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsBlockedByConnectionAllowlist.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestConfigBlockedByConnectionAllowlist.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenBlockedByConnectionAllowlist.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestWellKnownBlockedByConnectionAllowlist.md +1 -0
- package/build/src/tools/ToolDefinition.js +15 -0
- package/build/src/tools/categories.js +2 -5
- package/build/src/tools/console.js +9 -3
- package/build/src/tools/emulation.js +2 -2
- package/build/src/tools/extensions.js +7 -5
- package/build/src/tools/input.js +26 -16
- package/build/src/tools/lighthouse.js +3 -1
- package/build/src/tools/memory.js +112 -16
- package/build/src/tools/network.js +7 -4
- package/build/src/tools/pages.js +34 -23
- package/build/src/tools/performance.js +16 -25
- package/build/src/tools/pwa.js +128 -0
- package/build/src/tools/screencast.js +7 -4
- package/build/src/tools/screenshot.js +42 -9
- package/build/src/tools/script.js +29 -8
- package/build/src/tools/slim/tools.js +43 -35
- package/build/src/tools/snapshot.js +5 -3
- package/build/src/tools/thirdPartyDeveloper.js +2 -2
- package/build/src/tools/tools.js +2 -0
- package/build/src/tools/webmcp.js +2 -2
- package/build/src/{WaitForHelper.js → utils/WaitForHelper.js} +74 -38
- package/build/src/utils/bytes.js +105 -0
- package/build/src/utils/logger.js +25 -11
- package/build/src/utils/url.js +73 -0
- package/build/src/version.js +1 -1
- package/package.json +21 -13
- package/skills/a11y-debugging/SKILL.md +2 -0
- package/skills/chrome-devtools/SKILL.md +5 -4
- package/skills/chrome-devtools-cli/SKILL.md +103 -64
- package/skills/cookie-debugging/SKILL.md +149 -0
- package/skills/debug-optimize-lcp/SKILL.md +9 -9
- package/skills/memory-leak-debugging/SKILL.md +6 -2
- package/skills/troubleshooting/SKILL.md +1 -0
- package/build/src/utils/string.js +0 -37
|
@@ -4,107 +4,13 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { yargs, hideBin } from '../third_party/index.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (!value) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
return value;
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
browserUrl: {
|
|
21
|
-
type: 'string',
|
|
22
|
-
description: 'Connect to a running, debuggable Chrome instance (e.g. `http://127.0.0.1:9222`). For more details see: https://github.com/ChromeDevTools/chrome-devtools-mcp#connecting-to-a-running-chrome-instance.',
|
|
23
|
-
alias: 'u',
|
|
24
|
-
conflicts: ['wsEndpoint'],
|
|
25
|
-
coerce: (url) => {
|
|
26
|
-
if (!url) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
try {
|
|
30
|
-
new URL(url);
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
throw new Error(`Provided browserUrl ${url} is not valid URL.`);
|
|
34
|
-
}
|
|
35
|
-
return url;
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
wsEndpoint: {
|
|
39
|
-
type: 'string',
|
|
40
|
-
description: 'WebSocket endpoint to connect to a running Chrome instance (e.g., ws://127.0.0.1:9222/devtools/browser/<id>). Alternative to --browserUrl.',
|
|
41
|
-
alias: 'w',
|
|
42
|
-
conflicts: ['browserUrl'],
|
|
43
|
-
coerce: (url) => {
|
|
44
|
-
if (!url) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
try {
|
|
48
|
-
const parsed = new URL(url);
|
|
49
|
-
if (parsed.protocol !== 'ws:' && parsed.protocol !== 'wss:') {
|
|
50
|
-
throw new Error(`Provided wsEndpoint ${url} must use ws:// or wss:// protocol.`);
|
|
51
|
-
}
|
|
52
|
-
return url;
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
if (error.message.includes('ws://')) {
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
58
|
-
throw new Error(`Provided wsEndpoint ${url} is not valid URL.`);
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
wsHeaders: {
|
|
63
|
-
type: 'string',
|
|
64
|
-
description: 'Custom headers for WebSocket connection in JSON format (e.g., \'{"Authorization":"Bearer token"}\'). Only works with --wsEndpoint.',
|
|
65
|
-
implies: 'wsEndpoint',
|
|
66
|
-
coerce: (val) => {
|
|
67
|
-
if (!val) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
try {
|
|
71
|
-
const parsed = JSON.parse(val);
|
|
72
|
-
if (typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
73
|
-
throw new Error('Headers must be a JSON object');
|
|
74
|
-
}
|
|
75
|
-
return parsed;
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
throw new Error(`Invalid JSON for wsHeaders: ${error.message}`);
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
headless: {
|
|
83
|
-
type: 'boolean',
|
|
84
|
-
description: 'Whether to run in headless (no UI) mode.',
|
|
85
|
-
default: false,
|
|
86
|
-
},
|
|
87
|
-
executablePath: {
|
|
88
|
-
type: 'string',
|
|
89
|
-
description: 'Path to custom Chrome executable.',
|
|
90
|
-
conflicts: ['browserUrl', 'wsEndpoint'],
|
|
91
|
-
alias: 'e',
|
|
92
|
-
},
|
|
93
|
-
isolated: {
|
|
94
|
-
type: 'boolean',
|
|
95
|
-
description: 'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed. Defaults to false.',
|
|
96
|
-
},
|
|
97
|
-
userDataDir: {
|
|
98
|
-
type: 'string',
|
|
99
|
-
description: 'Path to the user data directory for Chrome. Default is $HOME/.cache/chrome-devtools-mcp/chrome-profile$CHANNEL_SUFFIX_IF_NON_STABLE',
|
|
100
|
-
conflicts: ['browserUrl', 'wsEndpoint', 'isolated'],
|
|
101
|
-
},
|
|
102
|
-
channel: {
|
|
103
|
-
type: 'string',
|
|
104
|
-
description: 'Specify a different Chrome channel that should be used. The default is the stable channel version.',
|
|
105
|
-
choices: ['canary', 'dev', 'beta', 'stable'],
|
|
106
|
-
conflicts: ['browserUrl', 'wsEndpoint', 'executablePath'],
|
|
107
|
-
},
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
export const DEFAULT_FILESYSTEM_ROOT = [os.tmpdir()];
|
|
9
|
+
import { getCategoryOptions } from './category-options.js';
|
|
10
|
+
import { getBrowserOptions } from './browser-options.js';
|
|
11
|
+
export const mcpOptions = {
|
|
12
|
+
...getCategoryOptions(),
|
|
13
|
+
...getBrowserOptions(),
|
|
108
14
|
logFile: {
|
|
109
15
|
type: 'string',
|
|
110
16
|
describe: 'Path to a file to write debug logs to. Set the env variable `DEBUG` to `*` to enable verbose logs. Useful for submitting bug reports.',
|
|
@@ -126,17 +32,14 @@ export const cliOptions = {
|
|
|
126
32
|
};
|
|
127
33
|
},
|
|
128
34
|
},
|
|
129
|
-
proxyServer: {
|
|
130
|
-
type: 'string',
|
|
131
|
-
description: `Proxy server configuration for Chrome passed as --proxy-server when launching the browser. See https://www.chromium.org/developers/design-documents/network-settings/ for details.`,
|
|
132
|
-
},
|
|
133
35
|
acceptInsecureCerts: {
|
|
134
36
|
type: 'boolean',
|
|
135
37
|
description: `If enabled, ignores errors relative to self-signed and expired certificates. Use with caution.`,
|
|
136
38
|
},
|
|
137
|
-
|
|
39
|
+
pageIdRouting: {
|
|
138
40
|
type: 'boolean',
|
|
139
|
-
describe: '
|
|
41
|
+
describe: 'Require pageId on page-scoped tools and route requests by page ID (useful for concurrent agent sessions). Use --no-page-id-routing to disable.',
|
|
42
|
+
default: true,
|
|
140
43
|
},
|
|
141
44
|
experimentalDevtools: {
|
|
142
45
|
type: 'boolean',
|
|
@@ -148,11 +51,13 @@ export const cliOptions = {
|
|
|
148
51
|
},
|
|
149
52
|
memoryDebugging: {
|
|
150
53
|
type: 'boolean',
|
|
54
|
+
default: false,
|
|
151
55
|
describe: 'Whether to enable memory debugging tools.',
|
|
152
56
|
alias: 'experimentalMemory',
|
|
153
57
|
},
|
|
154
58
|
experimentalStructuredContent: {
|
|
155
59
|
type: 'boolean',
|
|
60
|
+
default: false,
|
|
156
61
|
describe: 'Whether to output structured formatted content.',
|
|
157
62
|
},
|
|
158
63
|
experimentalToonFormat: {
|
|
@@ -184,13 +89,19 @@ export const cliOptions = {
|
|
|
184
89
|
describe: 'Path to ffmpeg executable for screencast recording.',
|
|
185
90
|
implies: 'experimentalScreencast',
|
|
186
91
|
},
|
|
187
|
-
|
|
188
|
-
type: '
|
|
189
|
-
describe: '
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
92
|
+
experimentalScreencastFps: {
|
|
93
|
+
type: 'number',
|
|
94
|
+
describe: 'Frames per second to use for screencast recording. Lower values can reduce memory pressure on pages that produce frames faster than ffmpeg can encode them.',
|
|
95
|
+
implies: 'experimentalScreencast',
|
|
96
|
+
coerce: (value) => {
|
|
97
|
+
if (value === undefined) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
101
|
+
throw new Error(`Invalid experimentalScreencastFps ${value}. Expected a positive integer.`);
|
|
102
|
+
}
|
|
103
|
+
return value;
|
|
104
|
+
},
|
|
194
105
|
},
|
|
195
106
|
blockedUrlPattern: {
|
|
196
107
|
type: 'array',
|
|
@@ -202,45 +113,25 @@ export const cliOptions = {
|
|
|
202
113
|
describe: "Restricts browser's network access by allowing only specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Requires Chrome 149+. Silently detaches from targets with unallowed URLs upon connection, and blocks runtime requests (including navigations and subresources). Accepts an array of patterns.",
|
|
203
114
|
conflicts: ['blockedUrlPattern'],
|
|
204
115
|
},
|
|
205
|
-
|
|
206
|
-
type: 'array',
|
|
207
|
-
describe: 'Explicitly disable default arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
|
|
208
|
-
},
|
|
209
|
-
categoryEmulation: {
|
|
210
|
-
type: 'boolean',
|
|
211
|
-
default: true,
|
|
212
|
-
describe: 'Set to false to exclude tools related to emulation.',
|
|
213
|
-
},
|
|
214
|
-
categoryPerformance: {
|
|
116
|
+
performanceCrux: {
|
|
215
117
|
type: 'boolean',
|
|
216
118
|
default: true,
|
|
217
|
-
describe: 'Set to false to
|
|
119
|
+
describe: 'Set to false to disable sending URLs from performance traces to CrUX API to get field performance data.',
|
|
218
120
|
},
|
|
219
|
-
|
|
121
|
+
usageStatistics: {
|
|
220
122
|
type: 'boolean',
|
|
221
123
|
default: true,
|
|
222
|
-
describe: 'Set to false to
|
|
223
|
-
},
|
|
224
|
-
categoryExtensions: {
|
|
225
|
-
type: 'boolean',
|
|
226
|
-
hidden: false,
|
|
227
|
-
default: false,
|
|
228
|
-
describe: 'Set to true to include tools related to extensions. Note: This feature is currently only supported with a pipe connection. autoConnect, browserUrl, and wsEndpoint are not supported with this feature until 149 will be released.',
|
|
229
|
-
},
|
|
230
|
-
categoryExperimentalThirdParty: {
|
|
231
|
-
type: 'boolean',
|
|
232
|
-
default: false,
|
|
233
|
-
describe: 'Set to true to enable third-party developer tools exposed by the inspected page itself',
|
|
124
|
+
describe: 'Set to false to opt-out of usage statistics collection. Google collects usage data to improve the tool, handled under the Google Privacy Policy (https://policies.google.com/privacy). This is independent from Chrome browser metrics. Disabled if `CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS` or `CI` env variables are set.',
|
|
234
125
|
},
|
|
235
|
-
|
|
126
|
+
javascriptEvaluation: {
|
|
236
127
|
type: 'boolean',
|
|
237
128
|
default: true,
|
|
238
|
-
describe: 'Set to false to disable
|
|
129
|
+
describe: 'Set to false to disable JavaScript execution. When disabled, evaluation tools (evaluate_script and slim evaluate) are disabled, the initScript parameter in navigate_page is turned off, and navigating to javascript:, data:, or vbscript: URLs is disallowed.',
|
|
239
130
|
},
|
|
240
|
-
|
|
131
|
+
sourceMaps: {
|
|
241
132
|
type: 'boolean',
|
|
242
133
|
default: true,
|
|
243
|
-
describe: '
|
|
134
|
+
describe: 'Whether to enable source maps in DevTools. Use --no-source-maps to disable.',
|
|
244
135
|
},
|
|
245
136
|
clearcutEndpoint: {
|
|
246
137
|
type: 'string',
|
|
@@ -259,7 +150,7 @@ export const cliOptions = {
|
|
|
259
150
|
},
|
|
260
151
|
screenshotFormat: {
|
|
261
152
|
type: 'string',
|
|
262
|
-
description: 'Override the default output format used by take_screenshot when the caller does not specify one. JPEG and WebP are ~3-5x smaller than PNG, which
|
|
153
|
+
description: 'Override the default output format used by take_screenshot when the caller does not specify one. JPEG and WebP are ~3-5x smaller than PNG, which reduces transfer and storage size. To reduce context size use --screenshotMaxWidth / --screenshotMaxHeight, since image tokens scale with dimensions rather than encoded bytes. Unset preserves the existing default ("png").',
|
|
263
154
|
choices: ['jpeg', 'png', 'webp'],
|
|
264
155
|
},
|
|
265
156
|
screenshotQuality: {
|
|
@@ -318,17 +209,74 @@ export const cliOptions = {
|
|
|
318
209
|
allowUnrestrictedPaths: {
|
|
319
210
|
type: 'boolean',
|
|
320
211
|
default: false,
|
|
212
|
+
deprecated: 'Use --workspace=/ instead.',
|
|
321
213
|
describe: 'If set, disables the default path restriction that applies when the MCP client does not negotiate ' +
|
|
322
214
|
'the roots capability. By default, file-writing tools are restricted to the OS temp directory when ' +
|
|
323
215
|
'no roots are configured. Use this only when connecting a trusted local client that does not implement ' +
|
|
324
216
|
'MCP roots and requires access to paths outside the temp directory.',
|
|
325
217
|
},
|
|
218
|
+
filesystemRoot: {
|
|
219
|
+
type: 'array',
|
|
220
|
+
alias: 'workspace',
|
|
221
|
+
default: DEFAULT_FILESYSTEM_ROOT,
|
|
222
|
+
defaultDescription: 'OS temp directory',
|
|
223
|
+
describe: 'A directory that filesystem tools are allowed to access. May be specified more than once.',
|
|
224
|
+
},
|
|
326
225
|
};
|
|
327
|
-
export function
|
|
226
|
+
export function getMcpOptionsForViaCli() {
|
|
227
|
+
if (!('default' in mcpOptions.headless)) {
|
|
228
|
+
throw new Error('headless cli option unexpectedly does not have a default');
|
|
229
|
+
}
|
|
230
|
+
if (!('default' in mcpOptions.experimentalStructuredContent)) {
|
|
231
|
+
throw new Error('experimentalStructuredContent cli option unexpectedly does not have a default');
|
|
232
|
+
}
|
|
233
|
+
if ('default' in mcpOptions.isolated) {
|
|
234
|
+
throw new Error('isolated cli option unexpectedly has a default');
|
|
235
|
+
}
|
|
236
|
+
return {
|
|
237
|
+
...mcpOptions,
|
|
238
|
+
headless: {
|
|
239
|
+
...mcpOptions.headless,
|
|
240
|
+
default: true,
|
|
241
|
+
},
|
|
242
|
+
memoryDebugging: {
|
|
243
|
+
...mcpOptions.memoryDebugging,
|
|
244
|
+
default: true,
|
|
245
|
+
},
|
|
246
|
+
categoryExtensions: {
|
|
247
|
+
...mcpOptions.categoryExtensions,
|
|
248
|
+
default: true,
|
|
249
|
+
},
|
|
250
|
+
experimentalStructuredContent: {
|
|
251
|
+
...mcpOptions.experimentalStructuredContent,
|
|
252
|
+
default: true,
|
|
253
|
+
},
|
|
254
|
+
isolated: {
|
|
255
|
+
...mcpOptions.isolated,
|
|
256
|
+
description: 'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed. Defaults to true unless userDataDir is provided.',
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Exported only for testing to not trigger process exit.
|
|
262
|
+
*/
|
|
263
|
+
export function parser(version, argv = process.argv, env = process.env) {
|
|
264
|
+
const isViaCli = argv.includes('--viaCli') || argv.includes('--via-cli');
|
|
265
|
+
const options = isViaCli ? getMcpOptionsForViaCli() : mcpOptions;
|
|
328
266
|
const yargsInstance = yargs(hideBin(argv))
|
|
329
267
|
.scriptName('npx chrome-devtools-mcp@latest')
|
|
330
|
-
.
|
|
268
|
+
.parserConfiguration({
|
|
269
|
+
'strip-aliased': true,
|
|
270
|
+
'strip-dashed': true,
|
|
271
|
+
})
|
|
272
|
+
.options(options)
|
|
273
|
+
.showHelpOnFail(false, 'Specify --help for available options')
|
|
331
274
|
.middleware(args => {
|
|
275
|
+
if (isViaCli && args.filesystemRoot === DEFAULT_FILESYSTEM_ROOT) {
|
|
276
|
+
const cliFilesystemArgs = args;
|
|
277
|
+
cliFilesystemArgs.allowUnrestrictedPaths = true;
|
|
278
|
+
cliFilesystemArgs.filesystemRoot = undefined;
|
|
279
|
+
}
|
|
332
280
|
// We can't set default in the options else
|
|
333
281
|
// Yargs will complain
|
|
334
282
|
if (!args.channel &&
|
|
@@ -341,6 +289,16 @@ export function parseArguments(version, argv = process.argv, env = process.env)
|
|
|
341
289
|
console.error("turning off usage statistics. process.env['CI'] || process.env['CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS'] is set.");
|
|
342
290
|
args.usageStatistics = false;
|
|
343
291
|
}
|
|
292
|
+
const cliOptionsAllowedArgs = [
|
|
293
|
+
...Object.keys(options),
|
|
294
|
+
// Yargs populated with positional args
|
|
295
|
+
'_',
|
|
296
|
+
'$0',
|
|
297
|
+
];
|
|
298
|
+
const unknownArgs = Object.keys(args).filter(arg => !cliOptionsAllowedArgs.includes(arg));
|
|
299
|
+
if (unknownArgs.length > 0) {
|
|
300
|
+
console.error(`Unknown arguments: ${unknownArgs.map(arg => `--${arg}`)}`);
|
|
301
|
+
}
|
|
344
302
|
})
|
|
345
303
|
.example([
|
|
346
304
|
[
|
|
@@ -399,6 +357,11 @@ export function parseArguments(version, argv = process.argv, env = process.env)
|
|
|
399
357
|
'$0 --no-performance-crux',
|
|
400
358
|
'Disable CrUX (field data) integration in performance tools.',
|
|
401
359
|
],
|
|
360
|
+
['$0 --no-source-maps', 'Disable source maps in DevTools.'],
|
|
361
|
+
[
|
|
362
|
+
'$0 --no-javascript-evaluation',
|
|
363
|
+
'Disable JavaScript execution (disables evaluation tools, initScript in navigate_page, and navigating to javascript:, data:, or vbscript: URLs).',
|
|
364
|
+
],
|
|
402
365
|
[
|
|
403
366
|
'$0 --slim',
|
|
404
367
|
'Only 3 tools: navigation, JavaScript execution and screenshot',
|
|
@@ -407,7 +370,9 @@ export function parseArguments(version, argv = process.argv, env = process.env)
|
|
|
407
370
|
return yargsInstance
|
|
408
371
|
.wrap(Math.min(120, yargsInstance.terminalWidth()))
|
|
409
372
|
.help()
|
|
410
|
-
.version(version)
|
|
411
|
-
|
|
373
|
+
.version(version);
|
|
374
|
+
}
|
|
375
|
+
export function parseArguments(version, argv = process.argv, env = process.env) {
|
|
376
|
+
return parser(version, argv, env).parseSync();
|
|
412
377
|
}
|
|
413
|
-
//# sourceMappingURL=
|
|
378
|
+
//# sourceMappingURL=mcp-options.js.map
|
|
@@ -8,7 +8,7 @@ import fs from 'node:fs';
|
|
|
8
8
|
import net from 'node:net';
|
|
9
9
|
import { PipeTransport } from '../third_party/index.js';
|
|
10
10
|
import { getTempFilePath } from '../utils/files.js';
|
|
11
|
-
import { logger } from '../utils/logger.js';
|
|
11
|
+
import { logger, puppeteerLogger } from '../utils/logger.js';
|
|
12
12
|
import { DAEMON_SCRIPT_PATH, getSocketPath, getPidFilePath, isDaemonRunning, } from './utils.js';
|
|
13
13
|
const FILE_TIMEOUT = 10_000;
|
|
14
14
|
const READY_CHECK_INTERVAL = 100;
|
|
@@ -116,7 +116,7 @@ export async function sendCommand(command, sessionId, timeout = SEND_COMMAND_TIM
|
|
|
116
116
|
socket.destroy();
|
|
117
117
|
reject(new Error('Timeout waiting for daemon response'));
|
|
118
118
|
}, timeout);
|
|
119
|
-
const transport = new PipeTransport(socket, socket);
|
|
119
|
+
const transport = new PipeTransport(socket, socket, puppeteerLogger);
|
|
120
120
|
transport.onmessage = async (message) => {
|
|
121
121
|
clearTimeout(timer);
|
|
122
122
|
logger?.('onmessage', message);
|
|
@@ -165,6 +165,15 @@ export async function verifyDaemonVersion(sessionId, cliVersion) {
|
|
|
165
165
|
}
|
|
166
166
|
export async function handleResponse(response, format) {
|
|
167
167
|
if (response.isError) {
|
|
168
|
+
if (format === 'md') {
|
|
169
|
+
const chunks = [];
|
|
170
|
+
for (const content of response.content) {
|
|
171
|
+
if (content.type === 'text') {
|
|
172
|
+
chunks.push(content.text);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return chunks.join(' ');
|
|
176
|
+
}
|
|
168
177
|
return JSON.stringify(response.content);
|
|
169
178
|
}
|
|
170
179
|
const chunks = [];
|
|
@@ -10,7 +10,7 @@ import os from 'node:os';
|
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
import process from 'node:process';
|
|
12
12
|
import { Client, PipeTransport, StdioClientTransport, } from '../third_party/index.js';
|
|
13
|
-
import { logger } from '../utils/logger.js';
|
|
13
|
+
import { logger, puppeteerLogger } from '../utils/logger.js';
|
|
14
14
|
import { VERSION } from '../version.js';
|
|
15
15
|
import { DAEMON_CLIENT_NAME, getPidFilePath, getSocketPath, INDEX_SCRIPT_PATH, IS_WINDOWS, isDaemonRunning, assertValidSessionId, } from './utils.js';
|
|
16
16
|
const sessionId = process.env.CHROME_DEVTOOLS_MCP_SESSION_ID || '';
|
|
@@ -174,7 +174,7 @@ async function startSocketServer() {
|
|
|
174
174
|
}
|
|
175
175
|
return await new Promise((resolve, reject) => {
|
|
176
176
|
server = createServer(socket => {
|
|
177
|
-
const transport = new PipeTransport(socket, socket);
|
|
177
|
+
const transport = new PipeTransport(socket, socket, puppeteerLogger);
|
|
178
178
|
transport.onmessage = async (message) => {
|
|
179
179
|
logger?.('onmessage', message);
|
|
180
180
|
const response = await handleRequest(JSON.parse(message));
|
|
@@ -107,6 +107,12 @@ export function serializeArgs(options, argv) {
|
|
|
107
107
|
continue;
|
|
108
108
|
}
|
|
109
109
|
const value = argv[key];
|
|
110
|
+
const option = options[key];
|
|
111
|
+
// Yargs reuses the option `default` object; skip it so the daemon parser
|
|
112
|
+
// still sees the original default (needed for filesystemRoot identity).
|
|
113
|
+
if (option !== undefined && value === option.default) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
110
116
|
const kebabKey = key.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`);
|
|
111
117
|
if (typeof value === 'boolean') {
|
|
112
118
|
if (value) {
|
|
@@ -19,6 +19,11 @@ export function overrideDevToolsGlobals({ loadResource, }) {
|
|
|
19
19
|
DevTools.Host.InspectorFrontendHost.installInspectorFrontendHost(new McpHostBindingAdapter(loadResource));
|
|
20
20
|
// DevTools CDP errors can get noisy.
|
|
21
21
|
DevTools.ProtocolClient.InspectorBackend.test.suppressRequestErrors = true;
|
|
22
|
+
const noopAgentCommand = () => {
|
|
23
|
+
return Promise.resolve({
|
|
24
|
+
getError: () => undefined,
|
|
25
|
+
});
|
|
26
|
+
};
|
|
22
27
|
// Stub out Network emulation commands on the DevTools Agent prototype globally.
|
|
23
28
|
// This prevents the DevTools Frontend from ever resetting/clearing Puppeteer's
|
|
24
29
|
// active network blocking/throttling rules during target setup or session lifetime.
|
|
@@ -36,41 +41,37 @@ export function overrideDevToolsGlobals({ loadResource, }) {
|
|
|
36
41
|
enumerable: true,
|
|
37
42
|
});
|
|
38
43
|
Object.defineProperty(networkAgentPrototype, 'invoke_overrideNetworkState', {
|
|
39
|
-
value:
|
|
40
|
-
return Promise.resolve({
|
|
41
|
-
getError: () => undefined,
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
+
value: noopAgentCommand,
|
|
44
45
|
writable: true,
|
|
45
46
|
configurable: true,
|
|
46
47
|
enumerable: true,
|
|
47
48
|
});
|
|
48
49
|
Object.defineProperty(networkAgentPrototype, 'invoke_enable', {
|
|
49
|
-
value:
|
|
50
|
-
return Promise.resolve({
|
|
51
|
-
getError: () => undefined,
|
|
52
|
-
});
|
|
53
|
-
},
|
|
50
|
+
value: noopAgentCommand,
|
|
54
51
|
writable: true,
|
|
55
52
|
configurable: true,
|
|
56
53
|
enumerable: true,
|
|
57
54
|
});
|
|
58
55
|
Object.defineProperty(networkAgentPrototype, 'invoke_disable', {
|
|
59
|
-
value:
|
|
60
|
-
return Promise.resolve({
|
|
61
|
-
getError: () => undefined,
|
|
62
|
-
});
|
|
63
|
-
},
|
|
56
|
+
value: noopAgentCommand,
|
|
64
57
|
writable: true,
|
|
65
58
|
configurable: true,
|
|
66
59
|
enumerable: true,
|
|
67
60
|
});
|
|
68
61
|
Object.defineProperty(networkAgentPrototype, 'invoke_setBlockedURLs', {
|
|
69
|
-
value:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
value: noopAgentCommand,
|
|
63
|
+
writable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
enumerable: true,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// Puppeteer already collects issues from its own Audits subscription. Avoid
|
|
69
|
+
// enabling the DevTools Frontend's redundant subscription, which can replay
|
|
70
|
+
// a large retained issue backlog and delay unrelated page work.
|
|
71
|
+
const auditsAgentPrototype = DevTools.ProtocolClient.InspectorBackend.inspectorBackend.agentPrototypes.get('Audits');
|
|
72
|
+
if (auditsAgentPrototype) {
|
|
73
|
+
Object.defineProperty(auditsAgentPrototype, 'invoke_enable', {
|
|
74
|
+
value: noopAgentCommand,
|
|
74
75
|
writable: true,
|
|
75
76
|
configurable: true,
|
|
76
77
|
enumerable: true,
|
|
@@ -91,7 +92,7 @@ export function overrideDevToolsGlobals({ loadResource, }) {
|
|
|
91
92
|
.resolve('../third_party/devtools-formatter-worker.js'),
|
|
92
93
|
});
|
|
93
94
|
}
|
|
94
|
-
export async function createTargetUniverse(session) {
|
|
95
|
+
export async function createTargetUniverse(session, options) {
|
|
95
96
|
const settingStorage = new DevTools.Common.Settings.SettingsStorage({});
|
|
96
97
|
const universe = new DevTools.Foundation.Universe.Universe({
|
|
97
98
|
settingsCreationOptions: {
|
|
@@ -105,30 +106,23 @@ export async function createTargetUniverse(session) {
|
|
|
105
106
|
inspectorFrontendHost: DevTools.Host.InspectorFrontendHost.InspectorFrontendHostInstance,
|
|
106
107
|
supportsEmulation: false,
|
|
107
108
|
});
|
|
109
|
+
const sourceMaps = options?.sourceMaps ?? true;
|
|
110
|
+
const jsSourceMapsSetting = universe.settings.resolve(DevTools.SDKSettings.jsSourceMapsEnabledSettingDescriptor);
|
|
111
|
+
jsSourceMapsSetting.set(sourceMaps);
|
|
112
|
+
const cssSourceMapsSetting = universe.settings.resolve(DevTools.SDKSettings.cssSourceMapsEnabledSettingDescriptor);
|
|
113
|
+
cssSourceMapsSetting.set(sourceMaps);
|
|
108
114
|
const setting = universe.settings.resolve(DevTools.SourceMapManager.lazyLoadingSettingDescriptor);
|
|
109
115
|
setting.set(true);
|
|
116
|
+
const skipAllPausesSetting = universe.settings.resolve(DevTools.skipAllPausesSettingDescriptor);
|
|
117
|
+
skipAllPausesSetting.set(true);
|
|
110
118
|
// @ts-expect-error devtools-frontend has diffrent types.
|
|
111
119
|
const connection = new DevTools.PuppeteerDevToolsConnection(session);
|
|
112
120
|
const targetManager = universe.context.get(DevTools.TargetManager);
|
|
113
|
-
targetManager.observeModels(DevTools.DebuggerModel, SKIP_ALL_PAUSES);
|
|
114
121
|
targetManager.observeModels(DevTools.NetworkManager.NetworkManager, DISABLE_NETWORK);
|
|
115
122
|
const target = targetManager.createTarget('main', '', 'frame', // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
116
123
|
/* parentTarget */ null, session.id(), undefined, connection);
|
|
117
124
|
return { target, universe, session };
|
|
118
125
|
}
|
|
119
|
-
// We don't want to pause any DevTools universe session ever on the MCP side.
|
|
120
|
-
//
|
|
121
|
-
// Note that calling `setSkipAllPauses` only affects the session on which it was
|
|
122
|
-
// sent. This means DevTools can still pause, step and do whatever. We just won't
|
|
123
|
-
// see the `Debugger.paused`/`Debugger.resumed` events on the MCP side.
|
|
124
|
-
const SKIP_ALL_PAUSES = {
|
|
125
|
-
modelAdded(model) {
|
|
126
|
-
void model.agent.invoke_setSkipAllPauses({ skip: true });
|
|
127
|
-
},
|
|
128
|
-
modelRemoved() {
|
|
129
|
-
// Do nothing.
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
126
|
// Not recording network requests in the DevTools universe.
|
|
133
127
|
//
|
|
134
128
|
// The network requests are collected through pptr and there isn't a use case for
|