Token-efficient browser agent for local LLMs — Playwright + accessibility tree + MarkGrab, MCP native.
Project description
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+httpxin core
Installation
pip install browsegrab
playwright install chromium
With optional features:
pip install browsegrab[mcp] # MCP server support
pip install browsegrab[content] # MarkGrab content extraction
pip install browsegrab[cli] # CLI with rich output
pip install browsegrab[all] # Everything
Quick Start
Python API
from browsegrab import BrowseSession
async with BrowseSession() as session:
# Navigate and get accessibility tree snapshot
await session.navigate("https://example.com")
snap = await session.snapshot()
print(snap.tree_text)
# - heading "Example Domain" [level=1]
# - link "Learn more": [ref=e1]
# Click using ref ID
result = await session.click("e1")
print(result.url) # https://www.iana.org/help/example-domains
# Type into search box
await session.navigate("https://en.wikipedia.org")
snap = await session.snapshot()
await session.type("e4", "Python programming", submit=True)
# Extract compressed content (AX tree + markdown)
content = await session.extract_content()
CLI
# Accessibility tree snapshot
browsegrab snapshot https://example.com
# JSON output
browsegrab snapshot https://example.com -f json
# Extract content (AX tree + markdown)
browsegrab extract https://en.wikipedia.org/wiki/Python
# Agentic browse (requires LLM endpoint)
browsegrab browse https://example.com "Find the about page"
MCP Server
browsegrab-mcp # Start MCP server (stdio)
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)
| Page | Interactive elements | Tokens | browser-use equivalent |
|---|---|---|---|
| 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):
# Browser
BROWSEGRAB_BROWSER_HEADLESS=true
BROWSEGRAB_BROWSER_TIMEOUT_MS=30000
# LLM (for agentic browse)
BROWSEGRAB_LLM_PROVIDER=vllm # vllm | ollama | openai
BROWSEGRAB_LLM_BASE_URL=http://localhost:8000/v1
BROWSEGRAB_LLM_MODEL=Qwen/Qwen3.5-32B-AWQ
# Agent
BROWSEGRAB_AGENT_MAX_STEPS=10
BROWSEGRAB_AGENT_ENABLE_CACHE=true
Part of the QuartzUnit Ecosystem
| Library | Role |
|---|---|
| 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
# Unit tests (no browser needed)
pytest tests/ -m "not e2e"
# Full suite including E2E
pytest tests/ -v
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file browsegrab-0.1.2.tar.gz.
File metadata
- Download URL: browsegrab-0.1.2.tar.gz
- Upload date:
- Size: 43.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ea31ea1e548c9c6c2bb12c98c5338c7502d397f988d012db4b94eef804a7777
|
|
| MD5 |
0b704ca7efb50935b1a132c778265668
|
|
| BLAKE2b-256 |
e4be5643b1bc5ed91cd093be3eef17f4ce6ef890b44d7dc804802333e8947c1f
|
Provenance
The following attestation bundles were made for browsegrab-0.1.2.tar.gz:
Publisher:
publish.yml on QuartzUnit/browsegrab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
browsegrab-0.1.2.tar.gz -
Subject digest:
0ea31ea1e548c9c6c2bb12c98c5338c7502d397f988d012db4b94eef804a7777 - Sigstore transparency entry: 1178845876
- Sigstore integration time:
-
Permalink:
QuartzUnit/browsegrab@2dbd1a026d68b4c97d7bf030f4e9361bb3767b41 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/QuartzUnit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2dbd1a026d68b4c97d7bf030f4e9361bb3767b41 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file browsegrab-0.1.2-py3-none-any.whl.
File metadata
- Download URL: browsegrab-0.1.2-py3-none-any.whl
- Upload date:
- Size: 34.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df5a10c11faf533bd992f34d1474ba130a9712fc3c4500dcebe570d817fbf008
|
|
| MD5 |
cd31aa5a245e3c492aa1c30ca7a69cb1
|
|
| BLAKE2b-256 |
b869041a4e0680fafe9366eafbc14f4db2cce05e0159798893cbc4afd37cc34e
|
Provenance
The following attestation bundles were made for browsegrab-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on QuartzUnit/browsegrab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
browsegrab-0.1.2-py3-none-any.whl -
Subject digest:
df5a10c11faf533bd992f34d1474ba130a9712fc3c4500dcebe570d817fbf008 - Sigstore transparency entry: 1178845877
- Sigstore integration time:
-
Permalink:
QuartzUnit/browsegrab@2dbd1a026d68b4c97d7bf030f4e9361bb3767b41 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/QuartzUnit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2dbd1a026d68b4c97d7bf030f4e9361bb3767b41 -
Trigger Event:
workflow_dispatch
-
Statement type: