chrome-devtools-mcp 1.10.1 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/BrowserManager.js +132 -13
- package/build/src/McpContext.js +188 -138
- package/build/src/McpPage.js +348 -96
- package/build/src/McpResponse.js +234 -76
- package/build/src/McpWorker.js +66 -0
- package/build/src/SlimMcpResponse.js +5 -1
- package/build/src/TextSnapshot.js +3 -2
- package/build/src/ToolHandler.js +80 -42
- package/build/src/bin/chrome-devtools-mcp-main.js +8 -7
- package/build/src/bin/chrome-devtools-mcp.js +1 -1
- package/build/src/bin/chrome-devtools.js +31 -41
- package/build/src/collectors/ServiceWorkerCollector.js +18 -11
- package/build/src/config/ConfigLocator.js +70 -0
- package/build/src/config/ConfigParser.js +264 -0
- package/build/src/config/ConfigWatcher.js +93 -0
- package/build/src/config/browser-options.js +2 -13
- package/build/src/config/category-options.js +15 -30
- package/build/src/config/cli-commands.js +165 -5
- package/build/src/config/cli-options.js +410 -43
- package/build/src/config/mcp-options.js +156 -234
- package/build/src/config/puppeteer-options.js +65 -0
- package/build/src/config/tool-options.js +60 -0
- package/build/src/daemon/client.js +81 -41
- package/build/src/daemon/daemon.js +55 -45
- package/build/src/daemon/utils.js +44 -11
- package/build/src/devtools/DevToolsCommentBridge.js +43 -6
- package/build/src/devtools/DevtoolsUtils.js +3 -3
- package/build/src/devtools/McpHostBindingAdapter.js +0 -1
- package/build/src/formatters/CommentFormatter.js +4 -13
- package/build/src/formatters/ConsoleFormatter.js +1 -1
- package/build/src/formatters/CssFormatter.js +3 -2
- package/build/src/formatters/HeapSnapshotFormatter.js +104 -46
- package/build/src/formatters/IssueFormatter.js +33 -32
- package/build/src/formatters/NetworkFormatter.js +12 -11
- package/build/src/formatters/SnapshotFormatter.js +31 -4
- package/build/src/index.js +54 -9
- package/build/src/processors/ChunkedTraceParser.js +11 -11
- package/build/src/processors/HeapSnapshotManager.js +121 -84
- package/build/src/processors/PerformanceTrace.js +9 -9
- package/build/src/telemetry/ClearcutLogger.js +1 -1
- package/build/src/telemetry/transformation.js +7 -11
- package/build/src/telemetry/watchdog/main.js +1 -1
- package/build/src/third_party/THIRD_PARTY_NOTICES +10 -397
- package/build/src/third_party/bundled-packages.json +7 -8
- package/build/src/third_party/devtools-formatter-worker.js +1193 -62
- package/build/src/third_party/devtools-heap-snapshot-worker.js +1126 -21
- package/build/src/third_party/index.js +8087 -19419
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantRead.md +0 -1
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantReadOptOut.md +5 -0
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSet.md +0 -1
- package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSetOptOut.md +5 -0
- package/build/src/third_party/issue-descriptions/deprecation.md +1 -1
- package/build/src/third_party/issue-descriptions/genericGeolocationPromptWithoutUserGesture.md +5 -0
- package/build/src/third_party/issue-descriptions/sriValidationFailedIntegrityMismatch.md +2 -0
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +3 -3
- package/build/src/tools/ToolDefinition.js +16 -4
- package/build/src/tools/comments.js +20 -1
- package/build/src/tools/css.js +4 -2
- package/build/src/tools/emulation.js +17 -4
- package/build/src/tools/input.js +8 -3
- package/build/src/tools/lighthouse.js +112 -4
- package/build/src/tools/memory.js +129 -28
- package/build/src/tools/pages.js +5 -2
- package/build/src/tools/performance.js +21 -3
- package/build/src/tools/screencast.js +71 -32
- package/build/src/tools/screenshot.js +29 -14
- package/build/src/tools/script.js +90 -37
- package/build/src/tools/slim/tools.js +6 -8
- package/build/src/tools/thirdPartyDeveloper.js +6 -4
- package/build/src/tools/tools.js +35 -22
- package/build/src/tools/webmcp.js +9 -6
- package/build/src/types.js +11 -0
- package/build/src/utils/WaitForHelper.js +14 -1
- package/build/src/utils/check-for-updates.js +1 -1
- package/build/src/utils/errorHandling.js +20 -0
- package/build/src/utils/logger.js +15 -5
- package/build/src/utils/text.js +15 -0
- package/build/src/utils/url.js +99 -3
- package/build/src/version.js +1 -1
- package/package.json +14 -10
- package/skills/a11y-debugging/SKILL.md +4 -4
- package/skills/chrome-devtools/SKILL.md +2 -2
- package/skills/chrome-devtools-cli/SKILL.md +18 -15
- package/skills/cookie-debugging/SKILL.md +8 -5
- package/skills/debug-optimize-lcp/SKILL.md +1 -1
- package/skills/troubleshooting/SKILL.md +5 -6
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
var _a;
|
|
7
|
+
import { yargs, hideBin } from '../third_party/index.js';
|
|
8
|
+
import { readFileSync } from 'node:fs';
|
|
9
|
+
import { mcpOptions, getMcpOptionsForViaCli, CLI_EXAMPLES, CONFLICTING_ARGS, IMPLICATIONS, DEFAULT_FILESYSTEM_ROOT, isReloadableOption, withoutDefaults, } from './mcp-options.js';
|
|
10
|
+
import { getErrorMessage } from '../utils/errorHandling.js';
|
|
11
|
+
import { ConfigLocator } from './ConfigLocator.js';
|
|
12
|
+
function isPlainObject(value) {
|
|
13
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
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
|
+
export class ConfigParser {
|
|
34
|
+
version;
|
|
35
|
+
argv;
|
|
36
|
+
env;
|
|
37
|
+
exitProcess;
|
|
38
|
+
#configPath;
|
|
39
|
+
#usageStatisticsNoticeShown = false;
|
|
40
|
+
configLocator;
|
|
41
|
+
constructor(version, argv = process.argv, env = process.env, exitProcess = true, configLocator) {
|
|
42
|
+
this.version = version;
|
|
43
|
+
this.argv = argv;
|
|
44
|
+
this.env = env;
|
|
45
|
+
this.exitProcess = exitProcess;
|
|
46
|
+
this.configLocator = configLocator ?? new ConfigLocator();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The config file resolved by the last `parse()` call, if any.
|
|
50
|
+
*/
|
|
51
|
+
get configPath() {
|
|
52
|
+
return this.#configPath;
|
|
53
|
+
}
|
|
54
|
+
buildCliParser(options = mcpOptions) {
|
|
55
|
+
const yargsInstance = yargs(hideBin(this.argv));
|
|
56
|
+
return yargsInstance
|
|
57
|
+
.scriptName('npx chrome-devtools-mcp@latest')
|
|
58
|
+
.parserConfiguration({
|
|
59
|
+
'strip-aliased': true,
|
|
60
|
+
'strip-dashed': true,
|
|
61
|
+
})
|
|
62
|
+
.options(options)
|
|
63
|
+
.showHelpOnFail(false, 'Specify --help for available options')
|
|
64
|
+
.example(CLI_EXAMPLES)
|
|
65
|
+
.wrap(Math.min(120, yargsInstance.terminalWidth()))
|
|
66
|
+
.help()
|
|
67
|
+
.version(this.version);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Step 1: parses the CLI flags without applying defaults, so the result only
|
|
71
|
+
* contains what the user passed. `--help` and `--version` print and exit the
|
|
72
|
+
* process; parse errors throw.
|
|
73
|
+
*/
|
|
74
|
+
parseCliArgs() {
|
|
75
|
+
const parsed = this.buildCliParser(withoutDefaults(mcpOptions))
|
|
76
|
+
.fail(false)
|
|
77
|
+
.parseSync();
|
|
78
|
+
return stripYargsPositionalArgs(parsed);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Step 2: reads the JSON config file and runs it through yargs to reject
|
|
82
|
+
* unknown keys and apply coercions, without applying defaults.
|
|
83
|
+
*/
|
|
84
|
+
parseConfigFile(configPath) {
|
|
85
|
+
try {
|
|
86
|
+
const fileContent = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
87
|
+
if (!isPlainObject(fileContent)) {
|
|
88
|
+
throw new Error('Config must be a JSON object');
|
|
89
|
+
}
|
|
90
|
+
const parsed = yargs([])
|
|
91
|
+
.parserConfiguration({
|
|
92
|
+
'strip-aliased': true,
|
|
93
|
+
'camel-case-expansion': false,
|
|
94
|
+
})
|
|
95
|
+
.options(withoutDefaults(mcpOptions))
|
|
96
|
+
.config(fileContent)
|
|
97
|
+
.strict()
|
|
98
|
+
.fail(false)
|
|
99
|
+
.exitProcess(false)
|
|
100
|
+
.parseSync([]);
|
|
101
|
+
return stripYargsPositionalArgs(parsed);
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
throw new Error(`Invalid JSON config file: ${getErrorMessage(err)}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
warnUnknownArgs(cliArgs) {
|
|
108
|
+
const allowedArgs = new Set(Object.keys(mcpOptions));
|
|
109
|
+
const unknownArgs = Object.keys(cliArgs).filter(arg => !allowedArgs.has(arg));
|
|
110
|
+
if (unknownArgs.length > 0) {
|
|
111
|
+
console.error(`Unknown arguments: ${unknownArgs.map(arg => `--${arg}`)}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Step 4: rejects mutually exclusive inputs. Only explicit inputs are checked,
|
|
116
|
+
* so defaults never conflict.
|
|
117
|
+
*/
|
|
118
|
+
static validateConflicts(explicitArgs) {
|
|
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() {
|
|
206
|
+
try {
|
|
207
|
+
const cliArgs = this.parseCliArgs();
|
|
208
|
+
this.#configPath = cliArgs.config ?? this.configLocator.locate(this.env);
|
|
209
|
+
this.warnUnknownArgs(cliArgs);
|
|
210
|
+
return this.#resolve(cliArgs);
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
if (this.exitProcess) {
|
|
214
|
+
console.error(getErrorMessage(error));
|
|
215
|
+
process.exit(1);
|
|
216
|
+
}
|
|
217
|
+
throw error;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Re-reads the config file resolved by `parse()` and merges it with the CLI
|
|
222
|
+
* arguments again. Unlike `parse()`, it does not discover a new config file
|
|
223
|
+
* and throws on invalid configuration instead of exiting the process.
|
|
224
|
+
*/
|
|
225
|
+
reload() {
|
|
226
|
+
return this.#resolve(this.parseCliArgs());
|
|
227
|
+
}
|
|
228
|
+
#resolve(cliArgs) {
|
|
229
|
+
const configPath = this.#configPath;
|
|
230
|
+
const configFileArgs = configPath ? this.parseConfigFile(configPath) : {};
|
|
231
|
+
// Step 3: merges the explicit inputs. The CLI wins over the config file.
|
|
232
|
+
const explicitArgs = {
|
|
233
|
+
...configFileArgs,
|
|
234
|
+
...cliArgs,
|
|
235
|
+
...(configPath ? { config: configPath } : {}),
|
|
236
|
+
};
|
|
237
|
+
_a.validateConflicts(explicitArgs);
|
|
238
|
+
_a.validateImplications(explicitArgs);
|
|
239
|
+
return this.applyDefaults(explicitArgs);
|
|
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);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
_a = ConfigParser;
|
|
264
|
+
//# sourceMappingURL=ConfigParser.js.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { DevTools } from '../third_party/index.js';
|
|
9
|
+
import { getErrorMessage } from '../utils/errorHandling.js';
|
|
10
|
+
import { logger } from '../utils/logger.js';
|
|
11
|
+
const DEFAULT_DEBOUNCE_MS = 200;
|
|
12
|
+
/**
|
|
13
|
+
* Returns undefined if the file cannot be read, for example while it is being
|
|
14
|
+
* replaced.
|
|
15
|
+
*/
|
|
16
|
+
function readContent(filePath) {
|
|
17
|
+
try {
|
|
18
|
+
return fs.readFileSync(filePath, 'utf8');
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Watches a config file and calls `onChange` after it was modified.
|
|
26
|
+
*
|
|
27
|
+
* - Symlinks are resolved once on start, and the directory of the real file is
|
|
28
|
+
* watched. Watching the directory instead of the file keeps working when
|
|
29
|
+
* editors save atomically by replacing the file.
|
|
30
|
+
* - Events are debounced because some platforms emit several events for a
|
|
31
|
+
* single change.
|
|
32
|
+
* - Some platforms do not report the file name, such events are not filtered.
|
|
33
|
+
* - `onChange` is only called if the content changed. For example, macOS can
|
|
34
|
+
* report events that happened shortly before the watcher was started.
|
|
35
|
+
*/
|
|
36
|
+
export class ConfigWatcher {
|
|
37
|
+
#configPath;
|
|
38
|
+
#onChange;
|
|
39
|
+
#debounceMs;
|
|
40
|
+
#watcher;
|
|
41
|
+
#debounced;
|
|
42
|
+
#content;
|
|
43
|
+
#pending = Promise.resolve();
|
|
44
|
+
constructor(configPath, onChange, options = {}) {
|
|
45
|
+
this.#configPath = configPath;
|
|
46
|
+
this.#onChange = onChange;
|
|
47
|
+
this.#debounceMs = options.debounceMs ?? DEFAULT_DEBOUNCE_MS;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Starts watching the config file. Throws if `configPath` does not exist.
|
|
51
|
+
*/
|
|
52
|
+
start() {
|
|
53
|
+
if (this.#watcher) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const realPath = fs.realpathSync(this.#configPath);
|
|
57
|
+
const fileName = path.basename(realPath);
|
|
58
|
+
this.#content = readContent(realPath);
|
|
59
|
+
this.#debounced = DevTools.Common.Debouncer.debounce(() => {
|
|
60
|
+
const content = readContent(realPath);
|
|
61
|
+
if (content === undefined || content === this.#content) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.#content = content;
|
|
65
|
+
this.#pending = this.#pending
|
|
66
|
+
.then(() => this.#onChange())
|
|
67
|
+
.catch(err => {
|
|
68
|
+
console.error(`Failed to apply ${this.#configPath}:`, err);
|
|
69
|
+
});
|
|
70
|
+
}, this.#debounceMs);
|
|
71
|
+
this.#watcher = fs.watch(path.dirname(realPath), { persistent: false }, (_eventType, changedFileName) => {
|
|
72
|
+
if (changedFileName !== null && changedFileName !== fileName) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.#debounced?.();
|
|
76
|
+
});
|
|
77
|
+
this.#watcher.on('error', err => {
|
|
78
|
+
console.error(`Stopped watching ${this.#configPath}: ${getErrorMessage(err)}`);
|
|
79
|
+
this.dispose();
|
|
80
|
+
});
|
|
81
|
+
logger?.(`Watching ${realPath} for config changes`);
|
|
82
|
+
}
|
|
83
|
+
dispose() {
|
|
84
|
+
this.#debounced?.cancel();
|
|
85
|
+
this.#debounced = undefined;
|
|
86
|
+
this.#watcher?.close();
|
|
87
|
+
this.#watcher = undefined;
|
|
88
|
+
}
|
|
89
|
+
[Symbol.dispose]() {
|
|
90
|
+
this.dispose();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=ConfigWatcher.js.map
|
|
@@ -7,20 +7,12 @@ export const browserOptions = {
|
|
|
7
7
|
autoConnect: {
|
|
8
8
|
type: 'boolean',
|
|
9
9
|
description: 'If specified, automatically connects to a browser (Chrome 144+) running locally from the user data directory identified by the channel param (default channel is stable). Requires the remote debugging server to be started in the Chrome instance via chrome://inspect/#remote-debugging.',
|
|
10
|
-
conflicts: ['isolated', 'executablePath'],
|
|
11
10
|
default: false,
|
|
12
|
-
coerce: (value) => {
|
|
13
|
-
if (!value) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
return value;
|
|
17
|
-
},
|
|
18
11
|
},
|
|
19
12
|
browserUrl: {
|
|
20
13
|
type: 'string',
|
|
21
14
|
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/blob/main/docs/advanced-usage.md#connecting-to-a-running-chrome-instance.',
|
|
22
15
|
alias: 'u',
|
|
23
|
-
conflicts: ['wsEndpoint'],
|
|
24
16
|
coerce: (url) => {
|
|
25
17
|
if (!url) {
|
|
26
18
|
return;
|
|
@@ -38,7 +30,6 @@ export const browserOptions = {
|
|
|
38
30
|
type: 'string',
|
|
39
31
|
description: 'WebSocket endpoint to connect to a running Chrome instance (e.g., ws://127.0.0.1:9222/devtools/browser/<id>). Alternative to --browserUrl.',
|
|
40
32
|
alias: 'w',
|
|
41
|
-
conflicts: ['browserUrl'],
|
|
42
33
|
coerce: (url) => {
|
|
43
34
|
if (!url) {
|
|
44
35
|
return;
|
|
@@ -61,7 +52,6 @@ export const browserOptions = {
|
|
|
61
52
|
wsHeaders: {
|
|
62
53
|
type: 'string',
|
|
63
54
|
description: 'Custom headers for WebSocket connection in JSON format (e.g., \'{"Authorization":"Bearer token"}\'). Only works with --wsEndpoint.',
|
|
64
|
-
implies: 'wsEndpoint',
|
|
65
55
|
coerce: (val) => {
|
|
66
56
|
if (!val) {
|
|
67
57
|
return;
|
|
@@ -86,23 +76,22 @@ export const browserOptions = {
|
|
|
86
76
|
executablePath: {
|
|
87
77
|
type: 'string',
|
|
88
78
|
description: 'Path to custom Chrome executable.',
|
|
89
|
-
conflicts: ['browserUrl', 'wsEndpoint'],
|
|
90
79
|
alias: 'e',
|
|
91
80
|
},
|
|
92
81
|
isolated: {
|
|
93
82
|
type: 'boolean',
|
|
94
83
|
description: 'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed. Defaults to false.',
|
|
84
|
+
default: false,
|
|
95
85
|
},
|
|
96
86
|
userDataDir: {
|
|
97
87
|
type: 'string',
|
|
98
88
|
description: 'Path to the user data directory for Chrome. Default is $HOME/.cache/chrome-devtools-mcp/chrome-profile$CHANNEL_SUFFIX_IF_NON_STABLE',
|
|
99
|
-
conflicts: ['browserUrl', 'wsEndpoint', 'isolated'],
|
|
100
89
|
},
|
|
101
90
|
channel: {
|
|
102
91
|
type: 'string',
|
|
103
92
|
description: 'Specify a different Chrome channel that should be used. The default is the stable channel version.',
|
|
104
93
|
choices: ['canary', 'dev', 'beta', 'stable'],
|
|
105
|
-
|
|
94
|
+
default: 'stable',
|
|
106
95
|
},
|
|
107
96
|
proxyServer: {
|
|
108
97
|
type: 'string',
|
|
@@ -5,46 +5,28 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { ToolCategory } from '../tools/categories.js';
|
|
7
7
|
const categoryOverrides = {
|
|
8
|
-
[ToolCategory.INPUT]: {
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
[ToolCategory.
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
[ToolCategory.
|
|
15
|
-
hidden: false,
|
|
16
|
-
},
|
|
17
|
-
[ToolCategory.PERFORMANCE]: {
|
|
18
|
-
hidden: false,
|
|
19
|
-
},
|
|
20
|
-
[ToolCategory.NETWORK]: {
|
|
21
|
-
hidden: false,
|
|
22
|
-
},
|
|
23
|
-
[ToolCategory.DEBUGGING]: {
|
|
24
|
-
hidden: false,
|
|
25
|
-
},
|
|
26
|
-
[ToolCategory.MEMORY]: {
|
|
27
|
-
hidden: false,
|
|
28
|
-
},
|
|
8
|
+
[ToolCategory.INPUT]: {},
|
|
9
|
+
[ToolCategory.NAVIGATION]: {},
|
|
10
|
+
[ToolCategory.EMULATION]: {},
|
|
11
|
+
[ToolCategory.PERFORMANCE]: {},
|
|
12
|
+
[ToolCategory.NETWORK]: {},
|
|
13
|
+
[ToolCategory.DEBUGGING]: {},
|
|
14
|
+
[ToolCategory.MEMORY]: {},
|
|
29
15
|
[ToolCategory.WEBMCP]: {
|
|
30
|
-
describe: 'Set to true to enable debugging
|
|
16
|
+
describe: 'Set to true to enable WebMCP tools (excluding debugging tools, which are exposed under the third-party developer tools category). Requires Chrome 150+ with the following flag: `--enable-features=WebMCP`',
|
|
31
17
|
offByDefault: true,
|
|
32
|
-
hidden: false,
|
|
33
18
|
},
|
|
34
19
|
[ToolCategory.EXTENSIONS]: {
|
|
35
|
-
describe: 'Set to true to include tools related to extensions.
|
|
36
|
-
hidden: false,
|
|
20
|
+
describe: 'Set to true to include tools related to extensions.',
|
|
37
21
|
offByDefault: true,
|
|
22
|
+
reloadable: false,
|
|
38
23
|
},
|
|
39
24
|
[ToolCategory.THIRD_PARTY]: {
|
|
40
|
-
describe: 'Set to true to enable third-party developer tools exposed by the inspected page itself',
|
|
41
|
-
hidden: false,
|
|
25
|
+
describe: 'Set to true to enable third-party developer tools exposed by the inspected page itself (via WebMCP or devtoolstooldiscovery)',
|
|
42
26
|
offByDefault: true,
|
|
43
27
|
},
|
|
44
28
|
[ToolCategory.PWA]: {
|
|
45
29
|
describe: 'Set to true to include tools for automating Progressive Web Apps (install, launch, uninstall, and OS state). This feature is only supported with a pipe connection; autoConnect, browserUrl, and wsEndpoint are not supported.',
|
|
46
|
-
conflicts: ['autoConnect', 'browserUrl', 'wsEndpoint'],
|
|
47
|
-
hidden: false,
|
|
48
30
|
offByDefault: true,
|
|
49
31
|
},
|
|
50
32
|
};
|
|
@@ -56,8 +38,11 @@ function createOption(category) {
|
|
|
56
38
|
return {
|
|
57
39
|
type: 'boolean',
|
|
58
40
|
describe,
|
|
59
|
-
|
|
41
|
+
reloadable: true,
|
|
60
42
|
...overrides,
|
|
43
|
+
// Off-by-default categories have no default so that they stay unset unless
|
|
44
|
+
// passed explicitly. This keeps them out of conflict checks and lets
|
|
45
|
+
// --viaCli apply its own categoryExtensions default.
|
|
61
46
|
...(overrides.offByDefault ? {} : { default: true }),
|
|
62
47
|
};
|
|
63
48
|
}
|
|
@@ -6,21 +6,181 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* Builds the yargs command string and usage line for a CLI command.
|
|
8
8
|
*
|
|
9
|
-
* Optional args are rendered as `[--flag]` in the usage line only: as
|
|
10
|
-
* the command string yargs parses each one as a trailing positional,
|
|
11
|
-
* variadic positional has to be the last one.
|
|
9
|
+
* Optional flag args are rendered as `[--flag]` in the usage line only: as
|
|
10
|
+
* part of the command string yargs parses each one as a trailing positional,
|
|
11
|
+
* and a variadic positional has to be the last one. Which args are positional
|
|
12
|
+
* is decided at build time by `scripts/generate-cli.ts`.
|
|
12
13
|
*/
|
|
13
14
|
export function buildCommand(commandName, args) {
|
|
14
15
|
let command = commandName;
|
|
15
16
|
let flags = '';
|
|
16
17
|
for (const [name, arg] of Object.entries(args)) {
|
|
17
|
-
if (arg.
|
|
18
|
+
if (!arg.positional) {
|
|
19
|
+
flags += ` [--${name}]`;
|
|
20
|
+
}
|
|
21
|
+
else if (arg.required) {
|
|
18
22
|
command += arg.type === 'array' ? ` <${name}..>` : ` <${name}>`;
|
|
19
23
|
}
|
|
20
24
|
else {
|
|
21
|
-
|
|
25
|
+
command += arg.type === 'array' ? ` [${name}..]` : ` [${name}]`;
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
return { command, usage: `$0 ${command}${flags}` };
|
|
25
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Options that are available on every tool command and are consumed by yargs
|
|
32
|
+
* rather than forwarded to the tool.
|
|
33
|
+
*/
|
|
34
|
+
export const GLOBAL_CLI_OPTIONS = new Map([
|
|
35
|
+
['sessionId', 'value'],
|
|
36
|
+
['outputFormat', 'value'],
|
|
37
|
+
['help', 'boolean'],
|
|
38
|
+
['version', 'boolean'],
|
|
39
|
+
]);
|
|
40
|
+
/**
|
|
41
|
+
* Builds a `CommandArgSpec` for a tool command from its generated arg
|
|
42
|
+
* definitions and the options available on every command.
|
|
43
|
+
*/
|
|
44
|
+
export function getCommandArgSpec(args, globalOptions = GLOBAL_CLI_OPTIONS) {
|
|
45
|
+
const options = new Map(globalOptions);
|
|
46
|
+
let positionalCount = 0;
|
|
47
|
+
let variadic = false;
|
|
48
|
+
for (const [name, arg] of Object.entries(args)) {
|
|
49
|
+
if (arg.positional) {
|
|
50
|
+
positionalCount++;
|
|
51
|
+
variadic = arg.type === 'array';
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
options.set(name, toOptionKind(arg.type));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { options, positionalCount, variadic };
|
|
58
|
+
}
|
|
59
|
+
export function toOptionKind(type) {
|
|
60
|
+
if (type === 'boolean') {
|
|
61
|
+
return 'boolean';
|
|
62
|
+
}
|
|
63
|
+
if (type === 'array') {
|
|
64
|
+
return 'array';
|
|
65
|
+
}
|
|
66
|
+
return 'value';
|
|
67
|
+
}
|
|
68
|
+
const LITERAL_ARG_PREFIX = '\0literal:';
|
|
69
|
+
// Mirrors yargs-parser's negative number detection.
|
|
70
|
+
const NEGATIVE_NUMBER = /^-\d+(\.\d*)?(e-?\d+)?$/;
|
|
71
|
+
function optionName(token) {
|
|
72
|
+
let name = token.replace(/^-+/, '');
|
|
73
|
+
const eq = name.indexOf('=');
|
|
74
|
+
if (eq !== -1) {
|
|
75
|
+
name = name.slice(0, eq);
|
|
76
|
+
}
|
|
77
|
+
if (name.startsWith('no-')) {
|
|
78
|
+
name = name.slice(3);
|
|
79
|
+
}
|
|
80
|
+
return name.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Shields positional values that yargs cannot carry through its parsing.
|
|
84
|
+
*
|
|
85
|
+
* yargs re-parses command positionals as `--name value` pairs, and in that
|
|
86
|
+
* pass yargs-parser treats any value starting with `-` (other than a negative
|
|
87
|
+
* number) as the next flag, replacing the value with `''`. It also never fills
|
|
88
|
+
* positionals from the tokens after `--`. See
|
|
89
|
+
* https://github.com/yargs/yargs/issues/1312 and
|
|
90
|
+
* https://github.com/yargs/yargs/issues/1821.
|
|
91
|
+
*
|
|
92
|
+
* Shielded tokens are replaced by opaque placeholders that `restore` maps back
|
|
93
|
+
* to the original values. A token is shielded when:
|
|
94
|
+
*
|
|
95
|
+
* - it is a lone `-`, which can never be an option;
|
|
96
|
+
* - it follows the first `--`, which is dropped so the tokens populate
|
|
97
|
+
* positionals;
|
|
98
|
+
* - it starts with `-`, is not a known option of the command, and the command
|
|
99
|
+
* still has an unfilled positional. Known options and their values are
|
|
100
|
+
* skipped the way yargs consumes them, so a dash-prefixed value such as
|
|
101
|
+
* `--flag` in a positional slot is passed through as text, while an unknown
|
|
102
|
+
* flag after all positionals are filled is still rejected by yargs.
|
|
103
|
+
*
|
|
104
|
+
* `getSpec` resolves the spec of a command by name and returns `undefined`
|
|
105
|
+
* for tokens that are not a command.
|
|
106
|
+
*/
|
|
107
|
+
export function shieldLiteralArgs(argv, getSpec) {
|
|
108
|
+
const literals = new Map();
|
|
109
|
+
const result = [];
|
|
110
|
+
const shield = (token) => {
|
|
111
|
+
const placeholder = `${LITERAL_ARG_PREFIX}${literals.size}`;
|
|
112
|
+
literals.set(placeholder, token);
|
|
113
|
+
result.push(placeholder);
|
|
114
|
+
};
|
|
115
|
+
let spec;
|
|
116
|
+
let filled = 0;
|
|
117
|
+
let afterDoubleDash = false;
|
|
118
|
+
for (let i = 0; i < argv.length; i++) {
|
|
119
|
+
const token = argv[i];
|
|
120
|
+
if (afterDoubleDash) {
|
|
121
|
+
shield(token);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (token === '--') {
|
|
125
|
+
afterDoubleDash = true;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (token === '-') {
|
|
129
|
+
shield(token);
|
|
130
|
+
filled++;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (!token.startsWith('-') || NEGATIVE_NUMBER.test(token)) {
|
|
134
|
+
result.push(token);
|
|
135
|
+
if (!spec) {
|
|
136
|
+
spec = getSpec(token);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
filled++;
|
|
140
|
+
}
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const kind = spec?.options.get(optionName(token));
|
|
144
|
+
if (kind !== undefined) {
|
|
145
|
+
result.push(token);
|
|
146
|
+
if (token.includes('=')) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (kind === 'boolean') {
|
|
150
|
+
if (/^(true|false)$/.test(argv[i + 1] ?? '')) {
|
|
151
|
+
result.push(argv[++i]);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else if (kind === 'array') {
|
|
155
|
+
while (i + 1 < argv.length && !argv[i + 1].startsWith('-')) {
|
|
156
|
+
result.push(argv[++i]);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if (i + 1 < argv.length) {
|
|
160
|
+
result.push(argv[++i]);
|
|
161
|
+
}
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const hasUnfilledPositional = spec !== undefined &&
|
|
165
|
+
(filled < spec.positionalCount ||
|
|
166
|
+
(spec.variadic && spec.positionalCount > 0));
|
|
167
|
+
if (hasUnfilledPositional) {
|
|
168
|
+
shield(token);
|
|
169
|
+
filled++;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
result.push(token);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const restore = (value) => {
|
|
176
|
+
if (typeof value === 'string') {
|
|
177
|
+
return literals.get(value) ?? value;
|
|
178
|
+
}
|
|
179
|
+
if (Array.isArray(value)) {
|
|
180
|
+
return value.map(restore);
|
|
181
|
+
}
|
|
182
|
+
return value;
|
|
183
|
+
};
|
|
184
|
+
return { argv: result, restore };
|
|
185
|
+
}
|
|
26
186
|
//# sourceMappingURL=cli-commands.js.map
|