chrome-devtools-mcp 1.8.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.
Files changed (35) hide show
  1. package/README.md +20 -908
  2. package/build/src/McpContext.js +38 -21
  3. package/build/src/McpPage.js +5 -1
  4. package/build/src/ToolHandler.js +15 -45
  5. package/build/src/bin/chrome-devtools-mcp-main.js +2 -2
  6. package/build/src/browser.js +5 -16
  7. package/build/src/config/browser-options.js +123 -0
  8. package/build/src/config/category-options.js +80 -0
  9. package/build/src/config/cli-options.js +2 -2
  10. package/build/src/config/mcp-options.js +46 -146
  11. package/build/src/daemon/utils.js +6 -0
  12. package/build/src/devtools/DevtoolsUtils.js +27 -21
  13. package/build/src/formatters/NetworkFormatter.js +5 -2
  14. package/build/src/index.js +168 -102
  15. package/build/src/telemetry/ClearcutLogger.js +5 -4
  16. package/build/src/third_party/THIRD_PARTY_NOTICES +5 -5
  17. package/build/src/third_party/bundled-packages.json +2 -2
  18. package/build/src/third_party/devtools-formatter-worker.js +22 -0
  19. package/build/src/third_party/devtools-heap-snapshot-worker.js +22 -0
  20. package/build/src/third_party/index.js +4467 -2755
  21. package/build/src/tools/ToolDefinition.js +15 -0
  22. package/build/src/tools/categories.js +0 -6
  23. package/build/src/tools/network.js +1 -1
  24. package/build/src/tools/pages.js +22 -7
  25. package/build/src/tools/performance.js +1 -0
  26. package/build/src/tools/screencast.js +1 -0
  27. package/build/src/tools/script.js +1 -0
  28. package/build/src/tools/slim/tools.js +41 -33
  29. package/build/src/utils/WaitForHelper.js +12 -1
  30. package/build/src/utils/url.js +73 -0
  31. package/build/src/version.js +1 -1
  32. package/package.json +4 -4
  33. package/skills/chrome-devtools-cli/SKILL.md +1 -7
  34. package/skills/cookie-debugging/SKILL.md +149 -0
  35. package/skills/memory-leak-debugging/SKILL.md +4 -0
