playwright-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePlaywright CLI
Playwright CLI
Browser automation via Playwright. Token-efficient CLI for coding agents.
通过Playwright实现浏览器自动化。为编码Agent打造的高效Token CLI工具。
Installation
安装
bash
npm install -g @playwright/mcp@latest
playwright-cli --helpbash
npm install -g @playwright/mcp@latest
playwright-cli --helpCore Commands
核心命令
| Command | Description |
|---|---|
| Open URL in browser |
| Close the page |
| Type text into editable element |
| Click on element |
| Double click |
| Fill text into field |
| Drag and drop |
| Hover over element |
| Check checkbox/radio |
| Uncheck checkbox |
| Select dropdown option |
| Capture page snapshot for refs |
| 命令 | 描述 |
|---|---|
| 在浏览器中打开URL |
| 关闭页面 |
| 在可编辑元素中输入文本 |
| 点击元素 |
| 双击元素 |
| 为输入框填充文本 |
| 拖拽操作 |
| 悬停在元素上 |
| 勾选复选框/单选框 |
| 取消勾选复选框 |
| 选择下拉选项 |
| 捕获页面快照以获取元素引用 |
Navigation
页面导航
bash
playwright-cli go-back # Go back
playwright-cli go-forward # Go forward
playwright-cli reload # Reload pagebash
playwright-cli go-back # 返回上一页
playwright-cli go-forward # 前进到下一页
playwright-cli reload # 重新加载页面Keyboard & Mouse
键盘与鼠标操作
bash
playwright-cli press <key> # Press key (a, arrowleft, enter...)
playwright-cli keydown <key> # Key down
playwright-cli keyup <key> # Key up
playwright-cli mousemove <x> <y> # Move mouse
playwright-cli mousedown [button] # Mouse down
playwright-cli mouseup [button] # Mouse up
playwright-cli mousewheel <dx> <dy> # Scrollbash
playwright-cli press <key> # 按下按键(如a、arrowleft、enter等)
playwright-cli keydown <key> # 按住按键
playwright-cli keyup <key> # 松开按键
playwright-cli mousemove <x> <y> # 移动鼠标
playwright-cli mousedown [button] # 按住鼠标按键
playwright-cli mouseup [button] # 松开鼠标按键
playwright-cli mousewheel <dx> <dy> # 滚动鼠标滚轮Save & Export
保存与导出
bash
playwright-cli screenshot [ref] # Screenshot page or element
playwright-cli pdf # Save as PDFbash
playwright-cli screenshot [ref] # 截取页面或元素的屏幕截图
playwright-cli pdf # 保存为PDF文件Tabs
标签页管理
bash
playwright-cli tab-list # List all tabs
playwright-cli tab-new [url] # Open new tab
playwright-cli tab-close [index] # Close tab
playwright-cli tab-select <index> # Switch tabbash
playwright-cli tab-list # 列出所有标签页
playwright-cli tab-new [url] # 打开新标签页
playwright-cli tab-close [index] # 关闭标签页
playwright-cli tab-select <index> # 切换标签页DevTools
开发者工具
bash
playwright-cli console [min-level] # View console messages
playwright-cli network # View network requests
playwright-cli run-code <code> # Run JS snippet
playwright-cli tracing-start # Start trace
playwright-cli tracing-stop # Stop tracebash
playwright-cli console [min-level] # 查看控制台消息
playwright-cli network # 查看网络请求
playwright-cli run-code <code> # 运行JS代码片段
playwright-cli tracing-start # 开始追踪
playwright-cli tracing-stop # 停止追踪Sessions
会话管理
bash
playwright-cli session-list # List sessions
playwright-cli session-stop [name] # Stop session
playwright-cli session-stop-all # Stop all
playwright-cli session-delete [name] # Delete session databash
playwright-cli session-list # 列出所有会话
playwright-cli session-stop [name] # 停止指定会话
playwright-cli session-stop-all # 停止所有会话
playwright-cli session-delete [name] # 删除会话数据Headed Mode
有头模式
bash
playwright-cli open https://example.com --headedbash
playwright-cli open https://example.com --headedExamples
使用示例
bash
undefinedbash
undefinedOpen and interact
打开页面并进行交互
playwright-cli open https://example.com
playwright-cli type "search query"
playwright-cli press Enter
playwright-cli screenshot
playwright-cli open https://example.com
playwright-cli type "search query"
playwright-cli press Enter
playwright-cli screenshot
Use sessions
使用会话功能
playwright-cli open https://site1.com
playwright-cli --session=project-a open https://site2.com
undefinedplaywright-cli open https://site1.com
playwright-cli --session=project-a open https://site2.com
undefinedEnvironment Variables
环境变量
| Variable | Description |
|---|---|
| Browser: chrome, firefox, webkit, msedge |
| Run headless (default: headed) |
| Comma-separated allowed hosts |
| Path to config file |
| 变量名 | 描述 |
|---|---|
| 指定浏览器:chrome、firefox、webkit、msedge |
| 以无头模式运行(默认:有头模式) |
| 允许访问的主机列表,用逗号分隔 |
| 配置文件路径 |
Configuration
配置
Create for persistent settings:
playwright-cli.jsonjson
{
"browser": {
"browserName": "chromium",
"headless": false
},
"outputDir": "./playwright-output",
"console": {
"level": "info"
}
}创建文件以设置持久化配置:
playwright-cli.jsonjson
{
"browser": {
"browserName": "chromium",
"headless": false
},
"outputDir": "./playwright-output",
"console": {
"level": "info"
}
}Notes
注意事项
- Cross-platform — requires Node.js 18+ (Linux, macOS, Windows)
- Sessions persist cookies/storage by default
- Use flag for isolated browser instances
--session - Snapshots return element refs for subsequent commands
- 跨平台支持 — 需要Node.js 18+(支持Linux、macOS、Windows)
- 会话默认会保留Cookie和存储数据
- 使用标志可创建独立的浏览器实例
--session - 快照会返回元素引用,用于后续命令