playwright-bowser

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Playwright Bowser

Playwright 浏览器

Purpose

用途

Automate browsers using
playwright-cli
— a token-efficient CLI for Playwright. Runs headless by default, supports parallel sessions via named sessions (
-s=
), and doesn't load tool schemas into context.
使用
playwright-cli
实现浏览器自动化——这是一款高效利用Token的Playwright命令行工具。默认以无头模式运行,支持通过命名会话(
-s=
)实现并行会话,且不会将工具架构加载到上下文环境中。

Key Details

核心特性

  • Headless by default — pass
    --headed
    to
    open
    to see the browser
  • Parallel sessions — use
    -s=<name>
    to run multiple independent browser instances
  • 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
    PLAYWRIGHT_MCP_CAPS=vision
    to receive screenshots as image responses in context instead of just saving to disk
  • 默认无头模式——调用
    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
undefined

Derive 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 profile
playwright-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

工作流程

  1. Derive a session name from the user's prompt and open with
    --persistent
    to preserve cookies/state. Always set the viewport via env var at launch:
bash
PLAYWRIGHT_MCP_VIEWPORT_SIZE=1440x900 playwright-cli -s=<session-name> open <url> --persistent
  1. 根据用户的请求生成会话名称,使用
    --persistent
    参数打开会话以保留Cookie/状态。启动时务必通过环境变量设置视口大小:
bash
PLAYWRIGHT_MCP_VIEWPORT_SIZE=1440x900 playwright-cli -s=<session-name> open <url> --persistent

or 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
  1. Interact using refs from snapshot:
bash
playwright-cli click <ref>
playwright-cli fill <ref> "text"
playwright-cli type "text"
playwright-cli press Enter
  1. Capture results:
bash
playwright-cli screenshot
playwright-cli screenshot --filename=output.png
  1. Always close the session when done. This is not optional — close the named session after finishing your task:
bash
playwright-cli -s=<session-name> close
PLAYWRIGHT_MCP_VIEWPORT_SIZE=1440x900 PLAYWRIGHT_MCP_CAPS=vision playwright-cli -s=<session-name> open <url> --persistent

3. 通过snapshot命令获取元素引用:
```bash
playwright-cli snapshot
  1. 使用snapshot返回的引用进行交互:
bash
playwright-cli click <ref>
playwright-cli fill <ref> "text"
playwright-cli type "text"
playwright-cli press Enter
  1. 捕获结果:
bash
playwright-cli screenshot
playwright-cli screenshot --filename=output.png
  1. 任务完成后务必关闭会话——这是必填步骤,完成任务后关闭指定的命名会话:
bash
playwright-cli -s=<session-name> close

Configuration

配置

If a
playwright-cli.json
exists in the working directory, use it automatically. If the user provides a path to a config file, use
--config path/to/config.json
. Otherwise, skip configuration — the env var and CLI defaults are sufficient.
json
{
  "browser": {
    "browserName": "chromium",
    "launchOptions": { "headless": true },
    "contextOptions": { "viewport": { "width": 1440, "height": 900 } }
  },
  "outputDir": "./screenshots"
}
如果工作目录中存在
playwright-cli.json
,工具会自动加载该配置。如果用户提供了配置文件路径,使用
--config path/to/config.json
参数加载。否则,无需配置——环境变量和CLI默认参数已足够使用。
json
{
  "browser": {
    "browserName": "chromium",
    "launchOptions": { "headless": true },
    "contextOptions": { "viewport": { "width": 1440, "height": 900 } }
  },
  "outputDir": "./screenshots"
}

Full Help

完整帮助文档

Run
playwright-cli --help
or
playwright-cli --help <command>
for detailed command usage.
See docs/playwright-cli.md for full documentation.
运行
playwright-cli --help
playwright-cli --help <command>
查看详细的命令用法。
查看docs/playwright-cli.md获取完整文档。