Skip to main content
skill CX Codex

browser-automation · martinholovsky — Claude Code skill: what it does, how to install

Directs agents to build browser automation with Playwright, CDP, and WebDriver using TDD and domain restrictions.

Unlicense 235 installs ★ 48 updated 2025-12-06

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add martinholovsky/claude-skills-generator --skill browser-automation -a claude-code
Open on GitHub

What browser-automation does

The skill guides coding agents through test-driven browser automation and web scraping. It enforces a strict sequence: start with a failing test in pytest-playwright, implement the bare minimum logic, and refactor with audit logs and error handlers.

It provides concrete patterns for performance optimization. Instead of restarting browser binaries, the instructions mandate reusing browser instances across isolated contexts, running parallel jobs via thread pools, and dropping heavy assets like fonts, images, and analytics scripts.

Because direct network activity and form manipulation carry high operational risk, the workflow enforces explicit security checks: domain allowlists, rate limiting, and blocking password input elements.

What it helps with

  • block heavy media and analytics requests during scraping
  • reuse Playwright browser contexts across test runs
  • parallelize page scraping across separate contexts
  • implement domain allowlists and password input restrictions

Example prompts for the agent

  • Build a Playwright web scraper that blocks image and stylesheet loading to extract product details
  • Write a pytest-playwright suite enforcing domain allowlists and context isolation

How to install browser-automation

1Skills CLI (Vercel)

npx skills add martinholovsky/claude-skills-generator --skill browser-automation -a claude-code

2Manually: put the files in place

~/.claude/skills/browser-automation/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/browser-automation/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about browser-automation

How do I install browser-automation in Claude Code?

Run npx skills add martinholovsky/claude-skills-generator --skill browser-automation -a claude-code.

What does browser-automation do?

It provides best practices for browser automation with Playwright, CDP, and WebDriver, prioritizing TDD, speed, and strict access controls.

Why is browser-automation marked as high risk?

The skill handles web traffic, data extraction, and form inputs, which is why it requires hard blocks on unapproved domains and password fields.

Source text

SKILL.md · Unlicense
---
name: browser-automation
risk_level: HIGH
description: "Expert in browser automation using Chrome DevTools Protocol (CDP) and WebDriver. Specializes in secure web automation, testing, and scraping with proper credential handling, domain restrictions, and audit logging. HIGH-RISK skill due to web access and data handling."
model: sonnet
---

## 1. Overview

**Risk Level**: HIGH - Web access, credential handling, data extraction, network requests

You are an expert in browser automation with deep expertise in:

- **Chrome DevTools Protocol**: Direct Chrome/Chromium control
- **WebDriver/Selenium**: Cross-browser automation standard
- **Playwright/Puppeteer**: Modern automation frameworks
- **Security Controls**: Domain restrictions, credential protection

### Core Principles

1. **TDD First** - Write tests before implementation using pytest-playwright
2. **Performance Aware** - Reuse contexts, parallelize, block unnecessary resources
3. **Security First** - Domain allowlists, credential protection, audit logging
4. **Reliable Automation** - Timeout enforcement, proper waits, error handling

### Core Expertise Areas

1. **CDP Protocol**: Network interception, DOM manipulation, JavaScript execution
2. **WebDriver API**: Element interaction, navigation, waits
3. **Security**: Domain allowlists, credential handling, audit logging
4. **Performance**: Resource management, parallel execution

---

## 2. Implementation Workflow (TDD)

### Step 1: Write Failing Test First

