个人资料与状态
🌐 Profile & State
Playwright MCP 通过配置文件管理浏览器状态。默认情况下,登录状态和 Cookie 会在会话之间自动保持。
🌐 Playwright MCP manages browser state through profiles. By default, login state and cookies persist between sessions automatically.
配置文件模式
🌐 Profile modes
持久(默认)
🌐 Persistent (default)
登录状态、Cookies 和本地存储在会话之间都会被保留。配置文件目录的名称包含浏览器渠道和客户端工作区目录的哈希值,所以不同的项目会自动获得独立的配置文件。
🌐 Login state, cookies, and local storage are preserved between sessions. The profile directory name includes the browser channel and a hash of the client's workspace directory, so different projects get separate profiles automatically.
| 平台 | 默认位置 |
|---|---|
| macOS | ~/Library/Caches/ms-playwright-mcp/mcp-{channel}-{workspace-hash} |
| Linux | ~/.cache/ms-playwright-mcp/mcp-{channel}-{workspace-hash} |
| Windows | %LOCALAPPDATA%\ms-playwright-mcp\mcp-{channel}-{workspace-hash} |
覆盖配置文件位置:
🌐 Override the profile location:
["@playwright/mcp@latest", "--user-data-dir=/path/to/profile"]
一个配置文件一次只能被一个浏览器使用。如果它已经被锁定,服务器就无法启动。
🌐 A profile can only be used by one browser at a time. If it is already locked, the server fails to start.
Playwright CLI 默认使用 内存 状态(Cookies 会在命令间保留,但关闭浏览器后会丢失)。在这里使用 --persistent 可以启用磁盘持久化。查看 会话与仪表板 了解 CLI 专用的会话管理。
孤立的
🌐 Isolated
每次会话都是全新的,没有保存的状态,也不会写入磁盘。传入 --isolated 来启用:
🌐 Each session starts fresh with no saved state, and nothing is written to disk. Pass --isolated to enable:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest", "--isolated"]
}
}
}
--isolated 不能与 --user-data-dir 结合。使用 --storage-state 将初始状态加载到隔离会话中:
["@playwright/mcp@latest", "--isolated", "--storage-state=./auth-state.json"]
浏览器扩展
🌐 Browser extension
连接到你现有的浏览器标签页,而不是启动新的浏览器。请参见 浏览器扩展。
🌐 Connect to your existing browser tabs instead of launching a new browser. See Browser Extension.
保存和恢复状态
🌐 Saving and restoring state
使用 storage 功能保存已认证状态,以便在会话之间重复使用:
🌐 Save authenticated state for reuse across sessions with the storage capability:
// Login, then save
→ browser_storage_state { filename: "auth-state.json" }
- [Storage state](auth-state.json)
// Later: restore
→ browser_set_storage_state { filename: "auth-state.json" }
或者在服务器启动时使用 --storage-state 自动加载状态。完整工作流程请参见 存储与认证。
🌐 Or load state automatically on server startup with --storage-state. See Storage & Authentication for the full workflow.