chrome-devtools-mcp 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -20
- package/build/src/BrowserManager.js +27 -18
- package/build/src/McpContext.js +435 -87
- package/build/src/McpPage.js +189 -59
- package/build/src/McpResponse.js +61 -44
- package/build/src/TextSnapshot.js +37 -18
- package/build/src/ToolHandler.js +256 -135
- package/build/src/bin/chrome-devtools-mcp-main.js +6 -4
- package/build/src/bin/chrome-devtools.js +4 -4
- package/build/src/collectors/PageCollector.js +13 -9
- package/build/src/collectors/ServiceWorkerCollector.js +2 -2
- package/build/src/collectors/constants.js +7 -0
- package/build/src/config/ConfigParser.js +44 -149
- package/build/src/config/ConfigWatcher.js +3 -2
- package/build/src/config/ServerConfig.js +251 -0
- package/build/src/config/browser-options.js +13 -4
- package/build/src/config/cli-options.js +35 -19
- package/build/src/config/mcp-options.js +61 -35
- package/build/src/config/puppeteer-options.js +4 -2
- package/build/src/daemon/client.js +3 -3
- package/build/src/daemon/daemon.js +7 -3
- package/build/src/daemon/utils.js +2 -1
- package/build/src/devtools/DevToolsCommentBridge.js +28 -5
- package/build/src/devtools/DevtoolsUtils.js +49 -12
- package/build/src/formatters/ConsoleFormatter.js +28 -1
- package/build/src/formatters/HeapSnapshotFormatter.js +14 -18
- package/build/src/formatters/NetworkFormatter.js +54 -15
- package/build/src/formatters/RemoteObjectFormatter.js +231 -0
- package/build/src/formatters/SnapshotFormatter.js +13 -3
- package/build/src/index.js +256 -104
- package/build/src/processors/HeapSnapshotManager.js +390 -128
- package/build/src/third_party/THIRD_PARTY_NOTICES +542 -445
- package/build/src/third_party/bundled-packages.json +2 -2
- package/build/src/third_party/cli.js +9239 -0
- package/build/src/third_party/devtools-formatter-worker.js +3089 -2438
- package/build/src/third_party/devtools-heap-snapshot-worker.js +172 -1
- package/build/src/third_party/index.js +52247 -55764
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +54576 -52174
- package/build/src/tools/ToolDefinition.js +90 -12
- package/build/src/tools/comments.js +42 -3
- package/build/src/tools/console.js +6 -4
- package/build/src/tools/css.js +1 -0
- package/build/src/tools/emulation.js +5 -4
- package/build/src/tools/extensions.js +5 -0
- package/build/src/tools/input.js +21 -6
- package/build/src/tools/lighthouse.js +24 -8
- package/build/src/tools/memory.js +59 -53
- package/build/src/tools/network.js +5 -4
- package/build/src/tools/pages.js +48 -6
- package/build/src/tools/performance.js +7 -4
- package/build/src/tools/pwa.js +7 -0
- package/build/src/tools/screencast.js +3 -1
- package/build/src/tools/screenshot.js +23 -7
- package/build/src/tools/script.js +38 -6
- package/build/src/tools/slim/tools.js +21 -5
- package/build/src/tools/snapshot.js +13 -3
- package/build/src/tools/thirdPartyDeveloper.js +3 -1
- package/build/src/tools/webmcp.js +2 -0
- package/build/src/utils/TaskRunner.js +136 -0
- package/build/src/utils/WaitForHelper.js +1 -1
- package/build/src/utils/bytes.js +2 -12
- package/build/src/utils/check-for-updates.js +1 -1
- package/build/src/utils/disclaimers.js +27 -0
- package/build/src/utils/keyboard.js +14 -2
- package/build/src/utils/logger.js +69 -0
- package/build/src/utils/resourceType.js +27 -0
- package/build/src/utils/text.js +29 -0
- package/build/src/utils/timeout.js +14 -0
- package/build/src/utils/url.js +41 -0
- package/build/src/version.js +1 -1
- package/package.json +5 -4
- package/skills/a11y-debugging/SKILL.md +3 -8
|
@@ -3,39 +3,22 @@
|
|
|
3
3
|
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
var _a;
|
|
7
|
-
import { yargs, hideBin } from '../third_party/index.js';
|
|
8
6
|
import { readFileSync } from 'node:fs';
|
|
9
|
-
import {
|
|
7
|
+
import { yargs, hideBin, } from '../third_party/cli.js';
|
|
10
8
|
import { getErrorMessage } from '../utils/errorHandling.js';
|
|
11
9
|
import { ConfigLocator } from './ConfigLocator.js';
|
|
10
|
+
import { mcpOptions, CLI_EXAMPLES, stripYargsPositionalArgs, withoutDefaults, } from './mcp-options.js';
|
|
11
|
+
import { ServerConfig } from './ServerConfig.js';
|
|
12
12
|
function isPlainObject(value) {
|
|
13
13
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
14
14
|
}
|
|
15
|
-
function stripYargsPositionalArgs(parsed) {
|
|
16
|
-
const copy = { ...parsed };
|
|
17
|
-
delete copy._;
|
|
18
|
-
delete copy.$0;
|
|
19
|
-
return copy;
|
|
20
|
-
}
|
|
21
|
-
function isMcpOptionKey(key) {
|
|
22
|
-
return key in mcpOptions;
|
|
23
|
-
}
|
|
24
|
-
function copyOption(target, source, key) {
|
|
25
|
-
if (key in source) {
|
|
26
|
-
target[key] = source[key];
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
delete target[key];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const explicitArgsByParsed = new WeakMap();
|
|
33
15
|
export class ConfigParser {
|
|
34
16
|
version;
|
|
35
17
|
argv;
|
|
36
18
|
env;
|
|
37
19
|
exitProcess;
|
|
38
20
|
#configPath;
|
|
21
|
+
#cliArgs;
|
|
39
22
|
#usageStatisticsNoticeShown = false;
|
|
40
23
|
configLocator;
|
|
41
24
|
constructor(version, argv = process.argv, env = process.env, exitProcess = true, configLocator) {
|
|
@@ -81,18 +64,22 @@ export class ConfigParser {
|
|
|
81
64
|
* Step 2: reads the JSON config file and runs it through yargs to reject
|
|
82
65
|
* unknown keys and apply coercions, without applying defaults.
|
|
83
66
|
*/
|
|
84
|
-
parseConfigFile(configPath) {
|
|
67
|
+
static parseConfigFile(configPath, rawContent) {
|
|
85
68
|
try {
|
|
86
|
-
const fileContent = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
69
|
+
const fileContent = JSON.parse(rawContent ?? readFileSync(configPath, 'utf-8'));
|
|
87
70
|
if (!isPlainObject(fileContent)) {
|
|
88
71
|
throw new Error('Config must be a JSON object');
|
|
89
72
|
}
|
|
73
|
+
const configOptions = withoutDefaults(mcpOptions);
|
|
74
|
+
delete configOptions.config;
|
|
90
75
|
const parsed = yargs([])
|
|
91
76
|
.parserConfiguration({
|
|
92
77
|
'strip-aliased': true,
|
|
93
78
|
'camel-case-expansion': false,
|
|
94
79
|
})
|
|
95
|
-
.options(
|
|
80
|
+
.options(configOptions)
|
|
81
|
+
.help(false)
|
|
82
|
+
.version(false)
|
|
96
83
|
.config(fileContent)
|
|
97
84
|
.strict()
|
|
98
85
|
.fail(false)
|
|
@@ -104,6 +91,9 @@ export class ConfigParser {
|
|
|
104
91
|
throw new Error(`Invalid JSON config file: ${getErrorMessage(err)}`);
|
|
105
92
|
}
|
|
106
93
|
}
|
|
94
|
+
parseConfigFile(configPath, rawContent) {
|
|
95
|
+
return ConfigParser.parseConfigFile(configPath, rawContent);
|
|
96
|
+
}
|
|
107
97
|
warnUnknownArgs(cliArgs) {
|
|
108
98
|
const allowedArgs = new Set(Object.keys(mcpOptions));
|
|
109
99
|
const unknownArgs = Object.keys(cliArgs).filter(arg => !allowedArgs.has(arg));
|
|
@@ -112,102 +102,16 @@ export class ConfigParser {
|
|
|
112
102
|
}
|
|
113
103
|
}
|
|
114
104
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
105
|
+
* Parses CLI arguments and the config file into a layered
|
|
106
|
+
* {@link ServerConfig}.
|
|
117
107
|
*/
|
|
118
|
-
|
|
119
|
-
const activeArgs = new Set();
|
|
120
|
-
for (const [key, val] of Object.entries(explicitArgs)) {
|
|
121
|
-
if (val !== undefined && val !== false) {
|
|
122
|
-
activeArgs.add(key);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
for (const group of CONFLICTING_ARGS) {
|
|
126
|
-
const activeInGroup = group.filter(arg => activeArgs.has(arg));
|
|
127
|
-
if (activeInGroup.length > 1) {
|
|
128
|
-
const [arg1, arg2] = activeInGroup;
|
|
129
|
-
throw new Error(`Arguments ${String(arg1)} and ${String(arg2)} are mutually exclusive`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
static validateImplications(explicitArgs) {
|
|
134
|
-
for (const [key, implied] of IMPLICATIONS) {
|
|
135
|
-
const isKeySet = explicitArgs[key] !== undefined && explicitArgs[key] !== false;
|
|
136
|
-
const isImpliedSet = explicitArgs[implied] !== undefined && explicitArgs[implied] !== false;
|
|
137
|
-
if (isKeySet && !isImpliedSet) {
|
|
138
|
-
throw new Error(`Implications failed:\n ${String(key)} -> ${String(implied)}`);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Step 5: fills in defaults for everything that was not set explicitly.
|
|
144
|
-
* `viaCli` is an explicit input like any other; it selects which defaults
|
|
145
|
-
* apply.
|
|
146
|
-
*/
|
|
147
|
-
applyDefaults(explicitArgs) {
|
|
148
|
-
const isViaCli = explicitArgs.viaCli === true;
|
|
149
|
-
const baseOptions = isViaCli ? getMcpOptionsForViaCli() : mcpOptions;
|
|
150
|
-
const resolvedArgs = { ...explicitArgs };
|
|
151
|
-
// `channel` only applies when Chrome is launched by channel. Leaving it
|
|
152
|
-
// unset otherwise keeps it out of telemetry (computeFlagUsage).
|
|
153
|
-
const launchesByChannel = !resolvedArgs.browserUrl &&
|
|
154
|
-
!resolvedArgs.wsEndpoint &&
|
|
155
|
-
!resolvedArgs.executablePath;
|
|
156
|
-
for (const [key, option] of Object.entries(baseOptions)) {
|
|
157
|
-
if (key === 'channel' && !launchesByChannel) {
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
if (resolvedArgs[key] === undefined &&
|
|
161
|
-
'default' in option) {
|
|
162
|
-
resolvedArgs[key] = option.default;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (isViaCli) {
|
|
166
|
-
if (resolvedArgs.filesystemRoot === DEFAULT_FILESYSTEM_ROOT &&
|
|
167
|
-
explicitArgs.allowUnrestrictedPaths !== false) {
|
|
168
|
-
resolvedArgs.allowUnrestrictedPaths = true;
|
|
169
|
-
resolvedArgs.filesystemRoot = undefined;
|
|
170
|
-
}
|
|
171
|
-
const connectsToExistingBrowser = resolvedArgs.autoConnect ||
|
|
172
|
-
resolvedArgs.browserUrl ||
|
|
173
|
-
resolvedArgs.wsEndpoint;
|
|
174
|
-
if (explicitArgs.isolated === undefined &&
|
|
175
|
-
resolvedArgs.userDataDir === undefined &&
|
|
176
|
-
!connectsToExistingBrowser) {
|
|
177
|
-
resolvedArgs.isolated = true;
|
|
178
|
-
}
|
|
179
|
-
if (resolvedArgs.categoryExtensions === undefined &&
|
|
180
|
-
!connectsToExistingBrowser) {
|
|
181
|
-
resolvedArgs.categoryExtensions = true;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
if (this.env['CI'] || this.env['CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS']) {
|
|
185
|
-
if (!this.#usageStatisticsNoticeShown) {
|
|
186
|
-
this.#usageStatisticsNoticeShown = true;
|
|
187
|
-
console.error("turning off usage statistics. process.env['CI'] || process.env['CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS'] is set.");
|
|
188
|
-
}
|
|
189
|
-
resolvedArgs.usageStatistics = false;
|
|
190
|
-
}
|
|
191
|
-
if (resolvedArgs.categoryExperimentalThirdParty === undefined &&
|
|
192
|
-
this.env['CHROME_DEVTOOLS_MCP_CATEGORY_EXPERIMENTAL_THIRD_PARTY']) {
|
|
193
|
-
resolvedArgs.categoryExperimentalThirdParty = true;
|
|
194
|
-
}
|
|
195
|
-
// The merge and the default loop lose the static type that yargs infers from
|
|
196
|
-
// `mcpOptions`. Every value was produced by the same option definitions (CLI
|
|
197
|
-
// parser, strict config-file parser, option defaults), so the shape matches.
|
|
198
|
-
const parsed = resolvedArgs;
|
|
199
|
-
explicitArgsByParsed.set(parsed, {
|
|
200
|
-
parser: this,
|
|
201
|
-
explicitArgs: { ...explicitArgs },
|
|
202
|
-
});
|
|
203
|
-
return parsed;
|
|
204
|
-
}
|
|
205
|
-
parse() {
|
|
108
|
+
parseConfig() {
|
|
206
109
|
try {
|
|
207
110
|
const cliArgs = this.parseCliArgs();
|
|
111
|
+
this.#cliArgs = cliArgs;
|
|
208
112
|
this.#configPath = cliArgs.config ?? this.configLocator.locate(this.env);
|
|
209
113
|
this.warnUnknownArgs(cliArgs);
|
|
210
|
-
return this.#
|
|
114
|
+
return this.#resolveConfig(cliArgs);
|
|
211
115
|
}
|
|
212
116
|
catch (error) {
|
|
213
117
|
if (this.exitProcess) {
|
|
@@ -217,48 +121,39 @@ export class ConfigParser {
|
|
|
217
121
|
throw error;
|
|
218
122
|
}
|
|
219
123
|
}
|
|
124
|
+
parse() {
|
|
125
|
+
return this.parseConfig().resolved;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Re-reads the config file resolved by `parse()` and merges it with the CLI
|
|
129
|
+
* arguments again into a new {@link ServerConfig}. Unlike `parseConfig()`, it
|
|
130
|
+
* does not discover a new config file and throws on invalid configuration
|
|
131
|
+
* instead of exiting the process.
|
|
132
|
+
*/
|
|
133
|
+
reloadConfig() {
|
|
134
|
+
this.#cliArgs ??= this.parseCliArgs();
|
|
135
|
+
return this.#resolveConfig(this.#cliArgs);
|
|
136
|
+
}
|
|
220
137
|
/**
|
|
221
138
|
* Re-reads the config file resolved by `parse()` and merges it with the CLI
|
|
222
139
|
* arguments again. Unlike `parse()`, it does not discover a new config file
|
|
223
140
|
* and throws on invalid configuration instead of exiting the process.
|
|
224
141
|
*/
|
|
225
142
|
reload() {
|
|
226
|
-
return this
|
|
143
|
+
return this.reloadConfig().resolved;
|
|
227
144
|
}
|
|
228
|
-
#
|
|
145
|
+
#resolveConfig(cliArgs) {
|
|
229
146
|
const configPath = this.#configPath;
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
return
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Merges explicit inputs so that a running server continues with `next` for
|
|
243
|
-
* reloadable options and `previous` for everything else, then validates and
|
|
244
|
-
* applies defaults.
|
|
245
|
-
*/
|
|
246
|
-
static mergeReloadableOptions(previous, next) {
|
|
247
|
-
const previousEntry = explicitArgsByParsed.get(previous);
|
|
248
|
-
const nextEntry = explicitArgsByParsed.get(next);
|
|
249
|
-
const previousExplicit = previousEntry?.explicitArgs ?? previous;
|
|
250
|
-
const nextExplicit = nextEntry?.explicitArgs ?? next;
|
|
251
|
-
const merged = { ...previousExplicit };
|
|
252
|
-
for (const name of Object.keys(mcpOptions)) {
|
|
253
|
-
if (isMcpOptionKey(name) && isReloadableOption(name)) {
|
|
254
|
-
copyOption(merged, nextExplicit, name);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
_a.validateConflicts(merged);
|
|
258
|
-
_a.validateImplications(merged);
|
|
259
|
-
const parser = nextEntry?.parser ?? previousEntry?.parser ?? new _a('');
|
|
260
|
-
return parser.applyDefaults(merged);
|
|
147
|
+
const fileArgs = configPath ? this.parseConfigFile(configPath) : {};
|
|
148
|
+
const config = ServerConfig.create({
|
|
149
|
+
cliArgs,
|
|
150
|
+
fileArgs,
|
|
151
|
+
configPath,
|
|
152
|
+
env: this.env,
|
|
153
|
+
suppressUsageStatisticsNotice: this.#usageStatisticsNoticeShown,
|
|
154
|
+
});
|
|
155
|
+
this.#usageStatisticsNoticeShown = true;
|
|
156
|
+
return config;
|
|
261
157
|
}
|
|
262
158
|
}
|
|
263
|
-
_a = ConfigParser;
|
|
264
159
|
//# sourceMappingURL=ConfigParser.js.map
|
|
@@ -22,7 +22,8 @@ function readContent(filePath) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* Watches a config file and calls `onChange` after it was
|
|
25
|
+
* Watches a config file and calls `onChange` with the new content after it was
|
|
26
|
+
* modified.
|
|
26
27
|
*
|
|
27
28
|
* - Symlinks are resolved once on start, and the directory of the real file is
|
|
28
29
|
* watched. Watching the directory instead of the file keeps working when
|
|
@@ -63,7 +64,7 @@ export class ConfigWatcher {
|
|
|
63
64
|
}
|
|
64
65
|
this.#content = content;
|
|
65
66
|
this.#pending = this.#pending
|
|
66
|
-
.then(() => this.#onChange())
|
|
67
|
+
.then(() => this.#onChange(content))
|
|
67
68
|
.catch(err => {
|
|
68
69
|
console.error(`Failed to apply ${this.#configPath}:`, err);
|
|
69
70
|
});
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
7
|
+
import { yargs } from '../third_party/cli.js';
|
|
8
|
+
import { CONFLICTING_ARGS, DEFAULT_FILESYSTEM_ROOT, IMPLICATIONS, isReloadableOption, mcpOptions, mcpOptionsForViaCli, stripYargsPositionalArgs, } from './mcp-options.js';
|
|
9
|
+
function isMcpOptionKey(key) {
|
|
10
|
+
return key in mcpOptions;
|
|
11
|
+
}
|
|
12
|
+
function copyOption(target, source, key) {
|
|
13
|
+
if (key in source) {
|
|
14
|
+
target[key] = source[key];
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
delete target[key];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function filterExplicitArgs(args, baseOptions) {
|
|
21
|
+
const filtered = {};
|
|
22
|
+
for (const key of Object.keys(args)) {
|
|
23
|
+
if (!isMcpOptionKey(key)) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (args[key] === undefined && 'default' in baseOptions[key]) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
copyOption(filtered, args, key);
|
|
30
|
+
}
|
|
31
|
+
return filtered;
|
|
32
|
+
}
|
|
33
|
+
function mergeLayer(previous, next) {
|
|
34
|
+
const merged = { ...previous };
|
|
35
|
+
for (const name of Object.keys(mcpOptions)) {
|
|
36
|
+
if (isMcpOptionKey(name) && isReloadableOption(name)) {
|
|
37
|
+
copyOption(merged, next, name);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return merged;
|
|
41
|
+
}
|
|
42
|
+
function parseDefaultArgs(options) {
|
|
43
|
+
const parsed = yargs([])
|
|
44
|
+
.parserConfiguration({
|
|
45
|
+
'strip-aliased': true,
|
|
46
|
+
'camel-case-expansion': false,
|
|
47
|
+
})
|
|
48
|
+
.options(options)
|
|
49
|
+
.parseSync([]);
|
|
50
|
+
return {
|
|
51
|
+
...stripYargsPositionalArgs(parsed),
|
|
52
|
+
// yargs copies array defaults, so restore the shared reference that the
|
|
53
|
+
// `viaCli` check in `applyDefaults()` compares with `===`.
|
|
54
|
+
filesystemRoot: DEFAULT_FILESYSTEM_ROOT,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Holds explicit CLI and config-file layers alongside the resolved arguments.
|
|
59
|
+
*
|
|
60
|
+
* Components read live configuration through {@link ReadonlyServerConfig}.
|
|
61
|
+
* Only the owning server updates the config in place via {@link commit} after
|
|
62
|
+
* computing and validating a candidate reload via {@link mergeReloadable}.
|
|
63
|
+
*/
|
|
64
|
+
export class ServerConfig {
|
|
65
|
+
#cliArgs;
|
|
66
|
+
#fileArgs;
|
|
67
|
+
#configPath;
|
|
68
|
+
#env;
|
|
69
|
+
#resolved;
|
|
70
|
+
constructor(init) {
|
|
71
|
+
this.#cliArgs = { ...init.cliArgs };
|
|
72
|
+
this.#fileArgs = { ...init.fileArgs };
|
|
73
|
+
this.#configPath = init.configPath;
|
|
74
|
+
this.#env = init.env ?? process.env;
|
|
75
|
+
this.#resolved = { ...init.resolved };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Step 4: rejects mutually exclusive inputs. Only explicit inputs are
|
|
79
|
+
* checked, so defaults never conflict.
|
|
80
|
+
*/
|
|
81
|
+
static validateConflicts(explicitArgs) {
|
|
82
|
+
const activeArgs = new Set();
|
|
83
|
+
for (const [key, val] of Object.entries(explicitArgs)) {
|
|
84
|
+
if (val !== undefined && val !== false) {
|
|
85
|
+
activeArgs.add(key);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
for (const group of CONFLICTING_ARGS) {
|
|
89
|
+
const activeInGroup = group.filter(arg => activeArgs.has(arg));
|
|
90
|
+
if (activeInGroup.length > 1) {
|
|
91
|
+
const [arg1, arg2] = activeInGroup;
|
|
92
|
+
throw new Error(`Arguments ${String(arg1)} and ${String(arg2)} are mutually exclusive`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
static validateImplications(explicitArgs) {
|
|
97
|
+
for (const [key, implied] of IMPLICATIONS) {
|
|
98
|
+
const isKeySet = explicitArgs[key] !== undefined && explicitArgs[key] !== false;
|
|
99
|
+
const isImpliedSet = explicitArgs[implied] !== undefined && explicitArgs[implied] !== false;
|
|
100
|
+
if (isKeySet && !isImpliedSet) {
|
|
101
|
+
throw new Error(`Implications failed:\n ${String(key)} -> ${String(implied)}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Step 5: fills in defaults for everything that was not set explicitly.
|
|
107
|
+
* `viaCli` is an explicit input like any other; it selects which defaults
|
|
108
|
+
* apply.
|
|
109
|
+
*/
|
|
110
|
+
static applyDefaults(explicitArgs, options) {
|
|
111
|
+
const env = options?.env ?? process.env;
|
|
112
|
+
const isViaCli = explicitArgs.viaCli === true;
|
|
113
|
+
const baseOptions = isViaCli ? mcpOptionsForViaCli : mcpOptions;
|
|
114
|
+
const resolvedArgs = {
|
|
115
|
+
...parseDefaultArgs(baseOptions),
|
|
116
|
+
...filterExplicitArgs(explicitArgs, baseOptions),
|
|
117
|
+
};
|
|
118
|
+
// `channel` only applies when Chrome is launched by channel. Leaving it
|
|
119
|
+
// unset otherwise keeps it out of telemetry (computeFlagUsage).
|
|
120
|
+
const launchesByChannel = !resolvedArgs.browserUrl &&
|
|
121
|
+
!resolvedArgs.wsEndpoint &&
|
|
122
|
+
!resolvedArgs.executablePath;
|
|
123
|
+
if (!launchesByChannel && explicitArgs.channel === undefined) {
|
|
124
|
+
delete resolvedArgs.channel;
|
|
125
|
+
}
|
|
126
|
+
if (isViaCli) {
|
|
127
|
+
resolvedArgs.slim = false;
|
|
128
|
+
resolvedArgs.pageIdRouting = true;
|
|
129
|
+
if (resolvedArgs.filesystemRoot === DEFAULT_FILESYSTEM_ROOT &&
|
|
130
|
+
explicitArgs.allowUnrestrictedPaths !== false) {
|
|
131
|
+
resolvedArgs.allowUnrestrictedPaths = true;
|
|
132
|
+
resolvedArgs.filesystemRoot = undefined;
|
|
133
|
+
}
|
|
134
|
+
const connectsToExistingBrowser = resolvedArgs.autoConnect ||
|
|
135
|
+
resolvedArgs.browserUrl ||
|
|
136
|
+
resolvedArgs.wsEndpoint;
|
|
137
|
+
if (explicitArgs.isolated === undefined &&
|
|
138
|
+
resolvedArgs.userDataDir === undefined &&
|
|
139
|
+
!connectsToExistingBrowser) {
|
|
140
|
+
resolvedArgs.isolated = true;
|
|
141
|
+
}
|
|
142
|
+
if (resolvedArgs.categoryExtensions === undefined &&
|
|
143
|
+
!connectsToExistingBrowser) {
|
|
144
|
+
resolvedArgs.categoryExtensions = true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (env['CI'] || env['CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS']) {
|
|
148
|
+
if (!options?.suppressUsageStatisticsNotice) {
|
|
149
|
+
console.error("turning off usage statistics. process.env['CI'] || process.env['CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS'] is set.");
|
|
150
|
+
}
|
|
151
|
+
resolvedArgs.usageStatistics = false;
|
|
152
|
+
}
|
|
153
|
+
if (resolvedArgs.categoryExperimentalThirdParty === undefined &&
|
|
154
|
+
env['CHROME_DEVTOOLS_MCP_CATEGORY_EXPERIMENTAL_THIRD_PARTY']) {
|
|
155
|
+
resolvedArgs.categoryExperimentalThirdParty = true;
|
|
156
|
+
}
|
|
157
|
+
return resolvedArgs;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Step 3–5: merges CLI and config-file layers (`CLI > config file`),
|
|
161
|
+
* validates conflicts and implications, and applies defaults.
|
|
162
|
+
*/
|
|
163
|
+
static create(options) {
|
|
164
|
+
const explicitArgs = {
|
|
165
|
+
...options.fileArgs,
|
|
166
|
+
...options.cliArgs,
|
|
167
|
+
...(options.configPath ? { config: options.configPath } : {}),
|
|
168
|
+
};
|
|
169
|
+
ServerConfig.validateConflicts(explicitArgs);
|
|
170
|
+
ServerConfig.validateImplications(explicitArgs);
|
|
171
|
+
const resolved = ServerConfig.applyDefaults(explicitArgs, {
|
|
172
|
+
env: options.env,
|
|
173
|
+
suppressUsageStatisticsNotice: options.suppressUsageStatisticsNotice,
|
|
174
|
+
});
|
|
175
|
+
return new ServerConfig({
|
|
176
|
+
cliArgs: options.cliArgs,
|
|
177
|
+
fileArgs: options.fileArgs,
|
|
178
|
+
configPath: options.configPath,
|
|
179
|
+
env: options.env,
|
|
180
|
+
resolved,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
get cliArgs() {
|
|
184
|
+
return this.#cliArgs;
|
|
185
|
+
}
|
|
186
|
+
get fileArgs() {
|
|
187
|
+
return this.#fileArgs;
|
|
188
|
+
}
|
|
189
|
+
get configPath() {
|
|
190
|
+
return this.#configPath;
|
|
191
|
+
}
|
|
192
|
+
get resolved() {
|
|
193
|
+
return this.#resolved;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Produces a new {@link ServerConfig} with updated config-file arguments,
|
|
197
|
+
* preserving this config's CLI arguments, config path, and environment.
|
|
198
|
+
*/
|
|
199
|
+
withFileArgs(fileArgs) {
|
|
200
|
+
return ServerConfig.create({
|
|
201
|
+
cliArgs: { ...this.#cliArgs },
|
|
202
|
+
fileArgs,
|
|
203
|
+
configPath: this.#configPath,
|
|
204
|
+
env: this.#env,
|
|
205
|
+
suppressUsageStatisticsNotice: true,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Produces a new {@link ServerConfig} that takes reloadable options from
|
|
210
|
+
* `next` and keeps restart-required options from this config, preserving
|
|
211
|
+
* `CLI > config file > defaults` precedence.
|
|
212
|
+
*/
|
|
213
|
+
mergeReloadable(next, options) {
|
|
214
|
+
const mergedFileArgs = mergeLayer(this.#fileArgs, next.#fileArgs);
|
|
215
|
+
const mergedCliArgs = mergeLayer(this.#cliArgs, next.#cliArgs);
|
|
216
|
+
return ServerConfig.create({
|
|
217
|
+
cliArgs: mergedCliArgs,
|
|
218
|
+
fileArgs: mergedFileArgs,
|
|
219
|
+
configPath: this.#configPath,
|
|
220
|
+
env: options?.env ?? this.#env,
|
|
221
|
+
suppressUsageStatisticsNotice: true,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Returns the restart-required options whose resolved values differ between
|
|
226
|
+
* this config and `next`.
|
|
227
|
+
*/
|
|
228
|
+
getRestartRequiredChanges(next) {
|
|
229
|
+
const changed = [];
|
|
230
|
+
for (const name of Object.keys(mcpOptions)) {
|
|
231
|
+
if (isMcpOptionKey(name) &&
|
|
232
|
+
!isReloadableOption(name) &&
|
|
233
|
+
(!isDeepStrictEqual(this.#fileArgs[name], next.#fileArgs[name]) ||
|
|
234
|
+
!isDeepStrictEqual(this.#cliArgs[name], next.#cliArgs[name])) &&
|
|
235
|
+
!isDeepStrictEqual(this.#resolved[name], next.#resolved[name])) {
|
|
236
|
+
changed.push(name);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return changed;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Commits a previously validated {@link ServerConfig} snapshot in place so
|
|
243
|
+
* all shared {@link ReadonlyServerConfig} readers observe the new values.
|
|
244
|
+
*/
|
|
245
|
+
commit(next) {
|
|
246
|
+
this.#cliArgs = next.#cliArgs;
|
|
247
|
+
this.#fileArgs = next.#fileArgs;
|
|
248
|
+
this.#resolved = next.#resolved;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=ServerConfig.js.map
|
|
@@ -57,14 +57,23 @@ export const browserOptions = {
|
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
59
|
try {
|
|
60
|
-
const parsed = JSON.parse(val);
|
|
61
|
-
if (typeof parsed !== 'object' ||
|
|
60
|
+
const parsed = typeof val === 'string' ? JSON.parse(val) : val;
|
|
61
|
+
if (typeof parsed !== 'object' ||
|
|
62
|
+
parsed === null ||
|
|
63
|
+
Array.isArray(parsed)) {
|
|
62
64
|
throw new Error('Headers must be a JSON object');
|
|
63
65
|
}
|
|
64
|
-
|
|
66
|
+
const headers = {};
|
|
67
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
68
|
+
if (typeof value !== 'string') {
|
|
69
|
+
throw new Error(`Header "${key}" must have a string value`);
|
|
70
|
+
}
|
|
71
|
+
headers[key] = value;
|
|
72
|
+
}
|
|
73
|
+
return headers;
|
|
65
74
|
}
|
|
66
75
|
catch (error) {
|
|
67
|
-
throw new Error(`Invalid JSON for wsHeaders: ${error.message}`);
|
|
76
|
+
throw new Error(`Invalid JSON for wsHeaders: ${error instanceof Error ? error.message : String(error)}`);
|
|
68
77
|
}
|
|
69
78
|
},
|
|
70
79
|
},
|