browsegrab
한국어 문서
Token-efficient browser agent for local LLMs — Playwright + accessibility tree + MarkGrab, MCP native.
browsegrab is a lightweight browser automation library designed for local LLMs (8B-35B parameters). It combines Playwright's accessibility tree with MarkGrab's HTML-to-markdown conversion to achieve 5-8x fewer tokens per step compared to alternatives like browser-use.
Features
- Token-efficient: ~500-1,500 tokens/step (vs 4,000-10,000 for browser-use)
- Local LLM first: Optimized for vLLM, Ollama, and OpenAI-compatible endpoints
- MCP native: Built-in MCP server with 8 browser automation tools
- MarkGrab integration: HTML → clean markdown for content extraction
- Accessibility tree + ref system: Stable element references (
e1, e2, ...) without vision models
- Success pattern caching: Zero LLM calls on repeated workflows
- 5-stage JSON parser: Robust action parsing for local LLM outputs
- Minimal dependencies: Only
playwright + httpx in core
Installation
pip install browsegrab
playwright install chromium
With optional features:
pip install browsegrab[mcp]
pip install browsegrab[content]
pip install browsegrab[cli]
pip install browsegrab[all]
Quick Start
Python API
from browsegrab import BrowseSession
async with BrowseSession() as session:
await session.navigate("https://example.com")
snap = await session.snapshot()
print(snap.tree_text)
result = await session.click("e1")
print(result.url)
await session.navigate("https://en.wikipedia.org")
snap = await session.snapshot()
await session.type("e4", "Python programming", submit=True)
content = await session.extract_content()
CLI
browsegrab snapshot https://example.com
browsegrab snapshot https://example.com -f json
browsegrab extract https://en.wikipedia.org/wiki/Python
browsegrab browse https://example.com "Find the about page"
MCP Server
browsegrab-mcp
Claude Desktop / Cursor / VS Code config:
{
"mcpServers": {
"browsegrab": {
"command": "browsegrab-mcp"
}
}
}
8 MCP tools: browser_navigate, browser_click, browser_type, browser_snapshot, browser_scroll, browser_extract_content, browser_go_back, browser_wait
How It Works
browsegrab separates structure (accessibility tree) from content (MarkGrab markdown), sending only what the LLM needs:
Raw HTML
├── Structure: Accessibility tree → interactive elements → [ref=eN]
│ → ~200-500 tokens
└── Content: MarkGrab → clean markdown (on-demand)
→ ~300-800 tokens
Combined: ~500-1,300 tokens per step
Token efficiency (measured)
| example.com | 1 | ~60 | ~500+ |
| Wikipedia article | 452 | ~1,254 | ~10,000+ |
Architecture
browsegrab/
├── config.py # Dataclass configs (env var loading)
├── result.py # Result types (ActionResult, BrowseResult, ...)
├── session.py # BrowseSession orchestrator
├── browser/
│ ├── manager.py # Playwright lifecycle (async context manager)
│ ├── snapshot.py # Accessibility tree + ref system
│ ├── selectors.py # 4-strategy selector resolver
│ └── actions.py # navigate, click, type, scroll, go_back, wait
├── dom/
│ ├── ref_map.py # ref ID ↔ element bidirectional mapping
│ └── compress.py # AX tree + MarkGrab → compressed context
├── llm/
│ ├── base.py # LLMProvider ABC
│ ├── provider.py # vLLM, Ollama, OpenAI-compatible
│ ├── prompt.py # System prompts (~400 tokens)
│ └── parse.py # 5-stage JSON fallback parser
├── agent/
│ ├── history.py # Sliding window history compression
│ ├── cache.py # Domain-based success pattern cache
│ └── loop_guard.py # Duplicate action detection
├── __main__.py # CLI (click)
└── mcp_server.py # FastMCP server (8 tools)
Configuration
All settings via environment variables (BROWSEGRAB_* prefix):
BROWSEGRAB_BROWSER_HEADLESS=true
BROWSEGRAB_BROWSER_TIMEOUT_MS=30000
BROWSEGRAB_LLM_PROVIDER=vllm
BROWSEGRAB_LLM_BASE_URL=http://localhost:8000/v1
BROWSEGRAB_LLM_MODEL=Qwen/Qwen3.5-32B-AWQ
BROWSEGRAB_AGENT_MAX_STEPS=10
BROWSEGRAB_AGENT_ENABLE_CACHE=true
Part of the QuartzUnit Ecosystem
| markgrab | Passive extraction (URL → markdown) |
| snapgrab | Passive capture (URL → screenshot) |
| docpick | Document OCR → structured JSON |
| browsegrab | Active automation (goal → browser actions → results) |
Development
git clone https://github.com/QuartzUnit/browsegrab.git
cd browsegrab
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
playwright install chromium
pytest tests/ -m "not e2e"
pytest tests/ -v
License
MIT