Snapshots
The snapshot command returns a compact accessibility tree with refs for element interaction.
Options
Filter output to reduce size:
| Option | Description |
|---|---|
-i, --interactive | Only interactive elements (buttons, links, inputs) |
-u, --urls | Include href URLs for link elements |
-c, --compact | Remove empty structural elements |
-d, --depth | Limit tree depth |
-s, --selector | Scope to CSS selector |
Output format
The default text output is compact and AI-friendly:
Using refs
Refs from the snapshot map directly to commands:
Ref lifecycle
Surviving DOM elements retain their refs across snapshots and same-document updates. Replacing an element or navigating its page or iframe invalidates its refs without recycling IDs. Virtual accessibility nodes have snapshot-local refs. Re-snapshot after interactions to observe changes, and always after navigation:
Annotated screenshots
For visual context alongside text snapshots, use screenshot --annotate to overlay numbered labels on interactive elements. Each label [N] maps to ref @eN:
In native mode, annotated screenshots currently work on the CDP-backed browser path (Chromium/Lightpanda). The Safari/WebDriver backend does not yet support --annotate.
Headless Chromium screenshots hide native scrollbars for consistent image output. Pass --hide-scrollbars false when launching to keep native scrollbars visible.
Annotated screenshots also cache refs, so you can interact with elements immediately. This is useful when the text snapshot is insufficient for unlabeled icons, canvas content, or visual layout verification.
Iframes
Snapshots automatically detect and inline iframe content. Each Iframe node in the main frame is resolved and its child accessibility tree is included directly beneath it. Refs assigned to elements inside iframes carry frame context, so interactions work without switching frames first.
Only one level of iframe nesting is expanded. Cross-origin iframes that block accessibility tree access and empty iframes are silently omitted.
To scope a snapshot to a single iframe, switch into it first:
Best practices
- Use
-ito reduce output to actionable elements - Re-snapshot after page changes to get updated refs
- Scope with
-sfor specific page sections - Use
-dto limit depth on complex pages - Use
screenshot --annotatewhen visual context is needed alongside refs
JSON output
For programmatic parsing in scripts:
Note: JSON uses more tokens than text output. The default text format is preferred for AI agents.