Terug naar blog

Stop met tokens verspillen: maak browsertesten met Claude Code 10x goedkoper

Standaard gebruikt Claude Code claude-in-chrome voor browsertesten. Deze handleiding zet een custom skill op die Claude Code altijd naar Playwright laat grijpen met accessibility tree snapshots. Het resultaat: snellere, goedkopere en betrouwbaardere browserautomatisering.

DDarius Rosendahl
13-03-2026
5 min lezen
Blog cover

Standaard gebruikt Claude Code claude-in-chrome voor browsertesten — het maakt screenshots en analyseert die visueel. Dit verbruikt snel tokens en levert ongestructureerde beelddata op.

Deze handleiding zet een custom skill op die Claude Code altijd naar Playwright laat grijpen met accessibility tree snapshots. Het resultaat: snellere, goedkopere en betrouwbaardere browserautomatisering.

Hoe het werkt

Claude Code heeft een skills-systeem — markdown-bestanden in ~/.claude/skills/ die fungeren als herbruikbare instructies. Wanneer Claude een taak detecteert die overeenkomt met de beschrijving van een skill (bijv. “test deze pagina in de browser”), laadt het die skill en volgt de regels.

We maken een skill die Claude vertelt om:

  1. De Playwright CLI (npx playwright) te gebruiken in plaats van claude-in-chrome voor alle browserautomatisering

  2. De accessibility tree te lezen in plaats van screenshots te maken — gestructureerde tekst is goedkoper en preciezer dan base64-afbeeldingen

  3. Parallelle sub-agents in te zetten bij het testen van meerdere pagina’s, zodat elke pagina zijn eigen lichtgewicht context krijgt

We passen ook ~/.claude/CLAUDE.md (Claude’s globale instructiebestand) aan om de standaard te wijzigen van claude-in-chrome naar Playwright.

Vereisten

npm install -g @anthropic-ai/claude-code
  • Playwright geïnstalleerd:

npm install -g playwright
npx playwright install

Setup — Laat Claude het doen

Zodra je de vereisten hebt geïnstalleerd, open Claude Code en plak onderstaande prompt. Claude maakt de skill aan en past je configuratie automatisch aan.

De Prompt

Kopieer alles hieronder en plak het in Claude Code:

Do the following two things:

1. Create the file `~/.claude/skills/efficient-browser-automation/SKILL.md` with this exact content:

---
name: efficient-browser-automation
description: Use when testing pages in a browser, checking UI, verifying visual output, debugging frontend issues, or running any browser automation task
---

# Efficient Browser Automation

## Overview

Use the Playwright CLI (`npx playwright`) for all browser automation.
Use accessibility tree snapshots instead of screenshots to save tokens and get structured output.

## Quick Reference

| Task                                 | Command                          |
| ------------------------------------ | -------------------------------- |
| Open a URL in a browser              | `npx playwright open <url>`      |
| Generate test code interactively     | `npx playwright codegen <url>`   |
| Run test files                       | `npx playwright test`            |
| Run a specific test                  | `npx playwright test <file>`     |
| Show test report                     | `npx playwright show-report`     |
| Install browsers                     | `npx playwright install`         |

## Core Rules

1. **Playwright CLI only** — use `npx playwright` commands for all browser automation. Never use `claude-in-chrome` or `chrome-devtools` MCP unless the user explicitly asks for them
2. **Accessibility tree, not screenshots** — when inspecting page content, use `page.accessibility.snapshot()` in Playwright test scripts. This returns structured, parseable data and costs far fewer tokens than base64 images. Only take screenshots when a visual check is explicitly needed
3. **Parallel sub-agents for multi-page testing** — when checking multiple pages or flows, dispatch each as a separate sub-agent running its own Playwright CLI commands

## Inspecting Pages with Accessibility Snapshots

In Playwright test scripts, use the accessibility tree to inspect page content:

```js
const snapshot = await page.accessibility.snapshot();
console.log(JSON.stringify(snapshot, null, 2));
```

Or use `npx playwright codegen <url>` to interactively explore the page and generate selectors.

## Multi-Page Testing Pattern

When verifying multiple pages (e.g., checking 5 URLs for correct rendering), dispatch sub-agents in parallel:

- Agent 1: `npx playwright test` for url-1 + accessibility snapshot
- Agent 2: `npx playwright test` for url-2 + accessibility snapshot
- Agent 3: `npx playwright test` for url-3 + accessibility snapshot

Each agent reports back its findings. This is faster than sequential testing and keeps context windows small.

## Common Mistakes

| Mistake                                                  | Fix                                                      |
| -------------------------------------------------------- | -------------------------------------------------------- |
| Using `claude-in-chrome` or `chrome-devtools` MCP        | Use `npx playwright` CLI instead                         |
| Taking screenshots for page inspection                   | Use `page.accessibility.snapshot()` for structured output |
| Testing pages sequentially                               | Dispatch parallel sub-agents                             |
| Using MCP tools like `browser_navigate`                  | Use Playwright CLI commands and test scripts             |

---

2. Open `~/.claude/CLAUDE.md` (create it if it doesn't exist). Add or replace the
"Browser Testing Preferences" section with:

## Browser Testing Preferences

- **Default**: Always use the `efficient-browser-automation` skill (Playwright CLI) for all browser testing
- Only use alternative tools when explicitly requested:
  - `claude-in-chrome` - when user asks for "claude-in-chrome"
  - `chrome-devtools` MCP - when user asks for "chrome devtools" or "devtools mcp"

---

After you're done, verify both files exist and show me their contents.

Dat is alles. Start een nieuwe Claude Code-sessie en vraag om een webpagina te controleren — het zal de Playwright CLI en accessibility snapshots gebruiken in plaats van screenshots.

Waarom dit belangrijk is

Aanpak

Tokenkosten

Uitvoerformaat

Snelheid

Screenshots (claude-in-chrome)

Hoog — base64-afbeeldingen zijn groot

Ongestructureerde visuele analyse

Langzaam — een pagina tegelijk

Accessibility tree (Playwright)

Laag — gestructureerde tekst

Parseerbare, precieze data

Snel — parallelle sub-agents

De accessibility tree geeft je een gestructureerde weergave van de pagina — koppen, links, knoppen, formuliervelden, ARIA-labels — zonder de overhead van het coderen en verzenden van een afbeelding. Claude kan deze data direct parsen in plaats van pixels te interpreteren.

Probleemoplossing

Claude gebruikt nog steeds claude-in-chrome

Controleer of ~/.claude/CLAUDE.md de sectie Browser Testing Preferences bevat met Playwright als standaard. Controleer of het skill-bestand bestaat op ~/.claude/skills/efficient-browser-automation/SKILL.md.

Playwright niet gevonden

Voer npm install -g playwright uit om het globaal te installeren, daarna npx playwright install om de browserbinaries te downloaden.

Browsers starten niet op

Voer npx playwright install uit om de browserbinaries te downloaden. Op Linux heb je mogelijk ook npx playwright install-deps nodig voor systeemafhankelijkheden.

Bronnen

D

Darius Rosendahl

Deel dit artikel