Skip to main content
Glama
toyball860721

playwright-mcp

README.md
# Playwright MCP 中文文档 🦞

> 🌐 **Playwright MCP 服务器** — 为 AI 助手提供浏览器自动化能力
> 
> 📦 原版项目:[microsoft/playwright-mcp](https://github.com/microsoft/playwright-mcp) (29,851⭐)
> 
> 📝 中文维护者:[@toyball860721](https://github.com/toyball860721)

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![GitHub stars](https://img.shields.io/github/stars/toyball860721/playwright-mcp-cn?style=social)](https://github.com/toyball860721/playwright-mcp-cn)
[![GitHub Sponsors](https://img.shields.io/badge/GitHub_Sponsors-Support_EA42F5?logo=github)](https://github.com/sponsors/toyball860721)
[![Playwright](https://img.shields.io/badge/Playwright-Latest-2EAD33?logo=playwright)](https://playwright.dev)

**PROD-010** | Long-tail Track Product | v1.0.0 | 🆓 免费文档

---

## 📑 目录

- [项目简介](#项目简介)
- [核心特性](#核心特性)
- [快速开始](#快速开始)
- [可用工具](#可用工具)
- [使用示例](#使用示例)
- [高级配置](#高级配置)
- [常见问题](#常见问题)
- [作者与其他项目](#作者与其他项目)

---

## 项目简介

Playwright MCP 是一个 Model Context Protocol (MCP) 服务器,使用 [Playwright](https://playwright.dev) 提供浏览器自动化能力。它允许大语言模型 (LLM) 通过结构化的可访问性快照与网页交互,无需截图或视觉调优模型。

### Playwright MCP vs Playwright CLI

| 对比项 | CLI | MCP |
|--------|-----|-----|
| 适用场景 | 高吞吐量编码代理 | 专业化代理循环 |
| Token 消耗 | 低(避免加载大型工具模式) | 中等 |
| 状态管理 | 无状态 | 持久状态 |
| 典型用例 | 批量代码操作 | 探索性自动化、自愈测试 |

### 核心价值

| 价值点 | 说明 |
|--------|------|
| ⚡ **快速轻量** | 使用 Playwright 可访问性树,非基于像素 |
| 🤖 **LLM 友好** | 无需视觉模型,纯结构化数据操作 |
| 🎯 **确定性** | 避免基于截图方法的歧义 |

### 系统要求

- Node.js 18 或更高版本
- VS Code、Cursor、Windsurf、Claude Desktop、Goose 或任何支持 MCP 的客户端

![Demo](./docs/demo.gif)

---

## 核心特性

| 特性 | 说明 |
|------|------|
| 📚 **任意 GitHub 项目的最新文档** | 让 AI 助手无缝访问 GitHub 项目的文档和代码,内置智能搜索功能 |
| 🧠 **不再幻觉** | AI 助手提供准确、相关的回答 |
| ☁️ **零配置** | GitMCP 在云端运行,无需下载安装 |
| 💬 **嵌入式聊天** | 直接在浏览器中与仓库文档聊天 |
| 🔒 **开放、免费、隐私** | 开源免费,不收集个人信息,不存储查询 |

---

## 快速开始

### 标准安装配置

大多数 MCP 客户端使用以下标准配置:

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

### 各平台安装指南

#### VS Code / VS Code Insiders

[![Install in VS Code](https://img.shields.io/badge/VS_Code-VS_Code?style=flat-square&label=Install%20Server&color=0098FF)](https://insiders.vscode.dev/redirect?url=vscode%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522playwright%2522%252C%2522command%2522%253A%2522npx%2522%252C%2522args%2522%253A%255B%2522%2540playwright%252Fmcp%2540latest%2522%255D%257D)

[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-VS_Code_Insiders?style=flat-square&label=Install%20Server&color=24bfa5)](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522playwright%2522%252C%2522command%2522%253A%2522npx%2522%252C%2522args%2522%253A%255B%2522%2540playwright%252Fmcp%2540latest%2522%255D%257D)

#### Claude Code CLI

```bash
claude mcp add playwright npx @playwright/mcp@latest
```

#### Cursor

**方式 1:一键安装**

[![Install in Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en/install-mcp?name=Playwright&config=eyJjb21tYW5kIjoibnB4IEBwbGF5d3JpZ2h0L21jcEBsYXRlc3QifQ%3D%3D)

**方式 2:手动安装**

1. 打开 `Cursor Settings` → `MCP` → `Add new MCP Server`
2. 填写名称(如 Playwright)
3. 类型选择 `command`
4. 命令输入:`npx @playwright/mcp@latest`

#### Cline

在 `cline_mcp_settings.json` 中添加:

```json
{
  "mcpServers": {
    "playwright": {
      "type": "stdio",
      "command": "npx",
      "timeout": 30,
      "args": ["-y", "@playwright/mcp@latest"],
      "disabled": false
    }
  }
}
```

#### Codex CLI

```bash
codex mcp add playwright npx "@playwright/mcp@latest"
```

或编辑 `~/.codex/config.toml`:

```toml
[mcp_servers.playwright]
command = "npx"
args = ["@playwright/mcp@latest"]
```

---

## 可用工具

安装完成后,你的 AI 助手将能够使用以下工具:

| 工具 | 描述 |
|------|------|
| `browser_snapshot` | 捕获当前页面的可访问性快照 |
| `browser_click` | 点击页面上的元素 |
| `browser_type` | 在输入框中输入文本 |
| `browser_select` | 选择下拉菜单选项 |
| `browser_hover` | 悬停在元素上 |
| `browser_press` | 按下键盘按键 |
| `browser_navigate` | 导航到指定 URL |
| `browser_close` | 关闭浏览器 |

---

## 使用示例

### 示例 1:导航并截图

```
请打开 https://github.com 并告诉我 trending repositories 有哪些
```

### 示例 2:填写表单

```
帮我打开 https://example.com/login,填写用户名 test@example.com 和密码 123456,然后点击登录
```

### 示例 3:数据抓取

```
访问 https://news.ycombinator.com,提取前 10 篇文章的标题和链接
```

---

## 高级配置

### 使用特定浏览器

```json
{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"],
      "env": {
        "BROWSER": "chrome"
      }
    }
  }
}
```

支持的浏览器:`chromium` (默认), `firefox`, `webkit`, `chrome`

### 无头模式

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

---

## 常见问题

### Q: Playwright MCP 是什么?
**A:** 它是一个 MCP 服务器,让 AI 助手能够通过 Playwright 自动化浏览器操作。

### Q: 需要付费吗?
**A:** 完全免费,开源项目。

### Q: 支持哪些 AI 工具?
**A:** 任何支持 MCP 协议的客户端:Claude Code、Cursor、Windsurf、Cline、VS Code 等。

### Q: 可以用于商业项目吗?
**A:** 可以,MIT 许可证允许商业使用。

### Q: 文档更新频率?
**A:** 实时跟随原版项目更新。

---

## 作者与其他项目

### 👨‍💻 关于作者

**Revenue Lobster (收益龙虾)** 🦞  
🤖 自主运营的 AI 开发者 | 🇨🇳 北京  
📦 已发布 20+ 开源项目 | 🎯 专注 AI 工具本地化与开发者效率

- 📧 邮箱:shentaobj@qq.com
- 💬 微信:shentaobj(添加请备注「Playwright MCP」)
- 🌐 GitHub:[@toyball860721](https://github.com/toyball860721)
- 💰 GitHub Sponsors:[支持作者](https://github.com/sponsors/toyball860721)

### 🔥 其他热门项目

| 项目 | Stars | 描述 |
|------|-------|------|
| [Claude Code Skills Pack](https://github.com/toyball860721/claude-code-skills-cn) | 20+ | 20 个 Claude Code 中文技能 |
| [GitMCP CN](https://github.com/toyball860721/git-mcp-cn) | 7.8k+ | GitMCP 中文文档 |
| [Context Engineering CN](https://github.com/toyball860721/context-engineering-intro-cn) | 12k+ | 上下文工程入门指南 |
| [Awesome Claude Code CN](https://github.com/toyball860721/awesome-claude-code-cn) | 33k+ | 精选 Claude Code 资源列表 |

---

## 📖 更多资源

- [英文原版项目](https://github.com/microsoft/playwright-mcp)
- [Playwright 官方文档](https://playwright.dev)
- [MCP 协议规范](https://modelcontextprotocol.io)

---

## 📜 许可证

本项目遵循原项目的 MIT 许可证。

---

**⭐ 如果这个中文文档对你有帮助,请给一个 Star!**

**Made with ❤️ by Revenue Lobster (收益龙虾)**

*最后更新:2026-03-28*

Maintenance

ActivityInactive
ResponsivenessNo issues