Open-source project
zumerlab/snapdom avatar
zumerlab/snapdom

SnapDOM: capture a DOM element once, export it six ways

High-performance engine for capturing, modifying, and converting DOM elements into any format.

8,245 stars312 forksJavaScriptMIT

At a glance

What is it?
A browser engine that turns a live element into a capture object holding styles, fonts and images, then exports that one object as SVG, PNG, JPG, WebP, canvas or Blob. Plugins cover self-contained HTML, agent context, PDF and recording, Plugins 4.x require SnapDOM 3.3.0 or newer within 3.x, and a Blob is SVG unless you name a format.
Who is it for?
It suits a team capturing cards, charts, invoices or dashboards in the page, without a server-side renderer and without a heavyweight dependency. It does not suit a pipeline built around CommonJS, because there is no CommonJS build, and it does not suit a workflow that expects a capture to follow later edits to the element, since a result deliberately keeps the state it was taken from.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository received new commits within the last day.
What is it written in?
Mainly JavaScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • zumerlab/snapdom8,245 ★ · +93
Star history
Repository2026-09-222026-11-15
zumerlab/snapdom8.2k8.2k

93 Stars in the last 54 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

A capture is an object you keep, not a file you write

The unit of work is a result object, and that is what makes the library different from a one-shot converter. You capture an element once and then ask that result for whichever output you need.

js
const result = await snapdom(card);

const image = await result.toPng();
const canvas = await result.toCanvas();
const blob = await result.toBlob({ format: 'png' });
await result.download({ format: 'jpg', filename: 'card' });

The important property is stated plainly: the result keeps that capture even if the source element later changes. If you need the new state you call the capture function again on the element. So staleness is your responsibility rather than the library's, which is exactly what you want when a chart animates or a user is typing into a form while you are exporting, and exactly what surprises people who expect a live handle. There is also a one-step shortcut form, where the capture and the export happen in a single call on the element itself.

js
import { snapdom } from '@zumer/snapdom';

const card = document.querySelector('#card');
const image = await snapdom.toPng(card);
document.body.appendChild(image);

There is no CommonJS build and plugins share the core runtime

The distribution is deliberately narrow. Three outputs are documented: an ES module for imports and bundlers, a script-tag build that exposes the library on the window object, and a TypeScript declaration file. There is no CommonJS build, so a pipeline that only resolves require calls needs configuration before it can load this package. The exports map makes the same point twice. The package root and the plugins subpath both resolve to the same module file and the same declaration file, and the documentation states that they share the same runtime and plugin registry. That is a feature when a plugin has to reach the capture, and a hazard when a page accidentally loads two copies, because each copy would carry its own registry. The manifest also marks the package as side effect free, which is what lets a bundler drop the import if nothing from it is used.

Plugins are separate packages and their majors must match

The core covers images and canvas. Everything else is a plugin, installed from a second package, and the README states that Plugins 4.x require SnapDOM 3.3.0 or newer within 3.x.

sh
npm i @zumer/snapdom@latest @zumer/snapdom-plugins@latest

The documented set covers self-contained HTML for saving a page fragment for later display, text and JSON context plus an image with an element map for giving an agent or a log a view of page content, searchable, paginated PDF for downloading a document, and animated GIF or browser-encoded video for recording changing content. The last two behave differently from everything else: image, HTML and context exports use the captured state, while the GIF and video plugins record the live element over time. A repository that formalises this has a plugin specification document and a contributing guide for plugins beside the feature list, so the plugin boundary is a designed extension point rather than an accident.

toBlob defaults to SVG unless you name a format

The output methods are listed with their return types, and one row catches people out. The image methods return an image element, the SVG method returns an SVG-backed image element, and the canvas method returns a canvas element. The blob method returns an SVG Blob unless a format was explicitly set on the capture or on the export. That single sentence changes what your download button does. The raw method and the url property hand back the capture's SVG data URL instead, and the download method downloads whichever format you chose. There is also a generic exporter that runs a core or plugin exporter by name, which is how a plugin's output is reached through the same result object. Two compatibility aliases survive: a jpeg alias for the jpg method, and an img method that remains available but for which toSvg is the better choice when you want an SVG image.

fast defaults to on, and invalidate exists for CSSOM edits

The invalidate option defaults to false and exists to refresh the capture after changes. Two more shape the area being captured: clip is unset by default and captures either the viewport or a rectangle in page coordinates, and captureSelection defaults to false, so a user's text selection is left out unless you ask for it. The canvas option is also unset, which means you can hand the capture an existing canvas instead of letting it allocate one.

exclude and filter are two mechanisms with two layout behaviours

Selecting what not to capture takes two different routes, and the difference shows up in layout. Exclude takes selectors or predicates, where a true result means exclude, and its mode defaults to hide, which keeps an invisible spacer so the surrounding layout does not collapse; setting the mode to remove takes that space away. Filter is the independent control: it takes a predicate where true keeps a node and false filters it out, and it has its own mode that governs the layout of rejected nodes separately from exclude. Three more options round out the everyday set. Font embedding defaults to auto, so the web fonts the capture uses are embedded. Background colour is transparent except for JPG and WebP, which get white. And resolution is two knobs rather than one, where scale applies when neither width nor height is set, dpr multiplies the pixel dimensions, and setting only one of width or height preserves the aspect ratio.

Long pages are windowed instead of one oversized canvas

The test script chains linting, type checking, release checks, bundle verification and a headless browser run, with separate variants for visual tests and for the Firefox and WebKit engines. There is a benchmarks document in the repository, and the release checks run as plain node tests over release and benchmark statistic scripts.

Editorial conclusion

It suits a team capturing cards, charts, invoices or dashboards in the page, without a server-side renderer and without a heavyweight dependency. It does not suit a pipeline built around CommonJS, because there is no CommonJS build, and it does not suit a workflow that expects a capture to follow later edits to the element, since a result deliberately keeps the state it was taken from. Check four things before you commit: that your bundler can consume an ES module only package, that your core version meets the plugin requirement (plugins 4.x need SnapDOM 3.3.0 or newer within 3.x), what format your Blob consumer actually assumes, since the default is SVG, and whether you need recording rather than capture, because the GIF and video plugins watch the live element over time instead of using the frozen result.

Frequently asked questions

How do I install SnapDOM?

Install the core and, when you need them, the official plugins using npm i @zumer/snapdom@latest @zumer/snapdom-plugins@latest. You can also load a script tag from a CDN that exposes the library on the window object, or import it as an ES module from a CDN. There is no CommonJS build.

Does SnapDOM capture fonts and images with the element?

The capture holds rendered DOM state with styles, fonts and images included, and the embedFonts option, which defaults to auto, embeds the web fonts the capture uses. The html-export plugin goes further and produces self-contained HTML with the captured styles and fonts included.

Why does my exported element show stale content?

A result deliberately keeps the capture it took, even if the source element changes afterwards, so you call the capture function again to get the new state. The invalidate option, which defaults to false, exists to refresh the capture after changes.

What do the SnapDOM plugins add to the core?

The core exports images and canvas. Plugins add self-contained HTML, text and JSON page context, an element map for visual agents, searchable, paginated PDF, animated GIF and browser-encoded video. The plugin subpath and the package root share the same runtime and plugin registry, and the repository carries a plugin specification and a plugin contributing guide.

Official sources

  1. License: MIT
  2. Project website
  3. README
  4. Releases
  5. zumerlab/snapdom on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/zumerlab-snapdom.svg)](https://hysenlabs.com/projects/zumerlab-snapdom)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/zumerlab-snapdom.svg)](https://hysenlabs.com/projects/zumerlab-snapdom)

Was this useful?