# SnapDOM: v3 reference Last updated: 2026-11-12. SnapDOM (`@zumer/snapdom`) is a high-performance DOM engine that captures a rendered element in the browser and exports it as PNG, SVG or canvas. Plugins turn the same capture into PDF, HTML, editable vector, GIF, video or context for agents. Zero runtime dependencies; about one release a week. It captures a DOM subtree, its computed styles and its assets into a reusable result. The core exports SVG, PNG, JPG, WebP, canvas and blobs, and reports capture geometry. Plugins add HTML, text or JSON context, annotated element maps, searchable, paginated PDFs and editable vector artwork and recordings. SnapDOM has two integrated render engines: `svg` (default) and `html-in-canvas`. Both receive the same finished clone; the second uses the browser's native painter (Chrome 157 and newer) and falls back to SVG when unavailable or unsuitable for the capture. Package: `@zumer/snapdom`. License: MIT. Source: https://github.com/zumerlab/snapdom. Documentation: https://snapdom.dev/docs/. This reference describes SnapDOM v3.x.x. Release details: https://github.com/zumerlab/snapdom#installation. Preserved v2 branch: https://github.com/zumerlab/snapdom/tree/v2. ## Installation ```bash npm install @zumer/snapdom@latest ``` ```js import { snapdom } from '@zumer/snapdom'; ``` For a browser script tag, use the IIFE build, which exposes `window.snapdom`: ```html ``` For a browser ES module: ```html ``` The package entry is ESM; there is no CommonJS build. The core has no runtime dependencies. Official plugins are separate packages: the toolbox `@zumer/snapdom-plugins` 5.x, and `@zumer/snapdom-pdf`, `@zumer/snapdom-vector` and `@zumer/snapdom-stream` 1.x. All need SnapDOM 3.4.0 or newer within 3.x; the package major versions do not match. The toolbox is published on npm: ```bash npm install @zumer/snapdom-plugins@latest ``` ```js import { htmlExport, contextExport, agentMap } from '@zumer/snapdom-plugins'; ``` For plugins loaded from a CDN, map the core import and keep it external in the plugin URL so recordings share the same runtime: ```html ``` The core registry subpath uses the same runtime as the package root: ```js import { registerPlugins, clearPlugins, getGlobalPlugins } from '@zumer/snapdom/plugins'; ``` ## Choose the output for the task SnapDOM captures an existing browser interface as pixels, document content, editable artwork or structured data. Choose the result the consumer needs before choosing an exporter. Register the required plugins before capture; an existing result cannot gain a plugin afterward. | Task | Use | Result | | --- | --- | --- | | Show appearance, attach a screenshot or compare pixels | Core `toPng()`, `toJpg()`, `toWebp()` | Image element; use `toBlob({ format: 'png' })` for a file Blob | | Produce a report, invoice or printable document | `pdf()` → `toPdf()` | PDF Blob with pagination, searchable text, links and optional fields | | Edit artwork or paste it into Figma | `vector()` → `toVector()` / `toFigma()` | Native SVG string / clipboard write | | Read captured content and field state with an agent | `contextExport()` → `toContext()` | Text outline or JSON tree | | Relate interactive elements to their captured appearance | `agentMap()` → `toAgentMap()` | Element map with bounding boxes and optional annotated image | | Preserve captured markup, styles and assets | `htmlExport()` → `toHtml()` | HTML document or fragment; captured markup, not restored application behavior | | Record changes over time | `gifExport()` / `videoExport()` → `toGif()` / `toMp4()` | Recording Blob from new live frames at export time | | Keep a live canvas of an element, for a WebGL texture or a video overlay | `stream(element)`, or `streamExport()` → `toStream()` | Canvas updated in place, repainting only the boxes that changed | | Render terminal-style artwork | `asciiExport()` → `toAscii()` | Text | Core `toSvg()` preserves browser appearance through HTML in SVG `foreignObject`; use Vector when the destination needs editable native SVG shapes and text. For content extraction, start with context JSON or an outline; add an image when appearance matters, and an agent map when element locations matter. Context and maps are bounded capture representations, not complete DOM dumps or browser interaction tools. ## Capture once, export several ways ```js const capture = await snapdom(document.querySelector('#card')); const png = await capture.toPng({ width: 1200, dpr: 1 }); const svgBlob = await capture.toBlob(); await capture.download({ format: 'jpg', filename: 'card.jpg' }); document.body.appendChild(png); ``` These exports use the captured state, even if the live element changes later. Call `snapdom(element)` again to capture those changes. Eligible repeated captures may reuse an unchanged result or update a changed subtree. Recording plugins are an explicit exception: `toGif()` and `toMp4()` take new frames from the live element when the export starts. ## Core API ```text snapdom(element, options?) → Promise snapdom.fromString(html, options?) → Promise snapdom.toRaw(element, options?) → Promise snapdom.toSvg(element, options?) → Promise snapdom.toPng(element, options?) → Promise snapdom.toJpg(element, options?) → Promise snapdom.toWebp(element, options?) → Promise snapdom.toCanvas(element, options?) → Promise snapdom.toBlob(element, options?) → Promise snapdom.download(element, options?) → Promise snapdom.plugins(...definitions) → snapdom snapdom.preCapture() → void snapdom.version → string ``` Static shortcuts capture and then export. Use `snapdom.toJpg()` for the JPEG shortcut; `result.toJpeg()` is also available on a capture result. `snapdom.toImg()` is a deprecated alias for `snapdom.toSvg()`. `fromString()` mounts markup offscreen in the live document, lets page CSS and fonts apply, captures it, then removes the mount. A single root element becomes the target; otherwise it captures the wrapper. The markup goes through `innerHTML`: use trusted HTML or sanitize it first. This method requires a browser DOM; it does not render HTML in Node.js. ```js const capture = await snapdom.fromString('
Hello
'); const image = await capture.toPng(); ``` ## CaptureResult | Member | Result | Meaning | | --- | --- | --- | | `url` | string | SVG data URL on the SVG engine; lazily encoded PNG after successful native capture | | `needs` | `'clone'` or `'render'` | Stage reached by this capture | | `meta` | frozen CaptureMeta | Render geometry; throws below render | | `warnings` | array | Fallback or degradation records; export-time entries append after export | | `toRaw()` | string, synchronous | Same URL as `url`; no rasterization on SVG, PNG encoding on first native read | | `toSvg(options?)` | Promise | SVG-backed image normally; PNG-backed after successful native capture | | `toImg(options?)` | Promise | Deprecated alias for `toSvg()` | | `toPng(options?)` | Promise | PNG image | | `toJpg(options?)`, `toJpeg(options?)` | Promise | JPEG image | | `toWebp(options?)` | Promise | WebP image | | `toCanvas(options?)` | Promise | Rasterized canvas | | `toBlob(options?)` | Promise | SVG on the SVG engine, PNG on the native engine, unless a format was explicitly selected | | `download(options?)` | Promise | Triggers a browser download | | `to(name, options?)` | Promise | Runs a core or plugin export by name | Examples of plugin helpers are `toHtml()`, `toContext()` and `toAgentMap()`. ### Choosing an engine Set `engine: 'html-in-canvas'` to request the second integrated engine. It runs where the browser exposes `drawElementImage()`: Chrome 157 and newer, without a flag. Firefox and Safari have no implementation and get the SVG engine from the same call. A plugin with a `beforeRender` or `afterRender` hook (html-export, pdf, vector, and redact-inputs with `blocks` or `attributes`) sends the capture to SVG; the other official plugins run on the native engine. SVG stays the default because it is faster: the native paint waits for a rendering update, about 35 ms on a small card where SVG takes 3. Pick html-in-canvas when scrollbars, or anything else the SVG image draws differently, have to match the page. Both engines paint the same clone, so `