Skip to content
SnapDOMGitHub★ 8K
@zumer/snapdom-plugins · MIT

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@latest

Usage

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

OptionTypeDefaultDescription
format'outline' | 'json''outline'Text outline or { root, truncated, nodes }
maxTextLengthnumber120Per-node text limit; longer text ends with an ellipsis
maxNodesnumber800Node limit; output reports truncation
geometrybooleantrueInclude [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.

Try it here

Live element

Component preview
Capture an editable component
1,284+12% vs last week

Editable text and an open shadow root can be captured together.

Result

Nothing captured yet

Edit the title, then run. This uses the real library from unpkg.