选项
首页首页 Skill 浏览器自动化 browsing-with-playwright

browsing-with-playwright

bilalmk/todo_correct bilalmk/todo_correct

使用 Playwright MCP 实现浏览器自动化。浏览网站、填写表单、点击元素、 截图以及提取数据。当任务涉及网页浏览、表单提交、 网页抓取、UI 测试或任何浏览器交互时,请使用此工具。若仅需获取静态 内容,请勿使用(建议改用 curl/wget)。

...展开全部
15
更新时间 2026-08-25

关于browsing-with-playwright

browsing-with-playwright 技能通过Playwright MCP服务器实现浏览器自动化,使您能够通过编程方式控制网页浏览器,以完成需要实际浏览器交互的任务。 该技能解决了与动态网页内容交互、填写表单、点击按钮、从大量使用 JavaScript 的网站中提取数据以及执行 UI 测试等问题——在所有这些场景中,简单的 HTTP 请求都难以胜任,因为它们无法执行 JavaScript 或与 DOM 进行交互。

该技能提供了全面的浏览器控制功能,包括导航、元素交互(点击、输入、表单填写、下拉菜单选择)、通过无障碍快照和屏幕截图检查页面状态、等待动态内容以及执行 JavaScript。 它通过共享的浏览器上下文在多次操作中保持浏览器状态,因此适用于登录账户、浏览多页表单或从需要交互的网站抓取数据等多步骤工作流。MCP 服务器可通过命令行调用进行控制,以与通过无障碍快照识别的特定元素进行交互。

该技能非常适合需要自动化 Web 交互的开发人员和自动化工程师、进行 UI 测试的 QA 专业人员、从动态网站抓取数据的工程师,以及任何需要实际浏览器渲染和交互的 Web 应用程序从业者。 当任务涉及表单提交、点击界面、等待动态内容加载,或任何需要浏览器 JavaScript 引擎和渲染能力的场景时,请使用此技能。对于简单的静态内容抓取,curl 或 wget 等传统工具仍然更为高效。

常见问题

何时应使用此技能而非简单的 HTTP 请求?

当您需要与需要执行 JavaScript 的动态网页内容交互、填写表单、点击按钮、等待内容加载,或执行任何基于浏览器的交互时,请使用此技能。对于无需浏览器交互的静态内容获取,请使用 curl 或 wget。

为什么 --shared-browser-context 标志很重要?

--shared-browser-context 标志可在多次调用 mcp-client.py 时保持浏览器状态(Cookie、localStorage、会话数据)。若不使用该标志,每次调用都会以全新的浏览器上下文开始,导致操作之间登录会话及其他状态数据丢失。

如何与页面上的特定元素进行交互?

首先,使用 browser_snapshot 获取页面的辅助功能树,该函数会返回元素引用(如 'e42'、'e15')。然后在交互命令(如 browser_click、browser_type 或 browser_fill_form)中使用这些引用来定位特定元素。

何时应使用 browser_run_code 代替单独的命令?

对于需要原子性执行(全有或全无)的复杂多步骤工作流,请使用 `browser_run_code`。这比多次单独调用更高效,并确保整个操作作为一个整体成功或失败。

何时应停止 Playwright 服务器?

当浏览器自动化任务完成后,请停止服务器以释放资源。若需依次执行多个浏览器任务,请保持服务器运行。如果浏览器无响应,请停止并重启服务器。

所有文件

6个文件scripts/mcp-client.py16.9KB查看SKILL.md4.9KB查看scripts/stop-server.sh0.9KB查看references/playwright-tools.md20.7KB 查看scripts/verify.py 0.5KB 查看scripts/start-server.sh 0.7 KB 查看
在 GitHub 上查看

Automate browser interactions via Playwright MCP server.

Server Lifecycle

Start Server

# Using helper script (recommended)bash scripts/start-server.sh# Or manuallynpx @playwright/mcp@latest --port 8808 --shared-browser-context &

Stop Server

# Using helper script (closes browser first)bash scripts/stop-server.sh# Or manuallypython3 scripts/mcp-client.py call -u http://localhost:8808 -t browser_close -p '{}'pkill -f "@playwright/mcp"

When to Stop

  • End of task: Stop when browser work is complete
  • Long sessions: Keep running if doing multiple browser tasks
  • Errors: Stop and restart if browser becomes unresponsive

