Skip to content

Commit 8abf5b1

Browse files
committed
chore: add CLI docs
1 parent bcb852d commit 8abf5b1

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

docs/cli.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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
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+
```sh
51+
chrome-devtools new_page "https://example.com"
52+
chrome-devtools navigate_page "https://web.dev" --type url
53+
```
54+
55+
**Interaction:**
56+
```sh
57+
# Click an element by its UID from a snapshot
58+
chrome-devtools click "element-uid-123"
59+
60+
# Fill a form field
61+
chrome-devtools fill "input-uid-456" "search query"
62+
```
63+
64+
**Analysis:**
65+
```sh
66+
# Run a Lighthouse audit (defaults to navigation mode)
67+
chrome-devtools lighthouse_audit --mode snapshot
68+
```
69+
70+
## Output format
71+
72+
By default, the CLI outputs a human-readable summary of the tool's result. For programmatic use, you can request raw JSON:
73+
74+
```sh
75+
chrome-devtools list_pages --format=json
76+
```
77+
78+
## Troubleshooting
79+
80+
If the CLI hangs or fails to connect, try stopping the background process:
81+
82+
```sh
83+
chrome-devtools stop
84+
```
85+
86+
For more verbose logs, set the `DEBUG` environment variable:
87+
```sh
88+
DEBUG=* chrome-devtools list_pages
89+
```

0 commit comments

Comments
 (0)