Skip to content

Commit 1c277a2

Browse files
authored
Merge branch 'main' into fix/940-improve-mcp-invocation
2 parents 04d4473 + 7c9ff36 commit 1c277a2

33 files changed

Lines changed: 1672 additions & 313 deletions

.github/workflows/run-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ jobs:
4141
shell: bash
4242
run: npm ci
4343

44-
- name: Install Chrome Canary
45-
shell: bash
46-
run: |
47-
CANARY_PATH=$(npx @puppeteer/browsers install chrome@canary --format "{{path}}")
48-
echo "CANARY_EXECUTABLE_PATH=$CANARY_PATH" >> $GITHUB_ENV
49-
5044
- name: Build
5145
run: npm run bundle
5246
env:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Add the following config to your MCP client:
7373
> [!NOTE]
7474
> Using `chrome-devtools-mcp@latest` ensures that your MCP client will always use the latest version of the Chrome DevTools MCP server.
7575
76-
If you are intersted in doing only basic browser tasks, use the `--slim` mode:
76+
If you are interested in doing only basic browser tasks, use the `--slim` mode:
7777

7878
```json
7979
{
@@ -459,7 +459,7 @@ The Chrome DevTools MCP server supports the following configuration option:
459459
<!-- BEGIN AUTO GENERATED OPTIONS -->
460460

461461
- **`--autoConnect`/ `--auto-connect`**
462-
If specified, automatically connects to a browser (Chrome 144+) running in the user data directory identified by the channel param. Requires the remoted debugging server to be started in the Chrome instance via chrome://inspect/#remote-debugging.
462+
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 remoted debugging server to be started in the Chrome instance via chrome://inspect/#remote-debugging.
463463
- **Type:** boolean
464464
- **Default:** `false`
465465

docs/cli.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Chrome DevTools CLI
2+
3+
The `chrome-devtools-mcp` package includes a CLI interface that allows you to interact with the browser directly from your terminal. This is particularly useful for debugging or when you want an agent to generate scripts that automate browser actions.
4+
5+
## Getting started
6+
7+
Install the package globally to make the `chrome-devtools` command available:
8+
9+
```sh
10+
npm i chrome-devtools-mcp@latest -g
11+
chrome-devtools status # check if install worked.
12+
```
13+
14+
## How it works
15+
16+
The CLI acts as a client to a background `chrome-devtools-mcp` daemon.
17+
18+
- **Automatic Start**: The first time you call a tool (e.g., `list_pages`), the CLI automatically starts the MCP server and the browser in the background if they aren't already running.
19+
- **Persistence**: The same background instance is reused for subsequent commands, preserving the browser state (open pages, cookies, etc.).
20+
- **Manual Control**: You can explicitly manage the background process using `start`, `stop`, and `status`. The `start` command forwards all subsequent arguments to the underlying MCP server (e.g., `--headless`, `--userDataDir`).
21+
22+
```sh
23+
# Check if the daemon is running
24+
chrome-devtools status
25+
26+
# Navigate the current page to a URL
27+
chrome-devtools navigate_page "https://google.com"
28+
29+
# Take a screenshot and save it to a file
30+
chrome-devtools take_screenshot --filePath screenshot.png
31+
32+
# Stop the background daemon when finished
33+
chrome-devtools stop
34+
```
35+
36+
## Command Usage
37+
38+
The CLI supports all tools available in the [Tool reference](./tool-reference.md).
39+
40+
```sh
41+
chrome-devtools <tool> [arguments] [flags]
42+
```
43+
44+
- **Required Arguments**: Passed as positional arguments.
45+
- **Optional Arguments**: Passed as flags (e.g., `--filePath`, `--fullPage`).
46+
47+
### Examples
48+
49+
**New Page and Navigation:**
50+
51+
```sh
52+
chrome-devtools new_page "https://example.com"
53+
chrome-devtools navigate_page "https://web.dev" --type url
54+
```
55+
56+
**Interaction:**
57+
58+
```sh
59+
# Click an element by its UID from a snapshot
60+
chrome-devtools click "element-uid-123"
61+
62+
# Fill a form field
63+
chrome-devtools fill "input-uid-456" "search query"
64+
```
65+
66+
**Analysis:**
67+
68+
```sh
69+
# Run a Lighthouse audit (defaults to navigation mode)
70+
chrome-devtools lighthouse_audit --mode snapshot
71+
```
72+
73+
## Output format
74+
75+
By default, the CLI outputs a human-readable summary of the tool's result. For programmatic use, you can request raw JSON:
76+
77+
```sh
78+
chrome-devtools list_pages --format=json
79+
```
80+
81+
## Troubleshooting
82+
83+
If the CLI hangs or fails to connect, try stopping the background process:
84+
85+
```sh
86+
chrome-devtools stop
87+
```
88+
89+
For more verbose logs, set the `DEBUG` environment variable:
90+
91+
```sh
92+
DEBUG=* chrome-devtools list_pages
93+
```

docs/tool-reference.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- AUTO GENERATED DO NOT EDIT - run 'npm run docs' to update-->
22

3-
# Chrome DevTools MCP Tool Reference (~6919 cl100k_base tokens)
3+
# Chrome DevTools MCP Tool Reference (~6915 cl100k_base tokens)
44

55
- **[Input automation](#input-automation)** (9 tools)
66
- [`click`](#click)
@@ -260,9 +260,9 @@
260260

261261
**Parameters:**
262262

263-
- **autoStop** (boolean) **(required)**: Determines if the trace recording should be automatically stopped.
264-
- **reload** (boolean) **(required)**: Determines if, once tracing has started, the current selected page should be automatically reloaded. Navigate the page to the right URL using the [`navigate_page`](#navigate_page) tool BEFORE starting the trace if reload or autoStop is set to true.
263+
- **autoStop** (boolean) _(optional)_: Determines if the trace recording should be automatically stopped.
265264
- **filePath** (string) _(optional)_: The absolute file path, or a file path relative to the current working directory, to save the raw trace data. For example, trace.json.gz (compressed) or trace.json (uncompressed).
265+
- **reload** (boolean) _(optional)_: Determines if, once tracing has started, the current selected page should be automatically reloaded. Navigate the page to the right URL using the [`navigate_page`](#navigate_page) tool BEFORE starting the trace if reload or autoStop is set to true.
266266

267267
---
268268

docs/troubleshooting.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
auto-accept installation prompt.
99
- Find a specific error in the output of the `chrome-devtools-mcp` server.
1010
Usually, if your client is an IDE, logs would be in the Output pane.
11+
- Search the [GitHub repository issues and discussions](https://github.com/ChromeDevTools/chrome-devtools-mcp) for help or existing similar problems.
1112

1213
## Debugging
1314

@@ -98,3 +99,12 @@ Possible workarounds include:
9899
`npx chrome-devtools-mcp --browser-url http://127.0.0.1:9222`
99100

