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
@@ -15,6 +15,7 @@ import { Locator, } from './third_party/index.js';
15
15
  import { listPages } from './tools/pages.js';
16
16
  import { CLOSE_PAGE_ERROR } from './tools/ToolDefinition.js';
17
17
  import { getTempFilePath, resolveCanonicalPath } from './utils/files.js';
18
+ import { isAllowedUrl } from './utils/url.js';
18
19
  // Page ids are handed out from a process-wide counter so they stay unique
19
20
  // across all contexts, in particular across browser reconnects. An id issued
20
21
  // before a reconnect then fails to resolve instead of hitting an unrelated
@@ -81,6 +82,12 @@ export class McpContext {
81
82
  }
82
83
  #onTargetCreated = async (target) => {
83
84
  try {
85
+ const url = target.url();
86
+ if (!isAllowedUrl(url, {
87
+ categoryExtensions: this.#options.categoryExtensions,
88
+ })) {
89
+ return;
90
+ }
84
91
  const page = await target.page();
85
92
  if (!page) {
86
93
  return;
@@ -204,7 +211,7 @@ export class McpContext {
204
211
  ctx = await this.browser.createBrowserContext();
205
212
  this.#isolatedContexts.set(isolatedContextName, ctx);
206
213
  }
207
- page = await ctx.newPage();
214
+ page = await ctx.newPage({ background });
208
215
  }
209
216
  else {
210
217
  page = await this.browser.newPage({ background });
@@ -389,6 +396,7 @@ export class McpContext {
389
396
  hasNetworkBlockOrAllowlist: this.#hasNetworkBlockOrAllowlist,
390
397
  isolatedContextName: this.#getBrowserContextToNameMap().get(page.browserContext()),
391
398
  navigationTimeout: this.#options.navigationTimeout,
399
+ sourceMaps: this.#options.sourceMaps,
392
400
  });
393
401
  this.#mcpPages.set(page, mcpPage);
394
402
  await mcpPage.init();
@@ -426,29 +434,38 @@ export class McpContext {
426
434
  }
427
435
  async #fetchBrowserPages() {
428
436
  const allPages = (await this.browser.pages(this.#options.experimentalIncludeAllPages)).filter(page => {
429
- return (this.#options.experimentalDevToolsDebugging ||
430
- !page.url().startsWith('devtools://'));
431
- });
432
- const allTargets = this.browser.targets();
433
- const extensionTargets = allTargets.filter(target => {
434
- return (target.url().startsWith('chrome-extension://') &&
435
- target.type() === 'page');
437
+ if (!this.#options.experimentalDevToolsDebugging &&
438
+ page.url().startsWith('devtools://')) {
439
+ return false;
440
+ }
441
+ return isAllowedUrl(page.url(), {
442
+ categoryExtensions: this.#options.categoryExtensions,
443
+ });
436
444
  });
437
- await Promise.allSettled(extensionTargets.map(async (target) => {
438
- try {
439
- let page = await target.page();
440
- if (!page) {
441
- page = await target.asPage();
445
+ if (this.#options.categoryExtensions) {
446
+ const allTargets = this.browser.targets();
447
+ const extensionTargets = allTargets.filter(target => {
448
+ return (target.url().startsWith('chrome-extension://') &&
449
+ target.type() === 'page');
450
+ });
451
+ await Promise.allSettled(extensionTargets.map(async (target) => {
452
+ try {
453
+ let page = await target.page();
454
+ if (!page) {
455
+ page = await target.asPage();
456
+ }
457
+ this.#extensionPages.set(target, page);
458
+ if (page &&
459
+ isAllowedUrl(page.url(), { categoryExtensions: true }) &&
460
+ !allPages.includes(page)) {
461
+ allPages.push(page);
462
+ }
442
463
  }
443
- this.#extensionPages.set(target, page);
444
- if (page && !allPages.includes(page)) {
445
- allPages.push(page);
464
+ catch (e) {
465
+ this.logger?.('Failed to get page for extension target', e);
446
466
  }
447
- }
448
- catch (e) {
449
- this.logger?.('Failed to get page for extension target', e);
450
- }
451
- }));
467
+ }));
468
+ }
452
469
  return allPages;
453
470
  }
454
471
  getExtensionServiceWorkers() {
@@ -139,10 +139,12 @@ export class McpPage {
139
139
  #hasNetworkBlockOrAllowlist;
140
140
  #locatorClass;
141
141
  #navigationTimeout;
142
+ #sourceMaps;
142
143
  constructor(page, id, options) {
143
144
  this.#hasNetworkBlockOrAllowlist = options.hasNetworkBlockOrAllowlist;
144
145
  this.#locatorClass = options.locatorClass;
145
146
  this.#navigationTimeout = options.navigationTimeout ?? NAVIGATION_TIMEOUT;
147
+ this.#sourceMaps = options.sourceMaps ?? true;
146
148
  this.pptrPage = page;
147
149
  this.id = id;
148
150
  this.isolatedContextName = options.isolatedContextName;
@@ -183,7 +185,9 @@ export class McpPage {
183
185
  }
184
186
  try {
185
187
  const session = await this.pptrPage.createCDPSession();
186
- this.#devtoolsUniverse = await createTargetUniverse(session);
188
+ this.#devtoolsUniverse = await createTargetUniverse(session, {
189
+ sourceMaps: this.#sourceMaps,
190
+ });
187
191
  }
188
192
  catch (e) {
189
193
  logger?.('Failed to initialize DevTools universe', e);
@@ -6,65 +6,35 @@
6
6
  import { McpResponse } from './McpResponse.js';
7
7
  import { SlimMcpResponse } from './SlimMcpResponse.js';
8
8
  import { ClearcutLogger } from './telemetry/ClearcutLogger.js';
9
- import { bucketizeLatency, buildContext } from './telemetry/transformation.js';
10
9
  import { zod } from './third_party/index.js';
11
- import { labels, OFF_BY_DEFAULT_CATEGORIES } from './tools/categories.js';
10
+ import { labels } from './tools/categories.js';
11
+ import { categoryToFlagName } from './config/category-options.js';
12
12
  import { pageIdSchema } from './tools/ToolDefinition.js';
13
13
  import { logger } from './utils/logger.js';
14
14
  import { fileURLToPath, pathToFileURL } from 'node:url';
15
15
  import { isLocalhost } from './utils/url.js';
16
- export function buildFlag(category) {
17
- return `category${category.charAt(0).toUpperCase() + category.slice(1)}`;
18
- }
19
16
  function buildDisabledMessage(toolName, flag, categoryLabel) {
20
17
  const reason = categoryLabel
21
18
  ? `is in category ${categoryLabel} which`
22
- : `requires experimental feature ${flag} and`;
19
+ : `requires ${flag.startsWith('--experimental') ? 'experimental feature' : 'flag'} ${flag} and`;
23
20
  return `Tool ${toolName} ${reason} is currently disabled. Enable it by running chrome-devtools start ${flag}=true. For more information check the README.`;
24
21
  }
25
- function getCategoryStatus(category, serverArgs) {
26
- const categoryFlag = buildFlag(category);
27
- const flagValue = serverArgs[categoryFlag];
28
- const isDisabled = OFF_BY_DEFAULT_CATEGORIES.includes(category)
29
- ? !flagValue
30
- : flagValue === false;
31
- if (isDisabled) {
32
- return {
33
- categoryFlag,
34
- disabled: true,
35
- };
36
- }
37
- return {
38
- disabled: false,
39
- };
40
- }
41
- function getConditionStatus(condition, serverArgs) {
42
- if (condition && !serverArgs[condition]) {
43
- return { conditionFlag: condition, disabled: true };
44
- }
45
- return { disabled: false };
46
- }
47
22
  function getToolStatusInfo(tool, serverArgs) {
48
23
  const category = tool.annotations.category;
49
- const categoryCheck = getCategoryStatus(category, serverArgs);
50
- if (category && categoryCheck.disabled) {
51
- if (!categoryCheck.categoryFlag) {
52
- throw new Error('when the category is disabled there should always be a flag set');
24
+ if (category) {
25
+ const flag = categoryToFlagName(category);
26
+ if (!serverArgs[flag]) {
27
+ return {
28
+ disabled: true,
29
+ reason: buildDisabledMessage(tool.name, `--${flag}`, labels[category]),
30
+ };
53
31
  }
54
- return {
55
- disabled: true,
56
- reason: buildDisabledMessage(tool.name, `--${categoryCheck.categoryFlag}`, labels[category]),
57
- };
58
32
  }
59
33
  for (const condition of tool.annotations.conditions || []) {
60
- const conditionCheck = getConditionStatus(condition, serverArgs);
61
- if (conditionCheck.disabled) {
62
- if (!conditionCheck.conditionFlag) {
63
- throw new Error('when the condition is disabled there should always be a flag set');
64
- }
34
+ if (!serverArgs[condition]) {
65
35
  return {
66
36
  disabled: true,
67
- reason: buildDisabledMessage(tool.name, `--${conditionCheck.conditionFlag}`),
37
+ reason: buildDisabledMessage(tool.name, `--${condition}`),
68
38
  };
69
39
  }
70
40
  }
@@ -282,14 +252,14 @@ export class ToolHandler {
282
252
  };
283
253
  }
284
254
  finally {
285
- const context = buildContext(devToolsData, pageUrl);
286
255
  void ClearcutLogger.get()?.logToolInvocation({
287
256
  toolName: this.tool.name,
288
257
  params,
289
258
  schema: this.inputSchema,
290
259
  success,
291
- latencyMs: bucketizeLatency(Date.now() - startTime),
292
- context,
260
+ latencyMs: Date.now() - startTime,
261
+ devToolsData,
262
+ pageUrl,
293
263
  });
294
264
  guard[Symbol.dispose]();
295
265
  }
@@ -6,7 +6,7 @@
6
6
  import '../utils/polyfill.js';
7
7
  import process from 'node:process';
8
8
  import { closeBrowser } from '../browser.js';
9
- import { createMcpServer, logDisclaimers } from '../index.js';
9
+ import { McpServer, logDisclaimers } from '../index.js';
10
10
  import { ClearcutLogger } from '../telemetry/ClearcutLogger.js';
11
11
  import { computeFlagUsage } from '../telemetry/flagUtils.js';
12
12
  import { StdioServerTransport } from '../third_party/index.js';
@@ -60,7 +60,7 @@ process.on('SIGHUP', () => {
60
60
  void shutdown('SIGHUP');
61
61
  });
62
62
  logger?.(`Starting Chrome DevTools MCP Server v${VERSION}`);
63
- const { server } = await createMcpServer(args, {
63
+ const server = await McpServer.from(args, {
64
64
  logFile,
65
65
  });
66
66
  const transport = new StdioServerTransport();
@@ -9,27 +9,16 @@ import os from 'node:os';
9
9
  import path from 'node:path';
10
10
  import { puppeteer } from './third_party/index.js';
11
11
  import { logger, puppeteerLogger } from './utils/logger.js';
12
+ import { isAllowedUrl } from './utils/url.js';
12
13
  let browser;
13
14
  let browserMode;
14
- function makeTargetFilter(enableExtensions = false) {
15
- const ignoredPrefixes = new Set(['chrome://', 'chrome-untrusted://']);
16
- if (!enableExtensions) {
17
- ignoredPrefixes.add('chrome-extension://');
18
- }
15
+ export function makeTargetFilter(enableExtensions = false) {
19
16
  return function targetFilter(target) {
20
- if (target.url() === 'chrome://newtab/') {
21
- return true;
22
- }
23
- // Could be the only page opened in the browser.
24
- if (target.url().startsWith('chrome://inspect')) {
17
+ const url = target.url();
18
+ if (!url) {
25
19
  return true;
26
20
  }
27
- for (const prefix of ignoredPrefixes) {
28
- if (target.url().startsWith(prefix)) {
29
- return false;
30
- }
31
- }
32
- return true;
21
+ return isAllowedUrl(url, { categoryExtensions: enableExtensions });
33
22
  };
34
23
  }
35
24
  export async function ensureBrowserConnected(options) {
@@ -0,0 +1,123 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export const browserOptions = {
7
+ autoConnect: {
8
+ type: 'boolean',
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
+ default: false,
12
+ coerce: (value) => {
13
+ if (!value) {
14
+ return;
15
+ }
16
+ return value;
17
+ },
18
+ },
19
+ browserUrl: {
20
+ type: 'string',
21
+ 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
+ alias: 'u',
23
+ conflicts: ['wsEndpoint'],
24
+ coerce: (url) => {
25
+ if (!url) {
26
+ return;
27
+ }
28
+ try {
29
+ new URL(url);
30
+ }
31
+ catch {
32
+ throw new Error(`Provided browserUrl ${url} is not valid URL.`);
33
+ }
34
+ return url;
35
+ },
36
+ },
37
+ wsEndpoint: {
38
+ type: 'string',
39
+ 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
+ alias: 'w',
41
+ conflicts: ['browserUrl'],
42
+ coerce: (url) => {
43
+ if (!url) {
44
+ return;
45
+ }
46
+ try {
47
+ const parsed = new URL(url);
48
+ if (parsed.protocol !== 'ws:' && parsed.protocol !== 'wss:') {
49
+ throw new Error(`Provided wsEndpoint ${url} must use ws:// or wss:// protocol.`);
50
+ }
51
+ return url;
52
+ }
53
+ catch (error) {
54
+ if (error.message.includes('ws://')) {
55
+ throw error;
56
+ }
57
+ throw new Error(`Provided wsEndpoint ${url} is not valid URL.`);
58
+ }
59
+ },
60
+ },
61
+ wsHeaders: {
62
+ type: 'string',
63
+ description: 'Custom headers for WebSocket connection in JSON format (e.g., \'{"Authorization":"Bearer token"}\'). Only works with --wsEndpoint.',
64
+ implies: 'wsEndpoint',
65
+ coerce: (val) => {
66
+ if (!val) {
67
+ return;
68
+ }
69
+ try {
70
+ const parsed = JSON.parse(val);
71
+ if (typeof parsed !== 'object' || Array.isArray(parsed)) {
72
+ throw new Error('Headers must be a JSON object');
73
+ }
74
+ return parsed;
75
+ }
76
+ catch (error) {
77
+ throw new Error(`Invalid JSON for wsHeaders: ${error.message}`);
78
+ }
79
+ },
80
+ },
81
+ headless: {
82
+ type: 'boolean',
83
+ description: 'Whether to run in headless (no UI) mode.',
84
+ default: false,
85
+ },
86
+ executablePath: {
87
+ type: 'string',
88
+ description: 'Path to custom Chrome executable.',
89
+ conflicts: ['browserUrl', 'wsEndpoint'],
90
+ alias: 'e',
91
+ },
92
+ isolated: {
93
+ type: 'boolean',
94
+ description: 'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed. Defaults to false.',
95
+ },
96
+ userDataDir: {
97
+ type: 'string',
98
+ 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
+ },
101
+ channel: {
102
+ type: 'string',
103
+ description: 'Specify a different Chrome channel that should be used. The default is the stable channel version.',
104
+ choices: ['canary', 'dev', 'beta', 'stable'],
105
+ conflicts: ['browserUrl', 'wsEndpoint', 'executablePath'],
106
+ },
107
+ proxyServer: {
108
+ type: 'string',
109
+ 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.`,
110
+ },
111
+ chromeArg: {
112
+ type: 'array',
113
+ describe: 'Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
114
+ },
115
+ ignoreDefaultChromeArg: {
116
+ type: 'array',
117
+ describe: 'Explicitly disable default arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
118
+ },
119
+ };
120
+ export function getBrowserOptions() {
121
+ return browserOptions;
122
+ }
123
+ //# sourceMappingURL=browser-options.js.map
@@ -0,0 +1,80 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { ToolCategory } from '../tools/categories.js';
7
+ const categoryOverrides = {
8
+ [ToolCategory.INPUT]: {},
9
+ [ToolCategory.NAVIGATION]: {},
10
+ [ToolCategory.EMULATION]: {
11
+ hidden: false,
12
+ },
13
+ [ToolCategory.PERFORMANCE]: {
14
+ hidden: false,
15
+ },
16
+ [ToolCategory.NETWORK]: {
17
+ hidden: false,
18
+ },
19
+ [ToolCategory.DEBUGGING]: {},
20
+ [ToolCategory.MEMORY]: {},
21
+ [ToolCategory.WEBMCP]: {
22
+ describe: 'Set to true to enable debugging WebMCP tools. Requires Chrome 150+ with the following flag: `--enable-features=WebMCP`',
23
+ offByDefault: true,
24
+ },
25
+ [ToolCategory.EXTENSIONS]: {
26
+ 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.',
27
+ hidden: false,
28
+ offByDefault: true,
29
+ },
30
+ [ToolCategory.THIRD_PARTY]: {
31
+ describe: 'Set to true to enable third-party developer tools exposed by the inspected page itself',
32
+ hidden: false,
33
+ offByDefault: true,
34
+ },
35
+ [ToolCategory.PWA]: {
36
+ 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.',
37
+ conflicts: ['autoConnect', 'browserUrl', 'wsEndpoint'],
38
+ hidden: false,
39
+ offByDefault: true,
40
+ },
41
+ };
42
+ function createOption(category) {
43
+ const overrides = categoryOverrides[category];
44
+ const describe = overrides.offByDefault
45
+ ? `Set to true to include tools related to ${category}.`
46
+ : `Set to false to exclude tools related to ${category}.`;
47
+ return {
48
+ type: 'boolean',
49
+ describe,
50
+ hidden: true,
51
+ ...overrides,
52
+ ...(overrides.offByDefault ? {} : { default: true }),
53
+ };
54
+ }
55
+ export function categoryToFlagName(category) {
56
+ return `category${category.charAt(0).toUpperCase()}${category.slice(1)}`;
57
+ }
58
+ export function getCategoryOptions() {
59
+ const options = {};
60
+ for (const category of Object.values(ToolCategory)) {
61
+ const flagName = categoryToFlagName(category);
62
+ options[flagName] = createOption(category);
63
+ }
64
+ return options;
65
+ }
66
+ export function isCategoryOffByDefault(category) {
67
+ const flagName = categoryToFlagName(category);
68
+ const option = getCategoryOptions()[flagName];
69
+ return !('default' in option) || option.default !== true;
70
+ }
71
+ export function getOffByDefaultCategories() {
72
+ const result = [];
73
+ for (const category of Object.values(ToolCategory)) {
74
+ if (isCategoryOffByDefault(category)) {
75
+ result.push(category);
76
+ }
77
+ }
78
+ return result;
79
+ }
80
+ //# sourceMappingURL=category-options.js.map
@@ -632,7 +632,7 @@ export const commands = {
632
632
  },
633
633
  },
634
634
  get_network_request: {
635
- description: 'Gets a network request by an optional reqid, if omitted returns the currently selected request in the DevTools Network panel.',
635
+ description: "Gets a network request by an optional reqid, if omitted returns the currently selected request in the DevTools Network panel. Useful for inspecting request headers (including 'Cookie') and response headers (including 'Set-Cookie' and directives).",
636
636
  category: 'Network',
637
637
  args: {
638
638
  pageId: {
@@ -1001,7 +1001,7 @@ export const commands = {
1001
1001
  isolatedContext: {
1002
1002
  name: 'isolatedContext',
1003
1003
  type: 'string',
1004
- description: 'If specified, the page is created in an isolated browser context with the given name. Pages in the same browser context share cookies and storage. Pages in different browser contexts are fully isolated.',
1004
+ description: 'If specified, the page is created in an isolated browser context with the given name. Pages in the same browser context share cookies and storage. Pages in different browser contexts are fully isolated (useful for clean-slate testing of cookies and authentication).',
1005
1005
  required: false,
1006
1006
  },
1007
1007
  timeout: {