MCP Playwright CDP

MCP Playwright CDP

site icon
2025.02.12 16
TypeScript浏览器自动化浏览器自动化
MCP Playwright CDP 是一个基于 Model Context Protocol 的服务,提供浏览器自动化能力,支持通过 Chrome DevTools Protocol (CDP) 连接现有 Chrome 实例。该服务使 LLMs 能够与网页交互、截图、在真实浏览器环境中执行 JavaScript。
View on GitHub

Overview

基本能力

产品定位

MCP Playwright CDP 是一个浏览器自动化工具,专为需要与网页交互的场景设计,支持通过 CDP 连接现有 Chrome 实例。

核心功能

  • 连接现有 Chrome 实例(通过 CDP)
  • 完整的浏览器自动化能力
  • 截图(整页或特定元素)
  • 全面的网页交互(导航、点击、表单填写)
  • 控制台日志监控
  • 在浏览器上下文中执行 JavaScript
  • 支持 HTTP API 测试

适用场景

  • 自动化网页测试
  • 网页内容抓取
  • 网页截图生成
  • 网页交互模拟
  • 控制台日志监控

工具列表

  • Playwright: 提供浏览器自动化能力
  • Chrome DevTools Protocol (CDP): 支持连接现有 Chrome 实例

常见问题解答

  1. 如何连接现有 Chrome 实例? 启动 Chrome 时添加 --remote-debugging-port=9222 参数,服务会自动尝试连接。

使用教程

使用依赖

确保已安装 Node.js 和 npm。

安装教程

通过 Smithery 安装

npx -y @smithery/cli install @lars-hagen/mcp-playwright-cdp --client claude

手动安装

npm install

配置

在 Claude Desktop 配置文件中添加:

{
  "mcpServers": {
    "playwright": {
      "command": "node",
      "args": ["/path/to/mcp-playwright/dist/index.js"]
    }
  }
}

替换 /path/to/mcp-playwright 为实际路径。

调试方式

  1. 启动 Chrome 并启用远程调试:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
  1. 服务会自动尝试连接运行中的 Chrome 实例。

许可证

该项目遵循 Other 开源许可条款,请参阅 Other 了解完整条款。