Important: The --shared-browser-context flag is required to maintain browser state across multiple mcp-client.py calls. Without it, each call gets a fresh browser context.

Quick Reference

Navigation

# Go to URLpython3 scripts/mcp-client.py call -u http://localhost:8808 -t browser_navigate \  -p '{"url": "https://example.com"}'# Go backpython3 scripts/mcp-client.py call -u http://localhost:8808 -t browser_navigate_back -p '{}'

Get Page State

# Accessibility snapshot (returns element refs for clicking/typing)python3 scripts/mcp-client.py call -u http://localhost:8808 -t browser_snapshot -p '{}'# Screenshotpython3 scripts/mcp-client.py call -u http://localhost:8808 -t browser_take_screenshot \  -p '{"type": "png", "fullPage": true}'

Interact with Elements

Use ref from snapshot output to target elements:

# Click elementpython3 scripts/mcp-client.py call -u http://localhost:8808 -t browser_click \  -p '{"element": "Submit button", "ref": "e42"}'# Type textpython3 scripts/mcp-client.py call -u http://localhost:8808 -t browser_type \  -p '{"element": "Search input", "ref": "e15", "text": "hello world", "submit": true}'# Fill form (multiple fields)python3 scripts/mcp-client.py call -u http://localhost:8808 -t browser_fill_form \  -p '{"fields": [{"ref": "e10", "value": "[email protected]"}, {"ref": "e12", "value": "password123"}]}'# Select dropdownpython3 scripts/mcp-client.py call -u http://localhost:8808 -t browser_select_option \  -p '{"element": "Country dropdown", "ref": "e20", "values": ["US"]}'

Wait for Conditions

# Wait for text to appearpython3 scripts/mcp-client.py call -u http://localhost:8808 -t browser_wait_for \  -p '{"text": "Success"}'# Wait for time (ms)python3 scripts/mcp-client.py call -u http://localhost:8808 -t browser_wait_for \  -p '{"time": 2000}'

Execute JavaScript

python3 scripts/mcp-client.py call -u http://localhost:8808 -t browser_evaluate \  -p '{"function": "return document.title"}'

Multi-Step Playwright Code

For complex workflows, use browser_run_code to run multiple actions in one call:

python3 scripts/mcp-client.py call -u http://localhost:8808 -t browser_run_code \  -p '{"code": "async (page) => { await page.goto(\"https://example.com\"); await page.click(\"text=Learn more\"); return await page.title(); }"}'

Tip: Use browser_run_code for complex multi-step operations that should be atomic (all-or-nothing).

Workflow: Form Submission

  1. Navigate to page
  2. Get snapshot to find element refs
  3. Fill form fields using refs
  4. Click submit
  5. Wait for confirmation
  6. Screenshot result

Workflow: Data Extraction

  1. Navigate to page
  2. Get snapshot (contains text content)
  3. Use browser_evaluate for complex extraction
  4. Process results

Verification

Run: python3 scripts/verify.py

Expected: ✓ Playwright MCP server running

If Verification Fails

  1. Run diagnostic: pgrep -f "@playwright/mcp"
  2. Check: Server process running on port 8808
  3. Try: bash scripts/start-server.sh
  4. Stop and report if still failing - do not proceed with downstream steps

Tool Reference

See references/playwright-tools.md for complete tool documentation.

Troubleshooting

IssueSolution
Element not foundRun browser_snapshot first to get current refs
Click failsTry browser_hover first, then click
Form not submittingUse "submit": true with browser_type
Page not loadingIncrease wait time or use browser_wait_for
Server not respondingStop and restart: bash scripts/stop-server.sh && bash scripts/start-server.sh

安装 browsing-with-playwright

下载技能文件并将其解压到 .claude/skills/ 目录中。

下载ZIP

克隆仓库并复制技能文件到您的项目中。

git clone https://github.com/bilalmk/todo_correct/blob/main/.claude/skills/mjs/browsing-with-playwright/SKILL.md # Copy SKILL.md to your .claude/skills/ directory

复制 复制
快速设置: 将技能文件夹复制到 .claude/skills/ 目录下,Claude 会自动检测并使用该技能。

相关技能

playwright-cli
更新时间 2026-06-29
frontend-testing-best-practices
更新时间 2026-07-07
Playwright Browser Automation
更新时间 2026-06-29
playwright-generate-test
更新时间 2026-06-29
OR