🛠️ Playwright (Automation + MCP + Scraper)
Playwrightは、Webブラウザの自動操作やWebサイトからのデータ抽出を可能にし、フォーム入力やスクリーンショット撮影、テスト実行まで幅広く対応するSkillです。
📜 元の英語説明(参考)
Browser automation and web scraping with Playwright. Forms, screenshots, data extraction. Works standalone or via MCP. Testing included.
🇯🇵 日本人クリエイター向け解説
Playwrightは、Webブラウザの自動操作やWebサイトからのデータ抽出を可能にし、フォーム入力やスクリーンショット撮影、テスト実行まで幅広く対応するSkillです。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o playwright-automation-mcp-scraper.zip https://jpskill.com/download/5230.zip && unzip -o playwright-automation-mcp-scraper.zip && rm playwright-automation-mcp-scraper.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/5230.zip -OutFile "$d\playwright-automation-mcp-scraper.zip"; Expand-Archive "$d\playwright-automation-mcp-scraper.zip" -DestinationPath $d -Force; ri "$d\playwright-automation-mcp-scraper.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
playwright-automation-mcp-scraper.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
playwright-automation-mcp-scraperフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
💬 こう話しかけるだけ — サンプルプロンプト
- › Playwright (Automation + MCP + を使って、最小構成のサンプルコードを示して
- › Playwright (Automation + MCP + の主な使い方と注意点を教えて
- › Playwright (Automation + MCP + を既存プロジェクトに組み込む方法を教えて
これをClaude Code に貼るだけで、このSkillが自動発動します。
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
[スキル名] Playwright (自動化 + MCP + スクレイパー)
使用する場面
このスキルは、以下の必要がある場合に使用します。
- ウェブサイトをスクレイピングする (静的またはJavaScriptでレンダリングされたもの)
- フォーム入力を自動化する (ログイン、チェックアウト、データ入力)
- ウェブアプリケーションをテストする (E2Eテスト、ビジュアルリグレッション)
- ウェブページのスクリーンショットやPDFを撮る
- テーブル、リスト、動的コンテンツからデータを抽出する
決定マトリックス
| シナリオ | 方法 | 速度 |
|---|---|---|
| 静的HTML | web_fetch ツール |
⚡ 最速 |
| JavaScriptレンダリング | Playwright direct | 🚀 速い |
| AIエージェント自動化 | MCP server | 🤖 統合済み |
| E2Eテスト | @playwright/test | ✅ 完全なフレームワーク |
クイックリファレンス
| タスク | ファイル |
|---|---|
| E2Eテストパターン | testing.md |
| CI/CD統合 | ci-cd.md |
| 失敗のデバッグ | debugging.md |
| ウェブスクレイピングパターン | scraping.md |
| セレクター戦略 | selectors.md |
コアルール
waitForTimeout()は絶対に使用しない - 常に特定の条件(要素、URL、ネットワーク)を待ちます。- 常にブラウザを閉じる - メモリリークを防ぐために
browser.close()を呼び出します。 - ロールセレクターを優先する -
getByRole()はCSSよりもUIの変更に強く対応します。 - 動的コンテンツを処理する - 要素を操作する前に
waitFor()を使用します。 - 認証状態を保持する -
storageStateを使用してログインセッションを保存し、再利用します。
クイックスタート - 一般的なタスク
ページのスクレイピング
const { chromium } = require('playwright');
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
const text = await page.locator('body').textContent();
await browser.close();
フォームの入力と送信
await page.goto('https://example.com/login');
await page.getByLabel('Email').fill('user@example.com');
await page.getByLabel('Password').fill('secret');
await page.getByRole('button', { name: 'Sign in' }).click();
await page.waitForURL('**/dashboard');
スクリーンショットの撮影
await page.goto('https://example.com');
await page.screenshot({ path: 'screenshot.png', fullPage: true });
テーブルデータの抽出
const rows = await page.locator('table tr').all();
const data = [];
for (const row of rows) {
const cells = await row.locator('td').allTextContents();
data.push(cells);
}
セレクターの優先順位
| 優先順位 | 方法 | 例 |
|---|---|---|
| 1 | getByRole() |
getByRole('button', { name: 'Submit' }) |
| 2 | getByLabel() |
getByLabel('Email') |
| 3 | getByPlaceholder() |
getByPlaceholder('Search...') |
| 4 | getByTestId() |
getByTestId('submit-btn') |
| 5 | locator() |
locator('.class') - 最後の手段 |
よくある落とし穴
| 落とし穴 | 修正策 |
|---|---|
| 要素が見つからない | 操作する前に await locator.waitFor() を追加する |
| クリックが不安定 | click({ force: true }) を使用するか、state: 'visible' を待つ |
| CIでのタイムアウト | タイムアウトを増やす、ビューポートサイズがローカルと一致するか確認する |
| テスト間で認証が失われる | storageState を使用してクッキーを保持する |
SPAが networkidle に到達しない |
代わりに特定のDOM要素を待つ |
| 403 Forbidden | サイトがヘッドレスをブロックしているか確認する; headless: false を試す |
| ロード後に空白ページ | 待機時間を増やすか、waitUntil: 'networkidle' を使用する |
セッションの処理
// ログイン後にセッションを保存
await page.context().storageState({ path: 'auth.json' });
// 新しいコンテキストでセッションを再利用
const context = await browser.newContext({ storageState: 'auth.json' });
MCP統合
Model Context Protocolを使用するAIエージェント向け:
npm install -g @playwright/mcp
npx @playwright/mcp --headless
MCPツールリファレンス
| ツール | 説明 |
|---|---|
browser_navigate |
URLへ移動 |
browser_click |
セレクターで要素をクリック |
browser_type |
入力欄にテキストを入力 |
browser_select_option |
ドロップダウンオプションを選択 |
browser_get_text |
テキストコンテンツを取得 |
browser_evaluate |
JavaScriptを実行 |
browser_snapshot |
アクセシブルなページスナップショットを取得 |
browser_close |
ブラウザコンテキストを閉じる |
browser_choose_file |
ファイルをアップロード |
browser_press |
キーボードキーを押す |
MCPサーバーオプション
--headless # UIなしで実行
--browser chromium # chromium|firefox|webkit
--viewport-size 1920x1080
--timeout-action 10000 # アクションタイムアウト (ms)
--timeout-navigation 30000
--allowed-hosts example.com,api.example.com
--save-trace # デバッグ用にトレースを保存
--save-video 1280x720 # ビデオを録画
インストール
npm init playwright@latest
# または既存のプロジェクトに追加
npm install -D @playwright/test
npx playwright install chromium
関連スキル
ユーザーが確認した場合、clawhub install <slug> でインストールしてください:
puppeteer- 代替のブラウザ自動化 (Chromeに特化)scrape- 一般的なウェブスクレイピングのパターンと戦略web- ウェブ開発の基礎とHTTP処理
フィードバック
- 役立った場合:
clawhub star playwright - 最新情報を入手:
clawhub sync
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
When to Use
Use this skill when you need to:
- Scrape a website (static or JavaScript-rendered)
- Automate form filling (login, checkout, data entry)
- Test a web application (E2E tests, visual regression)
- Take screenshots or PDFs of web pages
- Extract data from tables, lists, or dynamic content
Decision Matrix
| Scenario | Method | Speed |
|---|---|---|
| Static HTML | web_fetch tool |
⚡ Fastest |
| JavaScript-rendered | Playwright direct | 🚀 Fast |
| AI agent automation | MCP server | 🤖 Integrated |
| E2E testing | @playwright/test | ✅ Full framework |
Quick Reference
| Task | File |
|---|---|
| E2E testing patterns | testing.md |
| CI/CD integration | ci-cd.md |
| Debugging failures | debugging.md |
| Web scraping patterns | scraping.md |
| Selector strategies | selectors.md |
Core Rules
- Never use
waitForTimeout()- always wait for specific conditions (element, URL, network) - Always close the browser - call
browser.close()to prevent memory leaks - Prefer role selectors -
getByRole()survives UI changes better than CSS - Handle dynamic content - use
waitFor()before interacting with elements - Persist auth state - use
storageStateto save and reuse login sessions
Quick Start - Common Tasks
Scrape a Page
const { chromium } = require('playwright');
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
const text = await page.locator('body').textContent();
await browser.close();
Fill a Form and Submit
await page.goto('https://example.com/login');
await page.getByLabel('Email').fill('user@example.com');
await page.getByLabel('Password').fill('secret');
await page.getByRole('button', { name: 'Sign in' }).click();
await page.waitForURL('**/dashboard');
Take a Screenshot
await page.goto('https://example.com');
await page.screenshot({ path: 'screenshot.png', fullPage: true });
Extract Table Data
const rows = await page.locator('table tr').all();
const data = [];
for (const row of rows) {
const cells = await row.locator('td').allTextContents();
data.push(cells);
}
Selector Priority
| Priority | Method | Example |
|---|---|---|
| 1 | getByRole() |
getByRole('button', { name: 'Submit' }) |
| 2 | getByLabel() |
getByLabel('Email') |
| 3 | getByPlaceholder() |
getByPlaceholder('Search...') |
| 4 | getByTestId() |
getByTestId('submit-btn') |
| 5 | locator() |
locator('.class') - last resort |
Common Traps
| Trap | Fix |
|---|---|
| Element not found | Add await locator.waitFor() before interacting |
| Flaky clicks | Use click({ force: true }) or wait for state: 'visible' |
| Timeout in CI | Increase timeout, check viewport size matches local |
| Auth lost between tests | Use storageState to persist cookies |
| SPA never reaches networkidle | Wait for specific DOM element instead |
| 403 Forbidden | Check if site blocks headless; try headless: false |
| Blank page after load | Increase wait time or use waitUntil: 'networkidle' |
Handling Sessions
// Save session after login
await page.context().storageState({ path: 'auth.json' });
// Reuse session in new context
const context = await browser.newContext({ storageState: 'auth.json' });
MCP Integration
For AI agents using Model Context Protocol:
npm install -g @playwright/mcp
npx @playwright/mcp --headless
MCP Tools Reference
| Tool | Description |
|---|---|
browser_navigate |
Navigate to URL |
browser_click |
Click element by selector |
browser_type |
Type text into input |
browser_select_option |
Select dropdown option |
browser_get_text |
Get text content |
browser_evaluate |
Execute JavaScript |
browser_snapshot |
Get accessible page snapshot |
browser_close |
Close browser context |
browser_choose_file |
Upload file |
browser_press |
Press keyboard key |
MCP Server Options
--headless # Run without UI
--browser chromium # chromium|firefox|webkit
--viewport-size 1920x1080
--timeout-action 10000 # Action timeout (ms)
--timeout-navigation 30000
--allowed-hosts example.com,api.example.com
--save-trace # Save trace for debugging
--save-video 1280x720 # Record video
Installation
npm init playwright@latest
# Or add to existing project
npm install -D @playwright/test
npx playwright install chromium
Related Skills
Install with clawhub install <slug> if user confirms:
puppeteer- Alternative browser automation (Chrome-focused)scrape- General web scraping patterns and strategiesweb- Web development fundamentals and HTTP handling
Feedback
- If useful:
clawhub star playwright - Stay updated:
clawhub sync