剧作家React调试MCP
](https://www.npmjs.com/package/playwright-react-debug-mcp)  ](https://nodejs.org/)
使用Claude和Playwright在人工智能的帮助下调试React应用程序。
A. 模型上下文协议 (MCP)服务器,使Claude能够通过浏览器与实时web应用程序进行交互。导航页面、检查DOM、监视网络请求、调试React组件和分析错误——所有这些都是通过自然对话完成的。
______________________________________________________________________
为什么使用这个?
| 传统调试 | 使用Playwright React调试MCP |
|---|---|
| 手动重现问题 | “导航到/仪表板并检查错误” |
| 截图并粘贴到聊天中 | 克劳德看到实时页面并直接互动 |
| 复制粘贴控制台错误 | 自动捕获控制台日志 |
| 手动打开React DevTools | Claude使用state/props查询组件树 |
| 检查“网络”选项卡是否存在故障 | 所有HTTP流量都被监控和分析 |
______________________________________________________________________
特性
- 40个调试工具 跨越10个类别
- 浏览器控件 -导航、单击、填写表单、自动化用户流
- DOM检查 -元素细节、计算样式、文本提取
- 网络监控 -请求/响应正文、标头、时间
- 控制台捕获 -错误、警告、带过滤的日志
- React工具 -组件树、道具、状态、钩子检查
- 状态管理 -Redux、Zustand、React查询、上下文检查
- 演出 -渲染跟踪、慢速组件、Web重要信息
- 错误检测 -水合错误、错误边界、内存泄漏
- 无障碍 -WCAG风格审计、ARIA树检查
- 误差分析 -基于人工智能的分析,并提出修复建议
______________________________________________________________________
快速开始
安装
npm install -g playwright-react-debug-mcp
npx playwright install chromium配置Claude桌面
添加到 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"playwright-debug": {
"command": "npx",
"args": ["playwright-react-debug-mcp"]
}
}
}配置Claude代码
添加到您的项目 .mcp.json:
{
"mcpServers": {
"playwright-debug": {
"command": "npx",
"args": ["playwright-react-debug-mcp"],
"transport": "stdio"
}
}
}试试看
You: Navigate to https://example.com and take a screenshot
Claude: I'll navigate to the page and capture a screenshot.
[Browser opens, navigates, returns screenshot]
Done! The page shows...______________________________________________________________________
示例会话
You: Navigate to my app at localhost:3000/login and try logging in
with test@example.com
Claude: I'll navigate to the login page and fill in the credentials.
[Navigates, fills email/password, clicks submit]
The login failed. Let me check what happened:
- Console: "TypeError: Cannot read property 'token' of undefined"
- Network: POST /api/auth returned 200 but body is empty
- React: AuthProvider shows { isAuthenticated: false, error: null }
The API returns 200 without a token. The frontend expects response.data.token
but data is undefined. The error state isn't being set because the HTTP
status was 200.
Suggestions:
1. Backend should return { data: { token: "..." } } or proper error status
2. Frontend should validate response structure, not just HTTP status______________________________________________________________________
可用工具
导航与交互(11个工具)
| 工具 | 说明 |
|---|---|
navigate | 导航到具有等待条件的URL |
click | 点击元素(左/右/双) |
fill | 填写表单字段 |
select | 选择下拉选项 |
type | 逐个字符键入文本 |
hover | 将鼠标悬停在元素上 |
scroll | 滚动页面或元素进入视图 |
wait_for | 等待元素/导航 |
go_back | 浏览器返回 |
go_forward | 浏览器转发 |
reload | 重新加载页面 |
检查(3个工具)
| 工具 | 说明 |
|---|---|
get_dom | DOM树摘要 |
get_element | 元素细节与风格 |
get_text_content | 提取可见文本 |
网络(3个工具)
| 工具 | 说明 |
|---|---|
get_network | 使用筛选查看请求 |
get_request_detail | 完整的请求/响应详细信息 |
clear_network | 清除捕获的请求 |
控制台(2个工具)
| 工具 | 说明 |
|---|---|
get_console | 通过筛选查看日志 |
clear_console | 清除捕获的日志 |
React(4个工具)
| 工具 | 说明 |
|---|---|
get_react_tree | 带钩子的组件树 |
find_component | 按名称搜索组件 |
get_component_state | 详细状态/道具 |
collect_component_instances | 组件的所有实例 |
状态管理(4个工具)
| 工具 | 说明 |
|---|---|
get_redux_state | 冗余存储状态+操作 |
get_zustand_stores | 状态 store inspection |
get_react_query_cache | React查询缓存 |
get_context_values | React上下文值 |
性能(3个工具)
| 工具 | 说明 |
|---|---|
get_render_count | 组件渲染跟踪 |
get_slow_components | 组件检测缓慢 |
get_web_vitals | 核心网络生命体征(LCP、CLS等) |
错误检测(3个工具)
| 工具 | 说明 |
|---|---|
find_hydration_errors | SSR水合不匹配 |
get_error_boundaries | React错误边界 |
detect_memory_leaks | 内存泄漏指示器 |
可访问性(2个工具)
| 工具 | 说明 |
|---|---|
run_accessibility_audit | WCAG式审计 |
get_aria_tree | 可访问性树 |
高级(5个工具)
| 工具 | 说明 |
|---|---|
screenshot | 捕获页面或元素 |
evaluate_js | 执行JavaScript |
explain_error | AI错误分析 |
get_debug_summary | 页面状态概述 |
______________________________________________________________________
用例
交互式调试
What errors are on this page?
Why did the form submission fail?自动化测试
Fill the registration form and verify it submits successfully
Click through the checkout flow and check for errorsReact开发
Find the UserProfile component and show its state
What props are being passed to the Modal?
Collect all Button instances and compare their usageAPI集成
What requests were made when I clicked submit?
Show me the response from the failed API call______________________________________________________________________
配置
环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
MAX_CONSOLE_ENTRIES | 100 | 控制台日志缓冲区大小 |
MAX_NETWORK_ENTRIES | 100 | 网络请求缓冲区大小 |
PLAYWRIGHT_HEADLESS | false | 无头运行浏览器 |
{
"mcpServers": {
"playwright-debug": {
"command": "npx",
"args": ["playwright-react-debug-mcp"],
"env": {
"PLAYWRIGHT_HEADLESS": "true"
}
}
}
}______________________________________________________________________
发展
# Clone
git clone https://github.com/Lars-Albinsson/playwright-react-debug-mcp
cd playwright-react-debug-mcp
# Install
npm install
npx playwright install chromium
# Build
npm run build
# Run
npm start
# Watch mode
npm run dev______________________________________________________________________
文档
______________________________________________________________________
需求
- Node.js 18+
- 剧作家(铬)
- 克劳德桌面或克劳德代码
______________________________________________________________________
贡献
欢迎投稿!看 贡献.md 作为指导方针。
______________________________________________________________________
许可证
MIT许可证-请参阅 许可证 了解详情。
______________________________________________________________________
