豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 1ac574e

Browse files
OrKoNmathiasbynens
andauthored
feat: experimental chrome-devtools CLI (#1100)
This PR enables an alternative CLI interface for Chrome DevTools MCP. `chrome-devtools` can be used in shell scripts to automate the Chrome DevTools MCP session running as a daemon process. Currently, a single session is shared between all `chrome-devtools` calls. All tools available by default are included into the CLI. Examples: ```bash ❯ chrome-devtools navigate_page --url https://example.com Successfully navigated to https://example.com. ## Pages 1: https://example.com/ [selected] ❯ chrome-devtools lighthouse_audit ## Lighthouse Audit Results Mode: navigation Device: desktop URL: https://example.com/ ### Category Scores - Accessibility: 96 (accessibility) - Best Practices: 96 (best-practices) - SEO: 80 (seo) ### Audit Summary Passed: 30 Failed: 4 Total Timing: 4107.22ms ### Reports - /var/folders/hq/m1wr43z9665g5pghys7gkc2w00r23k/T/chrome-devtools-mcp-l5LRIT/report.json - /var/folders/hq/m1wr43z9665g5pghys7gkc2w00r23k/T/chrome-devtools-mcp-3o6rcM/report.htm ``` ```sh ❯ chrome-devtools lighthouse_audit --format=json | jq { "lighthouseResult": { "summary": { "mode": "navigation", "device": "desktop", "url": "https://example.com/", "scores": [ { "id": "accessibility", "title": "Accessibility", "score": 0.96 }, { "id": "best-practices", "title": "Best Practices", "score": 0.96 }, { "id": "seo", "title": "SEO", "score": 0.8 } ], "audits": { "failed": 4, "passed": 30 }, "timing": { "total": 3754.87 } }, "reports": [ "/var/folders/hq/m1wr43z9665g5pghys7gkc2w00r23k/T/chrome-devtools-mcp-nbLj82/report.json", "/var/folders/hq/m1wr43z9665g5pghys7gkc2w00r23k/T/chrome-devtools-mcp-VTp35b/report.html" ] } } ``` To test: ```sh npm ci npm run clean npm run bundle npm pack npm i chrome-devtools-mcp-0.18.1.tgz -g # to install globally ``` --------- Co-authored-by: Mathias Bynens <mathias@qiwi.be>
1 parent 3474f1f commit 1ac574e

File tree

4 files changed

+151
-1
lines changed

4 files changed

+151
-1
lines changed

package-lock.json

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

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
"version": "0.19.0",
44
"description": "MCP server for Chrome DevTools",
55
"type": "module",
6-
"bin": "./build/src/bin/chrome-devtools-mcp.js",
6+
"bin": {
7+
"chrome-devtools-mcp": "./build/src/bin/chrome-devtools-mcp.js",
8+
"chrome-devtools": "./build/src/bin/chrome-devtools.js"
9+
},
710
"main": "./build/src/index.js",
811
"scripts": {
912
"cli:generate": "node --experimental-strip-types scripts/generate-cli.ts",
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
name: chrome-devtools-cli
3+
description: Use this to skill to write shell scripts or run shell commands to automate tasks in the browser or otherwise use Chrome DevTools via CLI.
4+
---
5+
6+
The `chrome-devtools-mcp` CLI lets you interact with the browser from your terminal.
7+
8+
## Setup
9+
10+
_Note: If this is your very first time using the CLI, see [references/installation.md](references/installation.md) for setup. Installation is a one-time prerequisite and is **not** part of the regular AI workflow._
11+
12+
## AI Workflow
13+
14+
1. **Execute**: Run tools directly (e.g., `chrome-devtools list_pages`). The background server starts implicitly; **do not** run `start`/`status`/`stop` before each use.
15+
2. **Inspect**: Use `take_snapshot` to get an element `<uid>`.
16+
3. **Act**: Use `click`, `fill`, etc. State persists across commands.
17+
18+
Snapshot example:
19+
20+
```
21+
uid=1_0 RootWebArea "Example Domain" url="https://example.com/"
22+
uid=1_1 heading "Example Domain" level="1"
23+
```
24+
25+
## Command Usage
26+
27+
```sh
28+
chrome-devtools <tool> [arguments] [flags]
29+
```
30+
31+
Use `--help` on any command. Output defaults to Markdown, use `--output-format=json` for JSON.
32+
33+
## Input Automation (<uid> from snapshot)
34+
35+
```bash
36+
chrome-devtools take_snapshot --help # Help message for commands, works for any command.
37+
chrome-devtools take_snapshot # Take a text snapshot of the page to get UIDs for elements
38+
chrome-devtools click "id" # Clicks on the provided element
39+
chrome-devtools click "id" --dblClick true --includeSnapshot true # Double clicks and returns a snapshot
40+
chrome-devtools drag "src" "dst" # Drag an element onto another element
41+
chrome-devtools drag "src" "dst" --includeSnapshot true # Drag an element and return a snapshot
42+
chrome-devtools fill "id" "text" # Type text into an input or select an option
43+
chrome-devtools fill "id" "text" --includeSnapshot true # Fill an element and return a snapshot
44+
chrome-devtools handle_dialog accept # Handle a browser dialog
45+
chrome-devtools handle_dialog dismiss --promptText "hi" # Dismiss a dialog with prompt text
46+
chrome-devtools hover "id" # Hover over the provided element
47+
chrome-devtools hover "id" --includeSnapshot true # Hover over an element and return a snapshot
48+
chrome-devtools press_key "Enter" # Press a key or key combination
49+
chrome-devtools press_key "Control+A" --includeSnapshot true # Press a key and return a snapshot
50+
chrome-devtools type_text "hello" # Type text using keyboard into a focused input
51+
chrome-devtools type_text "hello" --submitKey "Enter" # Type text and press a submit key
52+
chrome-devtools upload_file "id" "file.txt" # Upload a file through a provided element
53+
chrome-devtools upload_file "id" "file.txt" --includeSnapshot true # Upload a file and return a snapshot
54+
```
55+
56+
## Navigation
57+
58+
```bash
59+
chrome-devtools close_page 1 # Closes the page by its index
60+
chrome-devtools list_pages # Get a list of pages open in the browser
61+
chrome-devtools navigate_page --url "https://example.com" # Navigates the currently selected page to a URL
62+
chrome-devtools navigate_page --type "reload" --ignoreCache true # Reload page ignoring cache
63+
chrome-devtools navigate_page --url "https://example.com" --timeout 5000 # Navigate with a timeout
64+
chrome-devtools navigate_page --handleBeforeUnload "accept" # Handle before unload dialog
65+
chrome-devtools navigate_page --type "back" --initScript "foo()" # Navigate back and run an init script
66+
chrome-devtools new_page "https://example.com" # Creates a new page
67+
chrome-devtools new_page "https://example.com" --background true --timeout 5000 # Create new page in background
68+
chrome-devtools new_page "https://example.com" --isolatedContext "ctx" # Create new page with isolated context
69+
chrome-devtools select_page 1 # Select a page as a context for future tool calls
70+
chrome-devtools select_page 1 --bringToFront true # Select a page and bring it to front
71+
```
72+
73+
## Emulation
74+
75+
```bash
76+
chrome-devtools emulate --networkConditions "Offline" # Emulate network conditions
77+
chrome-devtools emulate --cpuThrottlingRate 4 --geolocation "0,0" # Emulate CPU throttling and geolocation
78+
chrome-devtools emulate --colorScheme "dark" --viewport "1920x1080" # Emulate color scheme and viewport
79+
chrome-devtools emulate --userAgent "Mozilla/5.0..." # Emulate user agent
80+
chrome-devtools resize_page 1920 1080 # Resizes the selected page's window
81+
```
82+
83+
## Performance
84+
85+
```bash
86+
chrome-devtools performance_analyze_insight "1" "LCPBreakdown" # Get more details on a specific Performance Insight
87+
chrome-devtools performance_start_trace true false # Starts a performance trace recording
88+
chrome-devtools performance_start_trace true true --filePath t.gz # Start trace and save to a file
89+
chrome-devtools performance_stop_trace # Stops the active performance trace
90+
chrome-devtools performance_stop_trace --filePath "t.json" # Stop trace and save to a file
91+
chrome-devtools take_memory_snapshot "./snap.heapsnapshot" # Capture a memory heapsnapshot
92+
```
93+
94+
## Network
95+
96+
```bash
97+
chrome-devtools get_network_request # Get the currently selected network request
98+
chrome-devtools get_network_request --reqid 1 --requestFilePath req.md # Get request by id and save to file
99+
chrome-devtools get_network_request --responseFilePath res.md # Save response body to file
100+
chrome-devtools list_network_requests # List all network requests
101+
chrome-devtools list_network_requests --pageSize 50 --pageIdx 0 # List network requests with pagination
102+
chrome-devtools list_network_requests --resourceTypes Fetch # Filter requests by resource type
103+
chrome-devtools list_network_requests --includePreservedRequests true # Include preserved requests
104+
```
105+
106+
## Debugging & Inspection
107+
108+
```bash
109+
chrome-devtools evaluate_script "() => document.title" # Evaluate a JavaScript function on the page
110+
evaluate_script "(a) => a.innerText" --args 1_4 # Evaluate JS with UID arguments
111+
chrome-devtools get_console_message 1 # Gets a console message by its ID
112+
chrome-devtools lighthouse_audit --mode "navigation" # Run Lighthouse audit for navigation
113+
chrome-devtools lighthouse_audit --mode "snapshot" --device "mobile" # Run Lighthouse audit for a snapshot on mobile
114+
chrome-devtools lighthouse_audit --outputDirPath ./out # Run Lighthouse audit and save reports
115+
chrome-devtools list_console_messages # List all console messages
116+
chrome-devtools list_console_messages --pageSize 20 --pageIdx 1 # List console messages with pagination
117+
chrome-devtools list_console_messages --types error --types info # Filter console messages by type
118+
chrome-devtools list_console_messages --includePreservedMessages true # Include preserved messages
119+
chrome-devtools take_screenshot # Take a screenshot of the page viewport
120+
chrome-devtools take_screenshot --fullPage true --format "jpeg" --quality 80 # Take a full page screenshot as JPEG with quality
121+
chrome-devtools take_screenshot --uid "id" --filePath "s.png" # Take a screenshot of an element
122+
chrome-devtools take_snapshot # Take a text snapshot of the page from the a11y tree
123+
chrome-devtools take_snapshot --verbose true --filePath "s.txt" # Take a verbose snapshot and save to file
124+
```
125+
126+
## Service Management
127+
128+
```bash
129+
chrome-devtools start # Start or restart chrome-devtools-mcp
130+
chrome-devtools status # Checks if chrome-devtools-mcp is running
131+
chrome-devtools stop # Stop chrome-devtools-mcp if any
132+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Installation
2+
3+
Install the package globally to make the `chrome-devtools` command available. You only need to do this the first time you use it.
4+
5+
```sh
6+
npm i chrome-devtools-mcp@latest -g
7+
chrome-devtools status # check if install worked.
8+
```
9+
10+
## Troubleshooting
11+
12+
- **Command not found:** If `chrome-devtools` is not recognized, ensure your global npm `bin` directory is in your system's `PATH`. Restart your terminal or source your shell configuration file (e.g., `.bashrc`, `.zshrc`).
13+
- **Permission errors:** If you encounter `EACCES` or permission errors during installation, avoid using `sudo`. Instead, use a node version manager like `nvm`, or configure npm to use a different global directory.
14+
- **Old version running:** Run `chrome-devtools stop && npm uninstall -g chrome-devtools-mcp` before reinstalling, or ensure the latest version is being picked up by your path.

0 commit comments

Comments
 (0)