Skip to main content

个人资料与状态

🌐 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 localStorage are preserved between sessions. Each project gets a separate profile automatically based on the workspace.

平台默认位置
macOS~/Library/Caches/ms-playwright/mcp-{channel}-profile
Linux~/.cache/ms-playwright/mcp-{channel}-profile
Windows%LOCALAPPDATA%\ms-playwright\mcp-{channel}-profile

覆盖配置文件位置:

🌐 Override the profile location:

["@playwright/mcp@latest", "--user-data-dir=/path/to/profile"]
note

CLI 默认使用内存中状态(Cookie 在命令之间保留,但在浏览器关闭时丢失)。使用 --persistent 启用磁盘持久化。有关 CLI 特定会话管理,请参见 会话与仪表板

孤立的

🌐 Isolated

每个会话都是全新开始,没有保存的状态。传递 --isolated 来启用:

🌐 Each session starts fresh with no saved state. Pass --isolated to enable:

{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest", "--isolated"]
}
}
}

使用 --storage-state 将初始状态加载到隔离会话中:

🌐 Load initial state into an isolated session with --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

保存身份验证状态以便在会话之间重用:

🌐 Save authenticated state for reuse across sessions:

// Login, then save
→ browser_storage_state
State saved to: auth-state.json

// Later: restore
→ browser_set_storage_state { path: "./auth-state.json" }

或者在服务器启动时使用 --storage-state 自动加载状态。完整工作流程请参见 存储与认证

🌐 Or load state automatically on server startup with --storage-state. See Storage & Authentication for the full workflow.