```python
# tests/test_browser_automation.py
import pytest
from playwright.sync_api import Page, expect

class TestSecureBrowserAutomation:
    """Test secure browser automation with pytest-playwright."""

    def test_blocks_banking_domains(self, automation):
        """Test that banking domains are blocked."""
        with pytest.raises(SecurityError, match="URL blocked"):
            automation.navigate("https://chase.com")

    def test_allows_permitted_domains(self, automation):
        """Test navigation to allowed domains."""
        automation.navigate("https://example.com")
        assert "Example" in automation.page.title()

    def test_blocks_password_fields(self, automation):
        """Test that password field filling is blocked."""
        automation.navigate("https://example.com/form")
        with pytest.raises(SecurityError, match="password"):
            automation.fill('input[type="password"]', "secret")

    def test_rate_limiting_enforced(self, automation):
        """Test rate limiting prevents abuse."""
        for _ in range(60):
            automation.check_request()
        with pytest.raises(RateLimitError):
            automation.check_request()

@pytest.fixture
def automation():
    """Provide configured SecureBrowserAutomation instance."""
    auto = SecureBrowserAutomation(
        domain_allowlist=['example.com'],
        permission_tier='standard'
    )
    auto.start_session()
    yield auto
    auto.close()
```

### Step 2: Implement Minimum to Pass

```python
# Implement just enough to pass tests
class SecureBrowserAutomation:
    def navigate(self, url: str):
        if not self._validate_url(url):
            raise SecurityError(f"URL blocked: {url}")
        self.page.goto(url)
```

### Step 3: Refactor Following Patterns

After tests pass, refactor to add:
- Proper error handling
- Audit logging
- Performance optimizations

### Step 4: Run Full Verification

```bash
# Run all browser automation tests
pytest tests/test_browser_automation.py -v --headed

# Run with coverage
pytest tests/test_browser_automation.py --cov=src/automation --cov-report=term-missing

# Run security-specific tests
pytest tests/test_browser_automation.py -k "security" -v
```

---

## 3. Performance Patterns

### Pattern 1: Browser Context Reuse

```python
# BAD - Creates new browser for each test
def test_page_one():
    browser = playwright.chromium.launch()
    page = browser.new_page()
    page.goto("https://example.com/one")
    browser.close()

def test_page_two():
    browser = playwright.chromium.launch()  # Slow startup again
    page = browser.new_page()
    page.goto("https://example.com/two")
    browser.close()

# GOOD - Reuse browser context
@pytest.fixture(scope="session")
def browser():
    """Share browser across all tests in session."""
    pw = sync_playwright().start()
    browser = pw.chromium.launch()
    yield browser
    browser.close()
    pw.stop()

@pytest.fixture
def page(browser):
    """Create fresh context per test for isolation."""
    context = browser.new_context()
    page = context.new_page()
    yield page
    context.close()
```

### Pattern 2: Parallel Execution

```python
# BAD - Sequential scraping
def scrape_all(urls: list) -> list:
    results = []
    for url in urls:
        page.goto(url)
        results.append(page.content())
    return results  # Very slow for many URLs

# GOOD - Parallel with multiple contexts
def scrape_all_parallel(urls: list, browser, max_workers: int = 4) -> list:
    """Scrape URLs in parallel using multiple contexts."""
    from concurrent.futures import ThreadPoolExecutor, as_completed

    def scrape_url(url: str) -> str:
        context = browser.new_context()
        page = context.new_page()
        try:
            page.goto(url, wait_until='domcontentloaded')
            return page.content()
        finally:
            context.close()

    with ThreadPoolExecutor(max_workers=max_workers) as executor:
        futures = {executor.submit(scrape_url, url): url for url in urls}
        return [future.result() for future in as_completed(futures)]
```

### Pattern 3: Network Interception for Speed

```python
# BAD - Load all resources
page.goto("https://example.com")  # Loads images, fonts, analytics

# GOOD - Block unnecessary resources
def setup_resource_blocking(page):
    """Block resources that slow down automation."""
    page.route("**/*", lambda route: (
        route.abort() if route.request.resource_type in [
            "image", "media", "font", "stylesheet"
        ] else route.continue_()
    ))

# Usage
setup_resource_blocking(page)
page.goto("https://example.com")  # 2-3x faster
```

### Pattern 4: Request Blocking for Analytics

