playwright-bowser
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePlaywright Bowser
Playwright 浏览器
Purpose
用途
Automate browsers using — a token-efficient CLI for Playwright. Runs headless by default, supports parallel sessions via named sessions (), and doesn't load tool schemas into context.
playwright-cli-s=使用实现浏览器自动化——这是一款高效利用Token的Playwright命令行工具。默认以无头模式运行,支持通过命名会话()实现并行会话,且不会将工具架构加载到上下文环境中。
playwright-cli-s=Key Details
核心特性
- Headless by default — pass to
--headedto see the browseropen - Parallel sessions — use to run multiple independent browser instances
-s=<name> - Persistent profiles — cookies and storage state preserved between calls
- Token-efficient — CLI-based, no accessibility trees or tool schemas in context
- Vision mode (opt-in) — set to receive screenshots as image responses in context instead of just saving to disk
PLAYWRIGHT_MCP_CAPS=vision
- 默认无头模式——调用命令时传入
open参数即可显示浏览器界面--headed - 并行会话——使用参数运行多个独立的浏览器实例
-s=<name> - 持久化配置文件——调用之间会保留Cookie和存储状态
- Token高效——基于CLI,上下文环境中不包含可访问性树或工具架构
- 视觉模式(可选)——设置后,截图将以图片响应的形式返回至上下文,而非仅保存到磁盘
PLAYWRIGHT_MCP_CAPS=vision
Sessions
会话管理
Always use a named session. Derive a short, descriptive kebab-case name from the user's prompt. This gives each task a persistent browser profile (cookies, localStorage, history) that accumulates across calls.
bash
undefined务必使用命名会话。根据用户的请求生成一个简短、描述性的短横线分隔名称(kebab-case)。这样每个任务都会拥有一个持久化的浏览器配置文件(Cookie、localStorage、历史记录),且会在多次调用中累积。
bash
undefinedDerive session name from prompt context:
根据请求上下文生成会话名称:
"test the checkout flow on mystore.com" → -s=mystore-checkout
"测试mystore.com的结账流程" → -s=mystore-checkout
"scrape pricing from competitor.com" → -s=competitor-pricing
"抓取competitor.com的价格信息" → -s=competitor-pricing
"UI test the login page" → -s=login-ui-test
"对登录页面进行UI测试" → -s=login-ui-test
playwright-cli -s=mystore-checkout open https://mystore.com --persistent
playwright-cli -s=mystore-checkout snapshot
playwright-cli -s=mystore-checkout click e12
Managing sessions:
```bash
playwright-cli list # list all sessions
playwright-cli close-all # close all sessions
playwright-cli -s=<name> close # close specific session
playwright-cli -s=<name> delete-data # wipe session profileplaywright-cli -s=mystore-checkout open https://mystore.com --persistent
playwright-cli -s=mystore-checkout snapshot
playwright-cli -s=mystore-checkout click e12
会话管理命令:
```bash
playwright-cli list # 列出所有会话
playwright-cli close-all # 关闭所有会话
playwright-cli -s=<name> close # 关闭指定会话
playwright-cli -s=<name> delete-data # 清空会话配置文件Quick Reference
快速参考
Core: open [url], goto <url>, click <ref>, fill <ref> <text>, type <text>, snapshot, screenshot [ref], close
Navigate: go-back, go-forward, reload
Keyboard: press <key>, keydown <key>, keyup <key>
Mouse: mousemove <x> <y>, mousedown, mouseup, mousewheel <dx> <dy>
Tabs: tab-list, tab-new [url], tab-close [index], tab-select <index>
Save: screenshot [ref], pdf, screenshot --filename=f
Storage: state-save, state-load, cookie-*, localstorage-*, sessionstorage-*
Network: route <pattern>, route-list, unroute, network
DevTools: console, run-code <code>, tracing-start/stop, video-start/stop
Sessions: -s=<name> <cmd>, list, close-all, kill-all
Config: open --headed, open --browser=chrome, resize <w> <h>核心命令: open [url], goto <url>, click <ref>, fill <ref> <text>, type <text>, snapshot, screenshot [ref], close
导航命令: go-back, go-forward, reload
键盘操作: press <key>, keydown <key>, keyup <key>
鼠标操作: mousemove <x> <y>, mousedown, mouseup, mousewheel <dx> <dy>
标签页管理: tab-list, tab-new [url], tab-close [index], tab-select <index>
保存操作: screenshot [ref], pdf, screenshot --filename=f
存储管理: state-save, state-load, cookie-*, localstorage-*, sessionstorage-*
网络操作: route <pattern>, route-list, unroute, network
开发者工具: console, run-code <code>, tracing-start/stop, video-start/stop
会话操作: -s=<name> <cmd>, list, close-all, kill-all
配置选项: open --headed, open --browser=chrome, resize <w> <h>Workflow
工作流程
- Derive a session name from the user's prompt and open with to preserve cookies/state. Always set the viewport via env var at launch:
--persistent
bash
PLAYWRIGHT_MCP_VIEWPORT_SIZE=1440x900 playwright-cli -s=<session-name> open <url> --persistent- 根据用户的请求生成会话名称,使用参数打开会话以保留Cookie/状态。启动时务必通过环境变量设置视口大小:
--persistent
bash
PLAYWRIGHT_MCP_VIEWPORT_SIZE=1440x900 playwright-cli -s=<session-name> open <url> --persistentor headed:
或使用有头模式:
PLAYWRIGHT_MCP_VIEWPORT_SIZE=1440x900 playwright-cli -s=<session-name> open <url> --persistent --headed
PLAYWRIGHT_MCP_VIEWPORT_SIZE=1440x900 playwright-cli -s=<session-name> open <url> --persistent --headed
or with vision (screenshots returned as image responses in context):
或启用视觉模式(截图以图片响应形式返回至上下文):
PLAYWRIGHT_MCP_VIEWPORT_SIZE=1440x900 PLAYWRIGHT_MCP_CAPS=vision playwright-cli -s=<session-name> open <url> --persistent
3. Get element references via snapshot:
```bash
playwright-cli snapshot- Interact using refs from snapshot:
bash
playwright-cli click <ref>
playwright-cli fill <ref> "text"
playwright-cli type "text"
playwright-cli press Enter- Capture results:
bash
playwright-cli screenshot
playwright-cli screenshot --filename=output.png- Always close the session when done. This is not optional — close the named session after finishing your task:
bash
playwright-cli -s=<session-name> closePLAYWRIGHT_MCP_VIEWPORT_SIZE=1440x900 PLAYWRIGHT_MCP_CAPS=vision playwright-cli -s=<session-name> open <url> --persistent
3. 通过snapshot命令获取元素引用:
```bash
playwright-cli snapshot- 使用snapshot返回的引用进行交互:
bash
playwright-cli click <ref>
playwright-cli fill <ref> "text"
playwright-cli type "text"
playwright-cli press Enter- 捕获结果:
bash
playwright-cli screenshot
playwright-cli screenshot --filename=output.png- 任务完成后务必关闭会话——这是必填步骤,完成任务后关闭指定的命名会话:
bash
playwright-cli -s=<session-name> closeConfiguration
配置
If a exists in the working directory, use it automatically. If the user provides a path to a config file, use . Otherwise, skip configuration — the env var and CLI defaults are sufficient.
playwright-cli.json--config path/to/config.jsonjson
{
"browser": {
"browserName": "chromium",
"launchOptions": { "headless": true },
"contextOptions": { "viewport": { "width": 1440, "height": 900 } }
},
"outputDir": "./screenshots"
}如果工作目录中存在,工具会自动加载该配置。如果用户提供了配置文件路径,使用参数加载。否则,无需配置——环境变量和CLI默认参数已足够使用。
playwright-cli.json--config path/to/config.jsonjson
{
"browser": {
"browserName": "chromium",
"launchOptions": { "headless": true },
"contextOptions": { "viewport": { "width": 1440, "height": 900 } }
},
"outputDir": "./screenshots"
}Full Help
完整帮助文档
Run or for detailed command usage.
playwright-cli --helpplaywright-cli --help <command>See docs/playwright-cli.md for full documentation.
运行或查看详细的命令用法。
playwright-cli --helpplaywright-cli --help <command>查看docs/playwright-cli.md获取完整文档。