Export the UI as text for agents.
Adds toContext(): the captured UI as a text outline or JSON tree containing structure, roles, visible text, state and optional bounds. It skips hidden content and collapses wrappers that add no information.
npm install @zumer/snapdom@latest @zumer/snapdom-plugins@latestUsage
import { snapdom } from '@zumer/snapdom';
import { contextExport } from '@zumer/snapdom-plugins/context-export';
const el = document.querySelector('#target');
const result = await snapdom(el, { plugins: [contextExport()] });
const outline = await result.toContext();
const { root, truncated, nodes } = await result.toContext({ format: 'json' });
Options
| Option | Type | Default | Description |
|---|---|---|---|
format | 'outline' | 'json' | 'outline' | Text outline or { root, truncated, nodes } |
maxTextLength | number | 120 | Per-node text limit; longer text ends with an ellipsis |
maxNodes | number | 800 | Node limit; output reports truncation |
geometry | boolean | true | Include [x, y, width, height] relative to the capture root |
needs | 'clone' | 'render' | 'render' | 'clone' skips rendering; only valid on a per-capture plugin |
The tree is frozen during capture. Per-call options can change format, maxTextLength, or omit captured geometry. They cannot increase maxNodes or restore geometry that was not captured. Open shadow roots and slots follow core's exclusion policy. Sensitive input values are omitted; other input/textarea values are masked. Ordinary page text and attributes remain in the output.
Use contextExport({ needs: 'clone' }) when you only need structured output. That result has no image, so result.url and image exports throw.