Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Browser Agent Cookbook

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.

Why This Exists

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.

Patterns

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

Benchmarks

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

Who Is This For

  • 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

Philosophy

  1. Measure first. Every pattern includes numbers. "Feels faster" isn't a pattern.
  2. Fail fast, switch strategies. If something doesn't work after 2-3 attempts, the problem is your approach, not your persistence.
  3. Accessibility APIs are underrated. They were built for a different audience but they're often the best interface for agents too.
  4. Token budget is your real constraint. Network speed, CPU, memory — all secondary to how much context window you're burning per interaction.

Contributing

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.

License

MIT

About

Practical patterns for building LLM-driven browser agents. Real benchmarks, not theory.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors