Browser Automation Skill
Setup
pip install playwright && playwright install chromium
pip install playwright-stealth # optional, for anti-detection
Skill Comparison
| Skill |
Use Case |
browser-automation |
Scripted automation, data pipelines, form bots |
webapp-testing |
QA assertions, visual regression, test suites |
chrome-browser |
Interactive MCP DevTools control |
Iron Law
NEVER USE time.sleep() — use page.wait_for_selector() or wait_for_load_state()
Core Patterns
Navigation and Extraction
with sync_playwright() as p:
context = p.chromium.launch(headless=True).new_context(
user_agent="Mozilla/5.0 ...", viewport={"width": 1280, "height": 720})
page = context.new_page()
page.goto(url); page.wait_for_load_state("networkidle")
items = [i.inner_text() for i in page.get_by_role("listitem").all()]
Form Filling
page.get_by_label("Email").fill("user@example.com")
page.get_by_label("Password").fill("secret")
with page.expect_navigation():
page.get_by_role("button", name="Submit").click()
Screenshot and PDF
page.screenshot(path="full.png", full_page=True)
page.pdf(path="page.pdf", format="A4", print_background=True)
Auth Session Management
# Save session
context.storage_state(path="auth-state.json")
# Reuse session
context = browser.new_context(storage_state="auth-state.json")
Anti-Detection
browser = p.chromium.launch(args=["--disable-blink-features=AutomationControlled"])
context = browser.new_context(user_agent="...", locale="en-US", timezone_id="America/New_York")
page.add_init_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
Agent Usage
- Save extracted data to
.claude/context/tmp/ as structured JSON
- Save screenshots/PDFs to
.claude/context/artifacts/
- Never commit
auth-state.json — add to .gitignore
Anti-Patterns
| Anti-Pattern |
Correct Approach |
time.sleep() for waits |
page.wait_for_selector() / wait_for_load_state() |
| CSS selectors for forms |
get_by_label(), get_by_role() |
| Re-login each run |
context.storage_state() persistence |
| Committing auth state |
Add auth-state.json to .gitignore |
Memory Protocol (MANDATORY)
Before starting: Read .claude/context/memory/learnings.md
After completing:
- New extraction pattern ->
.claude/context/memory/learnings.md
- Bot detection encountered ->
.claude/context/memory/issues.md
ASSUME INTERRUPTION: If it's not in memory, it didn't happen.
1---2name: browser-automation3description: Programmatic web automation using Playwright Python — data extraction, form filling, multi-step workflows, auth session management, screenshot/PDF capture, and anti-detection patterns. Use for scripted automation tasks, not interactive MCP-based browser control.4version: 1.0.05model: sonnet6invoked_by: both7user_invocable: true8tools: [Read, Write, Bash, Glob, Grep]9args: '<url> [--extract] [--fill-form] [--screenshot] [--pdf] [--auth-state <path>] [--headless]'10agents: [developer, qa, researcher]11category: 'Automation'12tags: [playwright, browser, automation, scraping, data-extraction, forms, screenshots, pdf, auth]13best_practices:14 - Use storage state to persist authenticated sessions across runs15 - Prefer role-based locators (get_by_role, get_by_label) over CSS selectors16 - Always use context managers (with sync_playwright() as p) for resource cleanup17 - Set realistic user-agent and viewport to avoid bot detection18 - Use page.wait_for_selector() instead of time.sleep() for dynamic content19error_handling: graceful20streaming: supported21verified: true22lastVerifiedAt: '2026-03-13'23source: builtin24trust_score: 10025provenance_sha: a1970631f58f8bdd26metadata:27 source: https://skillmd.com/skills/oimiragieo/browser-automation28---2930# Browser Automation Skill3132## Setup3334```bash35pip install playwright && playwright install chromium36pip install playwright-stealth # optional, for anti-detection37```3839## Skill Comparison4041| Skill | Use Case |42| -------------------- | ---------------------------------------------- |43| `browser-automation` | Scripted automation, data pipelines, form bots |44| `webapp-testing` | QA assertions, visual regression, test suites |45| `chrome-browser` | Interactive MCP DevTools control |4647## Iron Law4849```50NEVER USE time.sleep() — use page.wait_for_selector() or wait_for_load_state()51```5253## Core Patterns5455### Navigation and Extraction5657```python58with sync_playwright() as p:59 context = p.chromium.launch(headless=True).new_context(60 user_agent="Mozilla/5.0 ...", viewport={"width": 1280, "height": 720})61 page = context.new_page()62 page.goto(url); page.wait_for_load_state("networkidle")63 items = [i.inner_text() for i in page.get_by_role("listitem").all()]64```6566### Form Filling6768```python69page.get_by_label("Email").fill("user@example.com")70page.get_by_label("Password").fill("secret")71with page.expect_navigation():72 page.get_by_role("button", name="Submit").click()73```7475### Screenshot and PDF7677```python78page.screenshot(path="full.png", full_page=True)79page.pdf(path="page.pdf", format="A4", print_background=True)80```8182### Auth Session Management8384```python85# Save session86context.storage_state(path="auth-state.json")87# Reuse session88context = browser.new_context(storage_state="auth-state.json")89```9091### Anti-Detection9293```python94browser = p.chromium.launch(args=["--disable-blink-features=AutomationControlled"])95context = browser.new_context(user_agent="...", locale="en-US", timezone_id="America/New_York")96page.add_init_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")97```9899## Agent Usage100101- Save extracted data to `.claude/context/tmp/` as structured JSON102- Save screenshots/PDFs to `.claude/context/artifacts/`103- Never commit `auth-state.json` — add to `.gitignore`104105## Anti-Patterns106107| Anti-Pattern | Correct Approach |108| ------------------------ | ---------------------------------------------------- |109| `time.sleep()` for waits | `page.wait_for_selector()` / `wait_for_load_state()` |110| CSS selectors for forms | `get_by_label()`, `get_by_role()` |111| Re-login each run | `context.storage_state()` persistence |112| Committing auth state | Add `auth-state.json` to `.gitignore` |113114## Memory Protocol (MANDATORY)115116**Before starting:** Read `.claude/context/memory/learnings.md`117118**After completing:**119120- New extraction pattern -> `.claude/context/memory/learnings.md`121- Bot detection encountered -> `.claude/context/memory/issues.md`122123> ASSUME INTERRUPTION: If it's not in memory, it didn't happen.