@@ -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
+ 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';
7
11
  export const mcpOptions = {
8
- autoConnect: {
9
- type: 'boolean',
10
- 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.',
11
- conflicts: ['isolated', 'executablePath'],
12
- default: false,
13
- coerce: (value) => {
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
- },
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,10 +32,6 @@ export const mcpOptions = {
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.`,
@@ -187,13 +89,19 @@ export const mcpOptions = {
187
89
  describe: 'Path to ffmpeg executable for screencast recording.',
188
90
  implies: 'experimentalScreencast',
189
91
  },
190
- categoryExperimentalWebmcp: {
191
- type: 'boolean',
192
- describe: 'Set to true to enable debugging WebMCP tools. Requires Chrome 150+ with the following flag: `--enable-features=WebMCP`',
193
- },
194
- chromeArg: {
195
- type: 'array',
196
- describe: 'Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
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
+ },
197
105
  },
198
106
  blockedUrlPattern: {
199
107
  type: 'array',
@@ -205,51 +113,25 @@ export const mcpOptions = {
205
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.",
206
114
  conflicts: ['blockedUrlPattern'],
207
115
  },
208
- ignoreDefaultChromeArg: {
209
- type: 'array',
210
- describe: 'Explicitly disable default arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
211
- },
212
- categoryEmulation: {
213
- type: 'boolean',
214
- default: true,
215
- describe: 'Set to false to exclude tools related to emulation.',
216
- },
217
- categoryPerformance: {
116
+ performanceCrux: {
218
117
  type: 'boolean',
219
118
  default: true,
220
- describe: 'Set to false to exclude tools related to performance.',
119
+ describe: 'Set to false to disable sending URLs from performance traces to CrUX API to get field performance data.',
221
120
  },
222
- categoryNetwork: {
121
+ usageStatistics: {
223
122
  type: 'boolean',
224
123
  default: true,
225
- describe: 'Set to false to exclude tools related to network.',
226
- },
227
- categoryExtensions: {
228
- type: 'boolean',
229
- hidden: false,
230
- default: false,
231
- 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.',
232
- },
233
- categoryExperimentalThirdParty: {
234
- type: 'boolean',
235
- default: false,
236
- describe: 'Set to true to enable third-party developer tools exposed by the inspected page itself',
237
- },
238
- categoryPwa: {
239
- type: 'boolean',
240
- hidden: false,
241
- conflicts: ['autoConnect', 'browserUrl', 'wsEndpoint'],
242
- 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.',
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.',
243
125
  },
244
- performanceCrux: {
126
+ javascriptEvaluation: {
245
127
  type: 'boolean',
246
128
  default: true,
247
- describe: 'Set to false to disable sending URLs from performance traces to CrUX API to get field performance data.',
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.',
248
130
  },
249
- usageStatistics: {
131
+ sourceMaps: {
250
132
  type: 'boolean',
251
133
  default: true,
252
- 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.',
134
+ describe: 'Whether to enable source maps in DevTools. Use --no-source-maps to disable.',
253
135
  },
254
136
  clearcutEndpoint: {
255
137
  type: 'string',
@@ -268,7 +150,7 @@ export const mcpOptions = {
268
150
  },
269
151
  screenshotFormat: {
270
152
  type: 'string',
271
- 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 helps reduce context size in AI conversations. Unset preserves the existing default ("png").',
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").',
272
154
  choices: ['jpeg', 'png', 'webp'],
273
155
  },
274
156
  screenshotQuality: {
@@ -327,11 +209,19 @@ export const mcpOptions = {
327
209
  allowUnrestrictedPaths: {
328
210
  type: 'boolean',
329
211
  default: false,
212
+ deprecated: 'Use --workspace=/ instead.',
330
213
  describe: 'If set, disables the default path restriction that applies when the MCP client does not negotiate ' +
331
214
  'the roots capability. By default, file-writing tools are restricted to the OS temp directory when ' +
332
215
  'no roots are configured. Use this only when connecting a trusted local client that does not implement ' +
333
216
  'MCP roots and requires access to paths outside the temp directory.',
334
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
+ },
335
225
  };
336
226
  export function getMcpOptionsForViaCli() {
337
227
  if (!('default' in mcpOptions.headless)) {
@@ -382,6 +272,11 @@ export function parser(version, argv = process.argv, env = process.env) {
382
272
  .options(options)
383
273
  .showHelpOnFail(false, 'Specify --help for available options')
384
274
  .middleware(args => {
275
+ if (isViaCli && args.filesystemRoot === DEFAULT_FILESYSTEM_ROOT) {
276
+ const cliFilesystemArgs = args;
277
+ cliFilesystemArgs.allowUnrestrictedPaths = true;
278
+ cliFilesystemArgs.filesystemRoot = undefined;
279
+ }
385
280
  // We can't set default in the options else
386
281
  // Yargs will complain
387
282
  if (!args.channel &&
@@ -462,6 +357,11 @@ export function parser(version, argv = process.argv, env = process.env) {
462
357
  '$0 --no-performance-crux',
463
358
  'Disable CrUX (field data) integration in performance tools.',
464
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
+ ],
465
365
  [
466
366
  '$0 --slim',
467
367
  'Only 3 tools: navigation, JavaScript execution and screenshot',
@@ -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
- return Promise.resolve({
71
- getError: () => undefined,
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,6 +106,11 @@ 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);
110
116
  const skipAllPausesSetting = universe.settings.resolve(DevTools.skipAllPausesSettingDescriptor);
@@ -6,6 +6,7 @@
6
6
  import { isUtf8 } from 'node:buffer';
7
7
  import { DevTools, } from '../third_party/index.js';
8
8
  const BODY_CONTEXT_SIZE_LIMIT = 10000;
9
+ const URL_CONTEXT_SIZE_LIMIT = 255;
9
10
  export class NetworkFormatter {
10
11
  #request;
11
12
  #options;
@@ -178,8 +179,10 @@ function getSizeLimitedString(text, sizeLimit) {
178
179
  return text;
179
180
  }
180
181
  function convertNetworkRequestConciseToString(data) {
181
- // TODO truncate the URL
182
- return `reqid=${data.requestId} ${data.method} ${data.url} [${data.status}]${data.selectedInDevToolsUI ? ` [selected in the DevTools Network panel]` : ''}`;
182
+ // Long URLs (e.g., data: URLs) bloat the concise list output. The full URL
183
+ // remains available via the detailed view and the structured content.
184
+ const url = getSizeLimitedString(data.url, URL_CONTEXT_SIZE_LIMIT);
185
+ return `reqid=${data.requestId} ${data.method} ${url} [${data.status}]${data.selectedInDevToolsUI ? ` [selected in the DevTools Network panel]` : ''}`;
183
186
  }
184
187
  function formatHeaders(headers) {
185
188
  const response = [];