Playwright MCP Server 🎭

Playwright MCP Server 🎭

site icon
2025.04.15 2976
TypeScript浏览器自动化测试工具网页抓取开发辅助浏览器自动化开发效率
Playwright MCP Server 是一个基于 Playwright 的浏览器自动化服务,通过 Model Context Protocol 协议提供网页交互能力。该服务使 LLMs(大型语言模型)能够与网页进行交互,包括截图、生成测试代码、网页抓取以及在真实浏览器环境中执行 JavaScript 等功能。
View on GitHub

Overview

基本能力

产品定位

Playwright MCP Server 是一个专注于浏览器自动化的服务,旨在为开发者和大型语言模型提供强大的网页交互能力。

核心功能

  • 浏览器自动化:使用 Playwright 进行网页交互
  • 截图功能:捕获网页截图
  • 测试代码生成:自动生成网页测试代码
  • 网页抓取:从网页中提取数据
  • JavaScript 执行:在真实浏览器环境中执行 JavaScript

适用场景

  • 自动化测试:生成和执行网页测试
  • 数据抓取:从网页中提取结构化数据
  • 网页监控:定期检查网页状态和内容
  • 开发辅助:为开发者提供浏览器环境下的调试能力

工具列表

  • Playwright:提供核心浏览器自动化能力
  • Jest:用于测试框架
  • Smithery:提供安装和管理功能

常见问题解答

  • 安装问题:可通过 npm、mcp-get 或 Smithery 多种方式安装
  • VS Code 集成:支持通过 CLI 或按钮直接安装到 VS Code
  • 配置使用:需要配置 Claude Desktop 以使用 Playwright 服务器

使用教程

使用依赖

需要安装 Node.js 环境以运行 npm 或 npx 命令

安装教程

有多种安装方式可选:

  1. 使用 npm:
npm install -g @executeautomation/playwright-mcp-server
  1. 使用 mcp-get:
npx @michaellatman/mcp-get@latest install @executeautomation/playwright-mcp-server
  1. 使用 Smithery:
npx -y @smithery/cli install @executeautomation/playwright-mcp-server --client claude
  1. VS Code 安装:
# For VS Code
code --add-mcp '{"name":"playwright","command":"npx","args":["@executeautomation/playwright-mcp-server"]}'

# For VS Code Insiders
code-insiders --add-mcp '{"name":"playwright","command":"npx","args":["@executeautomation/playwright-mcp-server"]}'

调试方式

项目使用 Jest 进行测试,可通过以下命令运行测试:

# 使用自定义脚本运行测试(带覆盖率)
node run-tests.cjs

# 使用 npm 脚本运行测试
npm test           # 不带覆盖率运行测试
npm run test:coverage  # 带覆盖率运行测试
npm run test:custom    # 使用自定义脚本运行测试

测试覆盖率报告将生成在 coverage 目录中。

许可证

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