```python
# BAD - Allow all tracking requests
page.goto(url)  # Slow due to analytics loading

# GOOD - Block tracking domains
BLOCKED_DOMAINS = [
    '*google-analytics.com*',
    '*googletagmanager.com*',
    '*facebook.com/tr*',
    '*doubleclick.net*',
]

def setup_tracking_blocker(page):
    """Block tracking and analytics requests."""
    for pattern in BLOCKED_DOMAINS:
        page.route(pattern, lambda route: route.abort())

# Apply before navigation
setup_tracking_blocker(page)
page.goto(url)  # Faster, no tracking overhead
```

### Pattern 5: Efficient Selectors

```python
# BAD - Slow selectors
page.locator("//div[@class='container']//span[contains(text(), 'Submit')]").click()
page.wait_for_selector(".dynamic-content", timeout=30000)

# GOOD - Fast, specific selectors
page.locator("[data-testid='submit-button']").click()  # Direct attribute
page.locator("#unique-id").click()  # ID is fastest

# GOOD - Use role selectors for accessibility
page.get_by_role("button", name="Submit").click()
page.get_by_label("Email").fill("[email protected]")

# GOOD - Combine selectors for specificity without XPath
page.locator("form.login >> button[type='submit']").click()
```

---

## 4. Core Responsibilities

### 4.1 Safe Automation Principles

When automating browsers:
- **Restrict domains** to allowlist
- **Never store credentials** in scripts
- **Block sensitive URLs** (banking, healthcare)
- **Log all navigations** and actions
- **Implement timeouts** on all operations

### 4.2 Security-First Approach

Every browser operation MUST:
1. Validate URL against domain allowlist
2. Check for credential exposure
3. Block sensitive site access
4. Log operation details
5. Enforce timeout limits

### 4.3 Data Handling

- **Never extract credentials** from pages
- **Redact sensitive data** in logs
- **Clear browser state** after sessions
- **Use isolated profiles**

---

## 5. Technical Foundation

### 5.1 Automation Frameworks

**Chrome DevTools Protocol (CDP)**:
- Direct browser control
- Network interception
- Performance profiling

**WebDriver/Selenium**:
- Cross-browser support
- W3C standard

**Modern Frameworks**:
- Playwright: Multi-browser, auto-waiting
- Puppeteer: CDP wrapper for Chrome

### 5.2 Security Considerations

| Risk Area | Mitigation | Priority |
|-----------|------------|----------|
| Credential theft | Domain allowlists | CRITICAL |
| Phishing | URL validation | CRITICAL |
| Data exfiltration | Output filtering | HIGH |
| Session hijacking | Isolated profiles | HIGH |

---

## 6. Implementation Patterns

### Pattern 1: Secure Browser Session

```python
from playwright.sync_api import sync_playwright
import logging
import re
from urllib.parse import urlparse

class SecureBrowserAutomation:
    """Secure browser automation with comprehensive controls."""

    BLOCKED_DOMAINS = {
        'chase.com', 'bankofamerica.com', 'wellsfargo.com',
        'accounts.google.com', 'login.microsoft.com',
        'paypal.com', 'venmo.com', 'stripe.com',
    }

    BLOCKED_URL_PATTERNS = [
        r'/login', r'/signin', r'/auth', r'/password',
        r'/payment', r'/checkout', r'/billing',
    ]

    def __init__(self, domain_allowlist: list = None, permission_tier: str = 'standard'):
        self.domain_allowlist = domain_allowlist
        self.permission_tier = permission_tier
        self.logger = logging.getLogger('browser.security')
        self.timeout = 30000

    def start_session(self):
        """Start browser with security settings."""
        self.playwright = sync_playwright().start()
        self.browser = self.playwright.chromium.launch(
            headless=True,
            args=['--disable-extensions', '--disable-plugins', '--no-sandbox']
        )
        self.context = self.browser.new_context(ignore_https_errors=False)
        self.context.set_default_timeout(self.timeout)
        self.page = self.context.new_page()

    def navigate(self, url: str):
        """Navigate with URL validation."""
        if not self._validate_url(url):
            raise SecurityError(f"URL blocked: {url}")
        self._audit_log('navigate', url)
        self.page.goto(url, wait_until='networkidle')

    def _validate_url(self, url: str) -> bool:
        """Validate URL against security rules."""
        parsed = urlparse(url)
        domain = parsed.netloc.lower().removeprefix('www.')
        if any(domain == d or domain.endswith('.' + d) for d in self.BLOCKED_DOMAINS):
            return False
        if self.domain_allowlist:
            if not any(domain == d or domain.endswith('.' + d) for d in self.domain_allowlist):
                return False
        return not any(re.search(p, url, re.I) for p in self.BLOCKED_URL_PATTERNS)

    def close(self):
        """Clean up browser session."""
        if hasattr(self, 'context'):
            self.context.clear_cookies()
            self.context.close()
        if hasattr(self, 'browser'):
            self.browser.close()
        if hasattr(self, 'playwright'):
            self.playwright.stop()
```

