Skip to Content
Optimized DOM

Token-Optimized DOM Export

Phase 3 — Compressed semantic JSON snapshot of the page for LLM context windows, achieving over 50% token reduction compared to the standard accessibility tree. Every AI browser agent benefits from this — smaller snapshots mean faster decisions, lower cost, and more room in the context window for browser automation instructions.

The Problem

A typical accessibility tree for a modern web page consumes 5,000-20,000 tokens. Most of those tokens are structural noise: wrapper divs, generic groups, section containers, paragraph wrappers, and redundant whitespace. The AI agent needs semantic content, not DOM bureaucracy.

Output Format

The optimized DOM uses an array-of-tuples format where each node is [depth, roleCode, name, props?]:

{ "v": 1, "title": "Hacker News", "url": "https://news.ycombinator.com", "nodes": [ [0, "doc", "Hacker News"], [1, "nav", "Navigation"], [2, "lnk", "new", {"href": "/newest"}], [2, "lnk", "comments", {"href": "/newcomments"}], [1, "lst", ""], [2, "li", "Show HN: VulpineOS"], [2, "li", "Ask HN: Best AI agent frameworks?"] ] }

Compression Strategies

StrategyExampleSavings
Short role codesheadingh2, buttonbtn, linklnk~30% on role strings
Skip structural wrapperssection, group, paragraph removed~20% node reduction
Single-child flatteningParent with one child → merge into parent~10% node reduction
Adjacent text mergingThree text nodes → one combined string~5% token reduction
Omit empty/default fieldsNo props key if empty~5% overhead reduction

Role Code Map

Over 50 roles are mapped to short codes:

RoleCodeRoleCode
documentdocheading (level N)hN
buttonbtnlinklnk
textboxtxtcheckboxchk
radioradcomboboxcmb
listitemlinavigationnav
tabletblrowrow
cellcelimageimg

Protocol

{ "method": "Page.getOptimizedDOM", "params": { "maxDepth": 10, "maxNodes": 500, "maxTextLength": 200 } }

All parameters are optional — sensible defaults are applied.

Configuration

vulpineos.dom_export.enabled = true // default

Files Modified

  • additions/juggler/content/PageAgent.jsROLE_MAP, SKIP_ROLES, _getOptimizedDOM() method
  • additions/juggler/protocol/Protocol.jsPage.getOptimizedDOM definition
  • additions/juggler/protocol/PageHandler.js — handler routing
  • settings/camoufox.cfgvulpineos.dom_export.enabled preference

See also

Last updated on