Practical patterns for building LLM-driven browser agents. Not theory — things that work, tested on real sites.
If you're building an agent that controls a browser (via CDP, Playwright, Puppeteer, or any MCP server), these patterns will save you hours of debugging.
Browser automation with LLMs is a different problem than traditional browser automation. The bottleneck isn't "can I click a button" — it's token efficiency, state representation, error recovery, and knowing when to switch strategies.
Most browser agent tutorials show a happy path on a static page. Real websites have SPAs, dynamic content, lazy loading, modals, iframes, and a dozen other things that break naive approaches. This cookbook covers what actually works.
| Pattern | What It Covers |
|---|---|
| Content Extraction | AX tree vs innerText vs DOM — when to use which, and how to combine them |
| Token Efficiency | Minimizing context window usage while keeping agents effective |
| Wait Strategies | commit vs domcontentloaded vs load, with real benchmarks |
| SPA Interaction | React, Vue, and other framework-specific gotchas |
| Session Management | Auth state, cookies, and persistent profiles |
| Parallel Operations | Multi-tab loading and concurrent page processing |
Real measurements, not vibes:
| Optimization | Improvement | Source |
|---|---|---|
| AX tree vs raw DOM | 3-5x fewer tokens | Token Efficiency |
commit vs load wait |
5-17x faster navigation | Wait Strategies |
| Ad blocking | 74% fewer requests | Token Efficiency |
| Parallel tab loading | 52% faster than sequential | Parallel Operations |
- Developers building browser agents with LLMs
- Anyone using MCP browser servers (Playwright MCP, cdp-browser, chrome-devtools-mcp, etc.)
- Teams evaluating browser automation approaches for AI agents
- Measure first. Every pattern includes numbers. "Feels faster" isn't a pattern.
- Fail fast, switch strategies. If something doesn't work after 2-3 attempts, the problem is your approach, not your persistence.
- Accessibility APIs are underrated. They were built for a different audience but they're often the best interface for agents too.
- Token budget is your real constraint. Network speed, CPU, memory — all secondary to how much context window you're burning per interaction.
Found a pattern that works? Open a PR. Include:
- What problem it solves
- A concrete example with real output
- Numbers (tokens, time, requests — whatever's relevant)
No vague advice. No "it depends." Show what works and when.
MIT