Skip to main content

连接到浏览器

🌐 Connecting to Browsers

不要启动一个新的浏览器,而是连接到已经运行的浏览器。

🌐 Instead of launching a new browser, connect to one that's already running.

按通道名称连接

🌐 Connect by channel name

通过其通道名称连接到正在运行的 Chrome 或 Edge。在目标浏览器中导航到 chrome://inspect/#remote-debugging 并启用“允许此浏览器实例的远程调试”。

🌐 Connect to a running Chrome or Edge by its channel name. Navigate to chrome://inspect/#remote-debugging in the target browser and enable "Allow remote debugging for this browser instance".

Chrome remote debugging settings at chrome://inspect/#remote-debugging
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest", "--cdp-endpoint=chrome"]
}
}
}

支持的通道:chromechrome-betachrome-devchrome-canarymsedgemsedge-betamsedge-devmsedge-canary

🌐 Supported channels: chrome, chrome-beta, chrome-dev, chrome-canary, msedge, msedge-beta, msedge-dev, msedge-canary.

这是最简单的连接方式——无需使用特殊标志启动 Chrome,也无需知道调试端口。

🌐 This is the simplest way to connect — no need to start Chrome with special flags or know the debugging port.

通过 CDP 端点连接

🌐 Connect via CDP endpoint

连接到任何具有 Chrome DevTools 协议端点的基于 Chromium 的浏览器:

🌐 Connect to any Chromium-based browser with a Chrome DevTools Protocol endpoint:

{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest", "--cdp-endpoint=http://localhost:9222"]
}
}
}

或者在配置文件中:

🌐 Or in the config file:

{
"browser": {
"cdpEndpoint": "http://localhost:9222"
}
}

适用于带有 --remote-debugging-port 的 Chrome/Chromium、Edge、Electron 应用以及云浏览器服务。

🌐 Works with Chrome/Chromium with --remote-debugging-port, Edge, Electron apps, and cloud browser services.

通过浏览器扩展连接

🌐 Connect via browser extension

Playwright 扩展 连接到你现有的浏览器标签页,重复使用你已登录的会话、Cookie 和已安装的扩展程序。

🌐 The Playwright Extension connects to your existing browser tabs, reusing your logged-in sessions, cookies, and installed extensions.

Playwright Extension in Chrome Web Store
  1. 在 Chrome 或 Edge 中安装扩展程序
  2. 配置 MCP 服务器:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest", "--extension"]
}
}
}

何时使用扩展模式

🌐 When to use extension mode

  • SSO / 2FA — 通过重复使用已认证的会话来跳过复杂的登录流程
  • 浏览器扩展 — 与依赖已安装扩展的页面进行交互
  • 已有标签页 — 自动化你已经打开的页面