chrome-devtools-mcp 0.7.0 → 0.8.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 CHANGED
@@ -291,6 +291,10 @@ The Chrome DevTools MCP server supports the following configuration option:
291
291
  If enabled, ignores errors relative to self-signed and expired certificates. Use with caution.
292
292
  - **Type:** boolean
293
293
 
294
+ - **`--chromeArg`**
295
+ Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.
296
+ - **Type:** array
297
+
294
298
  <!-- END AUTO GENERATED OPTIONS -->
295
299
 
296
300
  Pass them via the `args` property in the JSON configuration. For example:
@@ -328,6 +332,69 @@ all instances of `chrome-devtools-mcp`. Set the `isolated` option to `true`
328
332
  to use a temporary user data dir instead which will be cleared automatically after
329
333
  the browser is closed.
330
334
 
335
+ ### Connecting to a running Chrome instance
336
+
337
+ You can connect to a running Chrome instance by using the `--browser-url` option. This is useful if you want to use your existing Chrome profile or if you are running the MCP server in a sandboxed environment that does not allow starting a new Chrome instance.
338
+
339
+ Here is a step-by-step guide on how to connect to a running Chrome Stable instance:
340
+
341
+ **Step 1: Configure the MCP client**
342
+
343
+ Add the `--browser-url` option to your MCP client configuration. The value of this option should be the URL of the running Chrome instance. `http://localhost:9222` is a common default.
344
+
345
+ ```json
346
+ {
347
+ "mcpServers": {
348
+ "chrome-devtools": {
349
+ "command": "npx",
350
+ "args": [
351
+ "chrome-devtools-mcp@latest",
352
+ "--browser-url=http://localhost:9222"
353
+ ]
354
+ }
355
+ }
356
+ }
357
+ ```
358
+
359
+ **Step 2: Start the Chrome browser**
360
+
361
+ > [!WARNING]
362
+ > Enabling the remote debugging port opens up a debugging port on the running browser instance. Any application on your machine can connect to this port and control the browser. Make sure that you are not browsing any sensitive websites while the debugging port is open.
363
+
364
+ Start the Chrome browser with the remote debugging port enabled. Make sure to close any running Chrome instances before starting a new one with the debugging port enabled. The port number you choose must be the same as the one you specified in the `--browser-url` option in your MCP client configuration.
365
+
366
+ For security reasons, [Chrome requires you to use a non-default user data directory](https://developer.chrome.com/blog/remote-debugging-port) when enabling the remote debugging port. You can specify a custom directory using the `--user-data-dir` flag. This ensures that your regular browsing profile and data are not exposed to the debugging session.
367
+
368
+ **macOS**
369
+
370
+ ```bash
371
+ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-profile-stable
372
+ ```
373
+
374
+ **Linux**
375
+
376
+ ```bash
377
+ /usr/bin/google-chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-profile-stable
378
+ ```
379
+
380
+ **Windows**
381
+
382
+ ```bash
383
+ "C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 --user-data-dir="%TEMP%\chrome-profile-stable"
384
+ ```
385
+
386
+ **Step 3: Test your setup**
387
+
388
+ After configuring the MCP client and starting the Chrome browser, you can test your setup by running a simple prompt in your MCP client:
389
+
390
+ ```
391
+ Check the performance of https://developers.chrome.com
392
+ ```
393
+
394
+ Your MCP client should connect to the running Chrome instance and receive a performance report.
395
+
396
+ For more details on remote debugging, see the [Chrome DevTools documentation](https://developer.chrome.com/docs/devtools/remote-debugging/).
397
+
331
398
  ## Known limitations
332
399
 
333
400
  ### Operating system sandboxes
@@ -8,39 +8,41 @@ import os from 'node:os';
8
8
  import path from 'node:path';
9
9
  import puppeteer from 'puppeteer-core';
10
10
  let browser;
11
- const ignoredPrefixes = new Set([
12
- 'chrome://',
13
- 'chrome-extension://',
14
- 'chrome-untrusted://',
15
- 'devtools://',
16
- ]);
17
- function targetFilter(target) {
18
- if (target.url() === 'chrome://newtab/') {
19
- return true;
11
+ function makeTargetFilter(devtools) {
12
+ const ignoredPrefixes = new Set([
13
+ 'chrome://',
14
+ 'chrome-extension://',
15
+ 'chrome-untrusted://',
16
+ ]);
17
+ if (!devtools) {
18
+ ignoredPrefixes.add('devtools://');
20
19
  }
21
- for (const prefix of ignoredPrefixes) {
22
- if (target.url().startsWith(prefix)) {
23
- return false;
20
+ return function targetFilter(target) {
21
+ if (target.url() === 'chrome://newtab/') {
22
+ return true;
24
23
  }
25
- }
26
- return true;
24
+ for (const prefix of ignoredPrefixes) {
25
+ if (target.url().startsWith(prefix)) {
26
+ return false;
27
+ }
28
+ }
29
+ return true;
30
+ };
27
31
  }
28
- const connectOptions = {
29
- targetFilter,
30
- };
31
- export async function ensureBrowserConnected(browserURL) {
32
+ export async function ensureBrowserConnected(options) {
32
33
  if (browser?.connected) {
33
34
  return browser;
34
35
  }
35
36
  browser = await puppeteer.connect({
36
- ...connectOptions,
37
- browserURL,
37
+ targetFilter: makeTargetFilter(options.devtools),
38
+ browserURL: options.browserURL,
38
39
  defaultViewport: null,
40
+ handleDevToolsAsPage: options.devtools,
39
41
  });
40
42
  return browser;
41
43
  }
42
44
  export async function launch(options) {
43
- const { channel, executablePath, customDevTools, headless, isolated } = options;
45
+ const { channel, executablePath, headless, isolated } = options;
44
46
  const profileDirName = channel && channel !== 'stable'
45
47
  ? `chrome-profile-${channel}`
46
48
  : 'chrome-profile';
@@ -55,13 +57,13 @@ export async function launch(options) {
55
57
  ...(options.args ?? []),
56
58
  '--hide-crash-restore-bubble',
57
59
  ];
58
- if (customDevTools) {
59
- args.push(`--custom-devtools-frontend=file://${customDevTools}`);
60
- }
61
60
  if (headless) {
62
61
  args.push('--screen-info={3840x2160}');
63
62
  }
64
63
  let puppeteerChannel;
64
+ if (options.devtools) {
65
+ args.push('--auto-open-devtools-for-tabs');
66
+ }
65
67
  if (!executablePath) {
66
68
  puppeteerChannel =
67
69
  channel && channel !== 'stable'
@@ -70,8 +72,8 @@ export async function launch(options) {
70
72
  }
71
73
  try {
72
74
  const browser = await puppeteer.launch({
73
- ...connectOptions,
74
75
  channel: puppeteerChannel,
76
+ targetFilter: makeTargetFilter(options.devtools),
75
77
  executablePath,
76
78
  defaultViewport: null,
77
79
  userDataDir,
@@ -79,6 +81,7 @@ export async function launch(options) {
79
81
  headless,
80
82
  args,
81
83
  acceptInsecureCerts: options.acceptInsecureCerts,
84
+ handleDevToolsAsPage: options.devtools,
82
85
  });
83
86
  if (options.logFile) {
84
87
  // FIXME: we are probably subscribing too late to catch startup logs. We
package/build/src/cli.js CHANGED
@@ -39,13 +39,6 @@ export const cliOptions = {
39
39
  description: 'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed.',
40
40
  default: false,
41
41
  },
42
- customDevtools: {
43
- type: 'string',
44
- description: 'Path to custom DevTools.',
45
- hidden: true,
46
- conflicts: 'browserUrl',
47
- alias: 'd',
48
- },
49
42
  channel: {
50
43
  type: 'string',
51
44
  description: 'Specify a different Chrome channel that should be used. The default is the stable channel version.',
@@ -81,6 +74,15 @@ export const cliOptions = {
81
74
  type: 'boolean',
82
75
  description: `If enabled, ignores errors relative to self-signed and expired certificates. Use with caution.`,
83
76
  },
77
+ experimentalDevtools: {
78
+ type: 'boolean',
79
+ describe: 'Whether to enable automation over DevTools targets',
80
+ hidden: true,
81
+ },
82
+ chromeArg: {
83
+ type: 'array',
84
+ describe: 'Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
85
+ },
84
86
  };
85
87
  export function parseArguments(version, argv = process.argv) {
86
88
  const yargsInstance = yargs(hideBin(argv))
@@ -109,6 +111,10 @@ export function parseArguments(version, argv = process.argv) {
109
111
  '$0 --viewport 1280x720',
110
112
  'Launch Chrome with the initial viewport size of 1280x720px',
111
113
  ],
114
+ [
115
+ `$0 --chrome-arg='--no-sandbox' --chrome-arg='--disable-setuid-sandbox'`,
116
+ 'Launch Chrome without sandboxes. Use with caution.',
117
+ ],
112
118
  ]);
113
119
  return yargsInstance
114
120
  .wrap(Math.min(120, yargsInstance.terminalWidth()))
package/build/src/main.js CHANGED
@@ -54,22 +54,26 @@ server.server.setRequestHandler(SetLevelRequestSchema, () => {
54
54
  });
55
55
  let context;
56
56
  async function getContext() {
57
- const extraArgs = [];
57
+ const extraArgs = (args.chromeArg ?? []).map(String);
58
58
  if (args.proxyServer) {
59
59
  extraArgs.push(`--proxy-server=${args.proxyServer}`);
60
60
  }
61
+ const devtools = args.experimentalDevtools ?? false;
61
62
  const browser = args.browserUrl
62
- ? await ensureBrowserConnected(args.browserUrl)
63
+ ? await ensureBrowserConnected({
64
+ browserURL: args.browserUrl,
65
+ devtools,
66
+ })
63
67
  : await ensureBrowserLaunched({
64
68
  headless: args.headless,
65
69
  executablePath: args.executablePath,
66
- customDevTools: args.customDevtools,
67
70
  channel: args.channel,
68
71
  isolated: args.isolated,
69
72
  logFile,
70
73
  viewport: args.viewport,
71
74
  args: extraArgs,
72
75
  acceptInsecureCerts: args.acceptInsecureCerts,
76
+ devtools,
73
77
  });
74
78
  if (context?.browser !== browser) {
75
79
  context = await McpContext.from(browser, logger);
@@ -115,6 +119,10 @@ function registerTool(tool) {
115
119
  };
116
120
  }
117
121
  }
122
+ catch (err) {
123
+ logger(`${tool.name} error: ${err.message}`);
124
+ throw err;
125
+ }
118
126
  finally {
119
127
  guard.dispose();
120
128
  }
@@ -7,7 +7,7 @@ import { ToolCategories } from './categories.js';
7
7
  import { defineTool } from './ToolDefinition.js';
8
8
  export const consoleTool = defineTool({
9
9
  name: 'list_console_messages',
10
- description: 'List all console messages for the currently selected page',
10
+ description: 'List all console messages for the currently selected page since the last navigation.',
11
11
  annotations: {
12
12
  category: ToolCategories.DEBUGGING,
13
13
  readOnlyHint: true,
@@ -29,7 +29,7 @@ const FILTERABLE_RESOURCE_TYPES = [
29
29
  ];
30
30
  export const listNetworkRequests = defineTool({
31
31
  name: 'list_network_requests',
32
- description: `List all requests for the currently selected page`,
32
+ description: `List all requests for the currently selected page since the last navigation.`,
33
33
  annotations: {
34
34
  category: ToolCategories.NETWORK,
35
35
  readOnlyHint: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chrome-devtools-mcp",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "MCP server for Chrome DevTools",
5
5
  "type": "module",
6
6
  "bin": "./build/src/index.js",
@@ -40,7 +40,7 @@
40
40
  "@modelcontextprotocol/sdk": "1.19.1",
41
41
  "core-js": "3.45.1",
42
42
  "debug": "4.4.3",
43
- "puppeteer-core": "^24.23.1",
43
+ "puppeteer-core": "^24.24.0",
44
44
  "yargs": "18.0.0",
45
45
  "zod": "^3.25.76"
46
46
  },
@@ -60,7 +60,7 @@
60
60
  "eslint-plugin-import": "^2.32.0",
61
61
  "globals": "^16.4.0",
62
62
  "prettier": "^3.6.2",
63
- "puppeteer": "24.23.1",
63
+ "puppeteer": "24.24.0",
64
64
  "sinon": "^21.0.0",
65
65
  "typescript": "^5.9.2",
66
66
  "typescript-eslint": "^8.43.0"