100101
- **Use Powershell or Git Bash** instead of WSL.
102+
103+
### Connection timeouts with `--autoConnect`
104+
105+
If you are using the `--autoConnect` flag and tools like `list_pages`, `new_page`, or `navigate_page` fail with a timeout (e.g., `ProtocolError: Network.enable timed out` or `The socket connection was closed unexpectedly`), this usually means the MCP server cannot handshake with the running Chrome instance correctly. Ensure:
106+
107+
1. Chrome 144+ is **already** running.
108+
2. Remote debugging is enabled in Chrome via `chrome://inspect/#remote-debugging`.
109+
3. You have allowed the remote debugging connection prompt in the browser.
110+
4. There is no other MCP server or tool trying to connect to the same debugging port.

package-lock.json

Lines changed: 37 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@types/yargs": "^17.0.33",
5757
"@typescript-eslint/eslint-plugin": "^8.43.0",
5858
"@typescript-eslint/parser": "^8.43.0",
59-
"chrome-devtools-frontend": "1.0.1591204",
59+
"chrome-devtools-frontend": "1.0.1592362",
6060
"core-js": "3.48.0",
6161
"debug": "4.4.3",
6262
"eslint": "^9.35.0",
@@ -65,7 +65,7 @@
6565
"globals": "^17.0.0",
6666
"lighthouse": "13.0.3",
6767
"prettier": "^3.6.2",
68-
"puppeteer": "24.37.5",
68+
"puppeteer": "24.38.0",
6969
"rollup": "4.59.0",
7070
"rollup-plugin-cleanup": "^3.2.1",
7171
"rollup-plugin-license": "^3.6.0",

scripts/test.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Note: can be converted to ts file once node 20 support is dropped.
88
// Node 20 does not support --experimental-strip-types flag.
99

10-
import {spawn} from 'node:child_process';
10+
import {spawn, execSync} from 'node:child_process';
1111
import path from 'node:path';
1212
import process from 'node:process';
1313

@@ -52,12 +52,26 @@ const nodeArgs = [
5252
'--test-reporter',
5353
(process.env['NODE_TEST_REPORTER'] ?? process.env['CI']) ? 'spec' : 'dot',
5454
'--test-force-exit',
55+
'--test-concurrency=1',
5556
'--test',
5657
'--test-timeout=60000',
5758
...flags,
5859
...files,
5960
];
6061

62+
function installChrome(version) {
63+
try {
64+
return execSync(
65+
`npx puppeteer browsers install chrome@${version} --format "{{path}}"`,
66+
)
67+
.toString()
68+
.trim();
69+
} catch (e) {
70+
console.error(`Failed to install Chrome ${version}:`, e);
71+
process.exit(1);
72+
}
73+
}
74+
6175
async function runTests(attempt) {
6276
if (attempt > 1) {
6377
console.log(`\nRun attempt ${attempt}...\n`);
@@ -78,6 +92,9 @@ async function runTests(attempt) {
7892
});
7993
}
8094

95+
const chromePath = installChrome('146.0.7680.31');
96+
process.env.CHROME_M146_EXECUTABLE_PATH = chromePath;
97+
8198
const maxAttempts = shouldRetry ? 3 : 1;
8299
let exitCode = 1;
83100

0 commit comments

Comments
 (0)