|
| 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 | +``` |
0 commit comments