会话与仪表板
🌐 Sessions & Dashboard
CLI 默认会将浏览器配置文件保存在内存中——会话期间 CLI 调用之间会保留 cookie 和存储状态,但浏览器关闭时会丢失。
🌐 The CLI keeps the browser profile in memory by default — cookies and storage state are preserved between CLI calls within a session but lost when the browser closes.
命名会话
🌐 Named sessions
运行多个独立的浏览器实例:
🌐 Run multiple isolated browser instances:
playwright-cli open https://playwright.nodejs.cn
playwright-cli -s=example open https://example.com --persistent
playwright-cli list
# Active sessions:
# -> default (https://playwright.nodejs.cn)
# example (https://example.com) [persistent]
每个会话都有自己的浏览器实例、Cookies、本地存储、导航历史和控制台日志。
🌐 Each session has its own browser instance, cookies, localStorage, navigation history, and console log.
环境变量
🌐 Environment variable
PLAYWRIGHT_CLI_SESSION=todo-app claude .
该代理会话中的所有 playwright-cli 命令都使用 todo-app 浏览器实例。
🌐 All playwright-cli commands in that agent session use the todo-app browser instance.
配置文件持久性
🌐 Profile persistence
内存中(默认)
🌐 In-memory (default)
Cookie 和存储在会话中的命令之间会持续存在,但在浏览器关闭时会丢失:
🌐 Cookies and storage persist between commands within a session but are lost when the browser closes:
playwright-cli open https://example.com
持久化到磁盘
🌐 Persistent to disk
配置文件已保存到磁盘,并且在浏览器重启后仍然存在。这相当于 Playwright MCP 中的默认持久模式。
🌐 Profile is saved to disk and survives browser restarts. This is equivalent to the default persistent mode in Playwright MCP.
playwright-cli open https://example.com --persistent
默认持久配置文件位置:
🌐 Default persistent profile locations:
| 平台 | 默认位置 |
|---|---|
| macOS | ~/Library/Caches/ms-playwright/mcp-{channel}-profile |
| Linux | ~/.cache/ms-playwright/mcp-{channel}-profile |
| Windows | %LOCALAPPDATA%\ms-playwright\mcp-{channel}-profile |
自定义目录
🌐 Custom directory
playwright-cli open https://example.com --profile=./my-profile
会话管理
🌐 Session management
playwright-cli list # list all sessions
playwright-cli -s=name close # close a specific session
playwright-cli close-all # close all browsers
playwright-cli kill-all # force kill (for unresponsive browsers)
playwright-cli -s=name delete-data # delete stored profile data
仪表板
🌐 Dashboard
打开可视化仪表板以观察和控制所有正在运行的会话:
🌐 Open a visual dashboard to observe and control all running sessions:
playwright-cli show
仪表板提供:
🌐 The dashboard provides:
| 查看 | 描述 |
|---|---|
| 会话网格 | 所有活动会话,带实时屏幕投射、名称、网址和标题。点击以放大。 |
| 会话详情 | 带有标签栏、导航控件和完整远程鼠标/键盘输入的实时视口。按 Esc 键释放。 |
使用场景:
🌐 Use cases:
- 观看编码代理在后台自动操作浏览器
- 当代理被验证码或双重身份验证卡住时接管
- 关闭过期会话或从界面删除数据
保存和恢复状态
🌐 Saving and restoring state
保存身份验证状态以便在会话之间重用:
🌐 Save authenticated state for reuse across sessions:
# Login, then save state
playwright-cli state-save auth-state.json
# Later: restore state in a new session
playwright-cli state-load auth-state.json
工作流程:隔离测试
🌐 Workflow: isolated testing
# Admin session
playwright-cli -s=admin open https://app.example.com --persistent
playwright-cli -s=admin state-load admin-auth.json
playwright-cli -s=admin goto /admin/settings
# User session
playwright-cli -s=user open https://app.example.com --persistent
playwright-cli -s=user state-load user-auth.json
playwright-cli -s=user goto /dashboard
# Monitor both
playwright-cli show