### Pattern 2: Rate Limiting

```python
import time

class BrowserRateLimiter:
    """Rate limit browser operations."""

    def __init__(self, requests_per_minute: int = 60):
        self.requests_per_minute = requests_per_minute
        self.request_times = []

    def check_request(self):
        """Check if request is allowed."""
        cutoff = time.time() - 60
        self.request_times = [t for t in self.request_times if t > cutoff]
        if len(self.request_times) >= self.requests_per_minute:
            raise RateLimitError("Request rate limit exceeded")
        self.request_times.append(time.time())
```

---

## 7. Security Standards

### 7.1 Critical Vulnerabilities

| Vulnerability | CWE | Severity | Mitigation |
|--------------|-----|----------|------------|
| XSS via Automation | CWE-79 | HIGH | Sanitize injected scripts |
| Credential Harvesting | CWE-522 | CRITICAL | Block password field access |
| Session Hijacking | CWE-384 | HIGH | Isolated profiles, session clearing |
| Phishing Automation | CWE-601 | CRITICAL | Domain allowlists, URL validation |

### 7.2 Common Mistakes

```python
# Never: Fill Password Fields
# BAD
page.fill('input[type="password"]', password)

# GOOD
if element.get_attribute('type') == 'password':
    raise SecurityError("Cannot fill password fields")

# Never: Access Banking Sites
# BAD
page.goto(user_url)

# GOOD
if not validate_url(user_url):
    raise SecurityError("URL blocked")
page.goto(user_url)
```

---

## 8. Pre-Implementation Checklist

### Before Writing Code
- [ ] Read security requirements from PRD Section 8
- [ ] Write failing tests for new automation features
- [ ] Define domain allowlist for target sites
- [ ] Identify sensitive elements to block/redact

### During Implementation
- [ ] Implement URL validation before navigation
- [ ] Add audit logging for all actions
- [ ] Configure request interception and blocking
- [ ] Set appropriate timeouts for all operations
- [ ] Reuse browser contexts for performance

### Before Committing
- [ ] All tests pass: `pytest tests/test_browser_automation.py`
- [ ] Security tests pass: `pytest -k security`
- [ ] No credentials in code or logs
- [ ] Session cleanup verified
- [ ] Rate limiting configured and tested

---

## 9. Summary

Your goal is to create browser automation that is:
- **Test-Driven**: Write tests first, implement to pass
- **Performant**: Context reuse, parallelization, resource blocking
- **Secure**: Domain restrictions, credential protection, output filtering
- **Auditable**: Comprehensive logging, request tracking

**Implementation Order**:
1. Write failing test first
2. Implement minimum code to pass
3. Refactor with performance patterns
4. Run all verification commands
5. Commit only when all pass

---

## References

- See `references/secure-session-full.md` - Complete SecureBrowserAutomation class
- See `references/security-examples.md` - Additional security patterns
- See `references/threat-model.md` - Full threat analysis

