playwright-mcp
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseplaywright-mcp
playwright-mcp
Purpose
用途
This skill provides a Playwright-based MCP server for browser automation, enabling programmatic control of web pages via the MCP protocol. It focuses on tasks like navigating sites, interacting with elements, and filling forms, integrated with OpenClaw for AI-driven workflows.
本Skill提供一个基于Playwright的MCP服务器,用于浏览器自动化,支持通过MCP协议以编程方式控制网页。它专注于网站导航、元素交互和表单填写等任务,并与OpenClaw集成以实现AI驱动的工作流。
When to Use
使用场景
Use this skill for automating browser interactions in scenarios like web scraping, UI testing, or dynamic form submissions. It's ideal when you need remote browser control, such as in CI/CD pipelines, data extraction from JavaScript-heavy sites, or simulating user actions across multiple pages.
当你需要在网页爬取、UI测试或动态表单提交等场景中自动化浏览器交互时,可以使用本Skill。它非常适合需要远程浏览器控制的场景,例如CI/CD流水线、从JavaScript密集型网站提取数据,或者跨多个页面模拟用户操作。
Key Capabilities
核心功能
- Launch browsers (e.g., Chromium, Firefox) and manage sessions via MCP protocol.
- Interact with page elements: select, click, or type using methods like .
page.click('button') - Handle form filling and submissions: auto-populate fields and submit with .
page.fill('input[name="username"]', 'user123') - Support for asynchronous operations: wait for elements with .
page.waitForSelector('selector') - Error-resilient navigation: retry failed loads with built-in timeouts.
- Configurable via JSON files, e.g., {"browser": "chromium", "headless": true}.
- 通过MCP协议启动浏览器(如Chromium、Firefox)并管理会话。
- 与页面元素交互:使用等方法选择、点击或输入内容。
page.click('button') - 处理表单填写与提交:自动填充字段并通过提交表单。
page.fill('input[name="username"]', 'user123') - 支持异步操作:使用等待元素加载。
page.waitForSelector('selector') - 具备错误恢复能力的导航:内置超时机制,可重试加载失败的页面。
- 可通过JSON文件配置,例如{"browser": "chromium", "headless": true}。
Usage Patterns
使用模式
To use this skill, start the MCP server and send commands from OpenClaw. Always initialize with authentication via . Pattern 1: Launch a browser session and perform actions in sequence. Pattern 2: Use in loops for repetitive tasks, like form testing. For integration, wrap calls in try-catch blocks. Example pattern: Set up server with CLI, then use API endpoints to execute scripts.
$PLAYWRIGHT_MCP_API_KEY要使用本Skill,需启动MCP服务器并从OpenClaw发送命令。初始化时必须通过进行身份验证。模式1:启动浏览器会话并按顺序执行操作。模式2:在循环中用于重复任务,例如表单测试。集成时,将调用包裹在try-catch块中。示例模式:通过CLI设置服务器,然后使用API端点执行脚本。
$PLAYWRIGHT_MCP_API_KEYCommon Commands/API
常见命令/API
- CLI: Run to launch the server; add
playwright-mcp start --port 8080 --headlessfor verbose logging.--debug - API: POST to with JSON payload, e.g., {"action": "navigate", "url": "https://example.com"}.
/mcp/execute - Code snippet for basic navigation:
const response = fetch('http://localhost:8080/mcp/execute', { method: 'POST', headers: {'Authorization': `Bearer ${process.env.PLAYWRIGHT_MCP_API_KEY}`}, body: JSON.stringify({action: 'goto', url: 'https://example.com'}) }); - For element interaction: Use endpoint, e.g., POST with {"selector": '#id', "action": "click"}.
/mcp/interact - Config format: YAML or JSON, e.g., {"timeout": 30000, "retries": 3} in a file passed via .
--config path/to/config.json - Authentication: Always include in headers; check for 401 errors if missing.
$PLAYWRIGHT_MCP_API_KEY
- CLI:运行启动服务器;添加
playwright-mcp start --port 8080 --headless以启用详细日志。--debug - API:向发送POST请求,携带JSON负载,例如{"action": "navigate", "url": "https://example.com"}。
/mcp/execute - 基础导航代码片段:
const response = fetch('http://localhost:8080/mcp/execute', { method: 'POST', headers: {'Authorization': `Bearer ${process.env.PLAYWRIGHT_MCP_API_KEY}`}, body: JSON.stringify({action: 'goto', url: 'https://example.com'}) }); - 元素交互:使用端点,例如发送POST请求,携带{"selector": '#id', "action": "click"}。
/mcp/interact - 配置格式:YAML或JSON,例如在通过传入的文件中设置{"timeout": 30000, "retries": 3}。
--config path/to/config.json - 身份验证:请求头中必须包含;如果缺失,会返回401错误。
$PLAYWRIGHT_MCP_API_KEY
Integration Notes
集成说明
Integrate by running the server as a subprocess or via HTTP clients in OpenClaw. Set as an environment variable for authentication. For example, in OpenClaw scripts, import as a module and call functions like /mcp/ws--allow-origins *` to CLI. Test integrations with mock servers to simulate failures.
$PLAYWRIGHT_MCP_API_KEYmcpClient.execute({action: 'fill', selector: 'input', value: 'data'}). Use WebSockets for real-time updates on . Ensure compatibility with Node.js 14+; handle CORS by adding 可通过在OpenClaw中将服务器作为子进程运行,或通过HTTP客户端进行集成。将设置为环境变量以进行身份验证。例如,在OpenClaw脚本中,将其作为模块导入并调用等函数。使用WebSocket连接以获取实时更新。确保与Node.js 14+兼容;通过在CLI中添加解决CORS问题。使用模拟服务器测试集成以模拟故障场景。
$PLAYWRIGHT_MCP_API_KEYmcpClient.execute({action: 'fill', selector: 'input', value: 'data'})/mcp/ws--allow-origins *Error Handling
错误处理
Common errors include timeout exceptions (e.g., network delays) or selector failures; use before actions. For API errors, check response codes: 404 for invalid endpoints, 500 for server issues. Handle with try-catch in code, e.g.:
page.waitForTimeout(5000)try {
await page.click('nonexistent');
} catch (error) {
console.error('Element not found:', error.message);
// Retry or fallback
}Prescribe logging all errors with flag. For authentication failures, verify and retry. Use exponential backoff for transient errors like 429 (rate limit).
--debug$PLAYWRIGHT_MCP_API_KEY常见错误包括超时异常(如网络延迟)或选择器定位失败;在执行操作前可使用等待。对于API错误,检查响应代码:404表示端点无效,500表示服务器问题。在代码中使用try-catch块处理,例如:
page.waitForTimeout(5000)try {
await page.click('nonexistent');
} catch (error) {
console.error('Element not found:', error.message);
// 重试或执行回退逻辑
}建议使用标志记录所有错误。对于身份验证失败,验证后重试。对于429(速率限制)等临时错误,使用指数退避策略。
--debug$PLAYWRIGHT_MCP_API_KEYConcrete Usage Examples
具体使用示例
- Automate form filling: Start server with , then send API call to fill and submit a login form: POST
playwright-mcp start --port 8080with {"action": "fill", "selector": '#username', "value": "testuser", "then": "click('#submit')"}. This extracts data or verifies login success./mcp/execute - Web scraping task: Use in OpenClaw to navigate to a page and extract content: CLI command , then process the output for analysis.
playwright-mcp execute --url 'https://site.com' --script 'page.evaluate(() => document.querySelector("#data").textContent)'
- 自动化表单填写:使用启动服务器,然后发送API请求以填写并提交登录表单:向
playwright-mcp start --port 8080发送POST请求,携带{"action": "fill", "selector": '#username', "value": "testuser", "then": "click('#submit')"}。此操作可用于提取数据或验证登录是否成功。/mcp/execute - 网页爬取任务:在OpenClaw中使用本Skill导航到页面并提取内容:执行CLI命令,然后处理输出结果以进行分析。
playwright-mcp execute --url 'https://site.com' --script 'page.evaluate(() => document.querySelector("#data").textContent)'
Graph Relationships
关联关系
- Related to: browser-automation (depends on for core functionality), web-scraping (extends for data extraction), mcp-protocol (implements as base).
- Clusters: community (part of), automation-tools (links to for broader ecosystem).
- Dependencies: playwright-core (requires for browser control), mcp-server (bases on for protocol handling).
- 相关技能:browser-automation(核心功能依赖)、web-scraping(扩展用于数据提取)、mcp-protocol(作为基础协议实现)。
- 所属集群:community(社区成员)、automation-tools(链接至更广泛的生态系统)。
- 依赖项:playwright-core(用于浏览器控制)、mcp-server(基于其处理协议)。