選項
首頁首頁 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 伺服器可透過命令列呼叫進行控制,以與透過無障礙快照識別出的特定元素進行互動。

此技能非常適合需要自動化網頁互動的開發人員和自動化工程師、進行 UI 測試的品質保證專業人員、從動態網站擷取資料的資料工程師,以及任何需要實際瀏覽器渲染與互動的網頁應用程式工作者。 當任務涉及表單提交、點擊介面、等待動態內容載入,或任何需要瀏覽器 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.md 20.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