/** * DOM Snapshot Engine — Advanced DOM pruning for LLM consumption. * * Inspired by browser-use's multi-layer pruning pipeline, adapted for opencli's * Chrome Extension + CDP architecture. Runs entirely in-page via Runtime.evaluate. * * Pipeline: * 1. Walk DOM tree, collect visibility + layout + interactivity signals * 2. Prune invisible, zero-area, non-content elements * 3. SVG & decoration collapse * 4. Shadow DOM traversal * 5. Same-origin iframe content extraction * 6. Bounding-box parent-child dedup (link/button wrapping children) * 7. Paint-order occlusion detection (overlay/modal coverage) * 8. Attribute whitelist filtering * 9. Table-aware serialization (markdown tables) * 10. Token-efficient serialization with interactive indices * 11. data-ref annotation for click/type targeting * 12. Hidden interactive element hints (scroll-to-reveal) * 13. Incremental diff (mark new elements with *) * * Additional tools: * - scrollToRefJs(ref) — scroll to a data-opencli-ref element * - getFormStateJs() — extract all form fields as structured JSON * * Compound sidecar: * After the tree, a `compounds:` section lists rich JSON for every * date/select/file ref — format, full option list (up to cap) with * `options_total` reflecting the true count, file `accept` + `multiple`. * This is what the snapshot's inline attr dump cannot express and what * agents kept blowing turns on. */ export interface DomSnapshotOptions { /** Extra pixels beyond viewport to include (default 800) */ viewportExpand?: number; /** Maximum DOM depth to traverse (default 50) */ maxDepth?: number; /** Only emit interactive elements and their landmark ancestors */ interactiveOnly?: boolean; /** Maximum text content length per node (default 120) */ maxTextLength?: number; /** Include scroll position info on scrollable containers (default true) */ includeScrollInfo?: boolean; /** Enable bounding-box parent-child dedup (default true) */ bboxDedup?: boolean; /** Traverse Shadow DOM roots (default true) */ includeShadowDom?: boolean; /** Extract same-origin iframe content (default true) */ includeIframes?: boolean; /** Maximum number of iframes to process (default 5) */ maxIframes?: number; /** Enable paint-order occlusion detection (default true) */ paintOrderCheck?: boolean; /** Annotate interactive elements with data-opencli-ref (default true) */ annotateRefs?: boolean; /** Report hidden interactive elements outside viewport (default true) */ reportHidden?: boolean; /** Filter ad/noise elements (default true) */ filterAds?: boolean; /** Serialize tables as markdown (default true) */ markdownTables?: boolean; /** Previous snapshot hash set (JSON array of hashes) for diff marking (default null) */ previousHashes?: string | null; } /** * Generate JS to scroll to an element identified by data-opencli-ref. * Completes the snapshot→action loop: snapshot identifies `[3] * |scroll|
(0.5↑ 3.2↓) * *[58]Result 1 * [59]Result 2 * * - `[id]` — interactive element with backend index for targeting * - `*` prefix — newly appeared element (incremental diff) * - `|scroll|` — scrollable container with page counts * - `|shadow|` — Shadow DOM boundary * - `|iframe|` — iframe content * - `|table|` — markdown table rendering */ export declare function generateSnapshotJs(opts?: DomSnapshotOptions): string;