chrome-devtools-mcp 0.7.0 → 0.7.1
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 +63 -0
- package/build/src/browser.js +27 -21
- package/build/src/cli.js +5 -0
- package/build/src/main.js +10 -1
- package/build/src/tools/console.js +1 -1
- package/build/src/tools/network.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -328,6 +328,69 @@ all instances of `chrome-devtools-mcp`. Set the `isolated` option to `true`
|
|
|
328
328
|
to use a temporary user data dir instead which will be cleared automatically after
|
|
329
329
|
the browser is closed.
|
|
330
330
|
|
|
331
|
+
### Connecting to a running Chrome instance
|
|
332
|
+
|
|
333
|
+
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.
|
|
334
|
+
|
|
335
|
+
Here is a step-by-step guide on how to connect to a running Chrome Stable instance:
|
|
336
|
+
|
|
337
|
+
**Step 1: Configure the MCP client**
|
|
338
|
+
|
|
339
|
+
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.
|
|
340
|
+
|
|
341
|
+
```json
|
|
342
|
+
{
|
|
343
|
+
"mcpServers": {
|
|
344
|
+
"chrome-devtools": {
|
|
345
|
+
"command": "npx",
|
|
346
|
+
"args": [
|
|
347
|
+
"chrome-devtools-mcp@latest",
|
|
348
|
+
"--browser-url=http://localhost:9222"
|
|
349
|
+
]
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
**Step 2: Start the Chrome browser**
|
|
356
|
+
|
|
357
|
+
> [!WARNING]
|
|
358
|
+
> 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.
|
|
359
|
+
|
|
360
|
+
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.
|
|
361
|
+
|
|
362
|
+
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.
|
|
363
|
+
|
|
364
|
+
**macOS**
|
|
365
|
+
|
|
366
|
+
```bash
|
|
367
|
+
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-profile-stable
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
**Linux**
|
|
371
|
+
|
|
372
|
+
```bash
|
|
373
|
+
/usr/bin/google-chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-profile-stable
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
**Windows**
|
|
377
|
+
|
|
378
|
+
```bash
|
|
379
|
+
"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 --user-data-dir="%TEMP%\chrome-profile-stable"
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
**Step 3: Test your setup**
|
|
383
|
+
|
|
384
|
+
After configuring the MCP client and starting the Chrome browser, you can test your setup by running a simple prompt in your MCP client:
|
|
385
|
+
|
|
386
|
+
```
|
|
387
|
+
Check the performance of https://developers.chrome.com
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
Your MCP client should connect to the running Chrome instance and receive a performance report.
|
|
391
|
+
|
|
392
|
+
For more details on remote debugging, see the [Chrome DevTools documentation](https://developer.chrome.com/docs/devtools/remote-debugging/).
|
|
393
|
+
|
|
331
394
|
## Known limitations
|
|
332
395
|
|
|
333
396
|
### Operating system sandboxes
|
package/build/src/browser.js
CHANGED
|
@@ -8,34 +8,36 @@ import os from 'node:os';
|
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import puppeteer from 'puppeteer-core';
|
|
10
10
|
let browser;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
]);
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
22
|
-
if (target.url()
|
|
23
|
-
return
|
|
20
|
+
return function targetFilter(target) {
|
|
21
|
+
if (target.url() === 'chrome://newtab/') {
|
|
22
|
+
return true;
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
for (const prefix of ignoredPrefixes) {
|
|
25
|
+
if (target.url().startsWith(prefix)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
};
|
|
27
31
|
}
|
|
28
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -62,6 +64,9 @@ export async function launch(options) {
|
|
|
62
64
|
args.push('--screen-info={3840x2160}');
|
|
63
65
|
}
|
|
64
66
|
let puppeteerChannel;
|
|
67
|
+
if (options.devtools) {
|
|
68
|
+
args.push('--auto-open-devtools-for-tabs');
|
|
69
|
+
}
|
|
65
70
|
if (!executablePath) {
|
|
66
71
|
puppeteerChannel =
|
|
67
72
|
channel && channel !== 'stable'
|
|
@@ -70,8 +75,8 @@ export async function launch(options) {
|
|
|
70
75
|
}
|
|
71
76
|
try {
|
|
72
77
|
const browser = await puppeteer.launch({
|
|
73
|
-
...connectOptions,
|
|
74
78
|
channel: puppeteerChannel,
|
|
79
|
+
targetFilter: makeTargetFilter(options.devtools),
|
|
75
80
|
executablePath,
|
|
76
81
|
defaultViewport: null,
|
|
77
82
|
userDataDir,
|
|
@@ -79,6 +84,7 @@ export async function launch(options) {
|
|
|
79
84
|
headless,
|
|
80
85
|
args,
|
|
81
86
|
acceptInsecureCerts: options.acceptInsecureCerts,
|
|
87
|
+
handleDevToolsAsPage: options.devtools,
|
|
82
88
|
});
|
|
83
89
|
if (options.logFile) {
|
|
84
90
|
// FIXME: we are probably subscribing too late to catch startup logs. We
|
package/build/src/cli.js
CHANGED
|
@@ -81,6 +81,11 @@ export const cliOptions = {
|
|
|
81
81
|
type: 'boolean',
|
|
82
82
|
description: `If enabled, ignores errors relative to self-signed and expired certificates. Use with caution.`,
|
|
83
83
|
},
|
|
84
|
+
experimentalDevtools: {
|
|
85
|
+
type: 'boolean',
|
|
86
|
+
describe: 'Whether to enable automation over DevTools targets',
|
|
87
|
+
hidden: true,
|
|
88
|
+
},
|
|
84
89
|
};
|
|
85
90
|
export function parseArguments(version, argv = process.argv) {
|
|
86
91
|
const yargsInstance = yargs(hideBin(argv))
|
package/build/src/main.js
CHANGED
|
@@ -58,8 +58,12 @@ async function getContext() {
|
|
|
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(
|
|
63
|
+
? await ensureBrowserConnected({
|
|
64
|
+
browserURL: args.browserUrl,
|
|
65
|
+
devtools,
|
|
66
|
+
})
|
|
63
67
|
: await ensureBrowserLaunched({
|
|
64
68
|
headless: args.headless,
|
|
65
69
|
executablePath: args.executablePath,
|
|
@@ -70,6 +74,7 @@ async function getContext() {
|
|
|
70
74
|
viewport: args.viewport,
|
|
71
75
|
args: extraArgs,
|
|
72
76
|
acceptInsecureCerts: args.acceptInsecureCerts,
|
|
77
|
+
devtools,
|
|
73
78
|
});
|
|
74
79
|
if (context?.browser !== browser) {
|
|
75
80
|
context = await McpContext.from(browser, logger);
|
|
@@ -115,6 +120,10 @@ function registerTool(tool) {
|
|
|
115
120
|
};
|
|
116
121
|
}
|
|
117
122
|
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
logger(`${tool.name} error: ${err.message}`);
|
|
125
|
+
throw err;
|
|
126
|
+
}
|
|
118
127
|
finally {
|
|
119
128
|
guard.dispose();
|
|
120
129
|
}
|
|
@@ -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.
|
|
3
|
+
"version": "0.7.1",
|
|
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.
|
|
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.
|
|
63
|
+
"puppeteer": "24.24.0",
|
|
64
64
|
"sinon": "^21.0.0",
|
|
65
65
|
"typescript": "^5.9.2",
|
|
66
66
|
"typescript-eslint": "^8.43.0"
|