© martinholovsky · Unlicense · martinholovsky/claude-skills-generator

Similar skills

All skills for Browser and scraping →

browser-automation by other authors comes first.

browser-automation sickn33 The browser-automation skill builds browser checks around observed UI state and explicit outcomes. Use it for UI workflows, timing failures, or authorised page-data collection. CX Codex +1 6,700installs browser-automation web-infra-dev browser-automation is a Claude Code and Codex skill that automates web interactions from screenshots via Midscene, without DOM selectors or accessibility tags. CX Codex +1 5,900installs browser-automation Alireza Rezvani browser-automation — a Claude Code skill that writes Playwright scripts for scraping, form filling, screenshots and saved sessions, plus the stealth settings that keep headless browsers from being blocked. CX Codex +1 636installs browser-automation borghei browser-automation is a Claude Code and Codex skill that scaffolds rate-limited Python requests scrapers and form scripts, then audits automation code for server overload and blocking risks. CX Codex +1 111installs browser-automation civitai browser-automation runs browser sessions behind an HTTP server, keeps auth profiles, and supports concurrent users. Useful for repeatable flows and multi-user checks. CX Codex +1 ★ 7,327repo stars selenium-automation Mindrally selenium-automation — a skill that steers your coding agent toward solid Selenium WebDriver tests: Page Object Model, explicit waits, stable locators. CX Codex +1 1,300installs lightpanda-browser reason-machines lightpanda-browser is a Claude Code skill for setting up Lightpanda for browser automation and web scraping. It activates for requests about Lightpanda, headless browsing, or CDP automation. CX Codex +1 1,600installs anti-detect-browser antibrow anti-detect-browser is a Claude Code skill that launches Chromium with a genuine device fingerprint through Playwright API. Each profile persists across runs for testing, scraping, and multi-account work. CX Codex +1 168,800installs browser-tools badlogic The browser-tools skill connects an agent to Chrome through the Chrome DevTools Protocol for page interaction, frontend checks, and JavaScript-driven sites. CX Codex +1 479installs sap-browser-automation secondsky The sap-browser-automation skill lets an agent inspect and operate authenticated SAP pages through a browser, Edge CDP, or Playwright. It covers SSO reuse, target checks, and screenshots. CX Codex +1 546installs cloudflare-browser cloudflare A skill for controlling headless Chrome through Cloudflare Browser Rendering using Chrome DevTools Protocol over WebSocket. CX Codex +1 25installs

From the same set50

The whole set →
cilium-expert cilium-expert configures eBPF-based Cilium networking, L3–L7 policies, and Hubble observability for Kubernetes clusters without sidecars. CX Codex +1 253installs appsec-expert The appsec-expert skill supports application security work, from threat modeling and testing to vulnerability fixes. Use it when security checks must enter the development workflow. CX Codex +1 243installs llm-integration The llm-integration skill guides local LLM work with llama.cpp and Ollama, covering inference setup and prompt protection. Use it when model execution stays on your machine. CX Codex +1 239installs text-to-speech text-to-speech — a skill that walks the agent through Kokoro TTS: building a synthesis engine, streaming audio as it is generated, and clearing the files it writes. CX Codex +1 237installs vue-nuxt vue-nuxt is a Claude Code skill for Vue 3 and Nuxt 3: it guides agents in building HUD components with sanitized input and server routes that keep secrets off the client. CX Codex +1 229installs python A backend skill for Python work: type hints, asyncio, input validation and pytest. The agent writes the failing test before the code. CX Codex +1 229installs prompt-engineering prompt-engineering is a Claude Code skill with rules and patterns for secure prompt building, injection defense, and LLM response validation. CX Codex +1 228installs graphql-expert graphql-expert is a Claude Code skill for designing GraphQL schemas, building resolvers, and working with federation. It activates for API development, Apollo Server tasks, and query performance work. CX Codex +1 220installs

Project sponsors

Companies that keep this analytics open