If you've used Playwright MCP for AI browser automation, you know the pain. Every page navigation dumps the full DOM tree into the model context. Simple flows like "order 5 items from this shop" can burn hundreds of thousands of tokens on navbar/sidebar/footer noise that has nothing to do with the task.
We built a small MCP layer that sits in front of Playwright and only forwards the relevant bits. Open sourced it.
📚 Full writeup: https://treesoop.com/blog/playwright-mcp-optimizer-token-saving-2026
🔧 GitHub: https://github.com/treesoop/claude-native-plugin
The problem
Playwright MCP serializes the full DOM:
AI ← {ENTIRE_DOM_JSON} ← Playwright MCP
This works for QA where you need to see everything. For "browse and take an action" it's 5-10× the tokens you actually need.
The optimizer
AI ← {relevant_only} ← Optimizer ← {full DOM} ← Playwright MCP
Three filter rules:
- Interactive elements first: button, input, a — not decorative div/span
- Semantic grouping: navigation / main / form / footer regions, so the model knows where it is
- Task-aware skipping: if the current task is "checkout", skip sidebar recommendations and ad banners
Measured impact
On a "cart → checkout" flow with GPT-4: tokens dropped substantially, and round-trip latency improved as a side effect (smaller payloads → faster agent decisions).
Not a silver bullet. For QA tasks where you need full DOM accuracy, use vanilla Playwright MCP. For general browsing / automation agents, this is the cheaper + faster path.
Tool comparison (our testing)
| Tool | Strength | Use for |
|---|---|---|
| playwright-mcp (default) | Full DOM accuracy | QA, complex validation |
| playwright-optimizer (this) | Token efficiency | Automation agents, browsing |
| vercel-browser-agent | Code generation speed | Simple browsing |
| claude-chrome-extension | Uses logged-in session | Tasks needing auth state |
We use all four for different jobs.
Install
npm install -g @treesoop/playwright-optimizer
claude mcp add playwright-opt -- playwright-optimizer
- MIT licensed
- Configurable per-site presets
-
--log-tokensflag for measurement
More OSS from TreeSoop: ai-news-mcp, hwp-mcp, whisper_transcription, claude2codex
United States
NORTH AMERICA
Related News
UCP Variant Data: The #1 Reason Agent Checkouts Fail
7h ago
Amazon Employees Are 'Tokenmaxxing' Due To Pressure To Use AI Tools
21h ago
How Braze’s CTO is rethinking engineering for the agentic area
10h ago

Décryptage technique : Comment builder un téléchargeur de vidéos Reddit performant (DASH, HLS & WebAssembly)
17h ago
How AI Reduced Manual Driver Verification by 75% — Operations Case Study. Part 2
4h ago