Skip to content
SnapDOMTry SnapStudioGitHub★ 8K
Library Comparison

SnapDOM vs modern-screenshot

Two modern libraries, the same core idea: clone the DOM and let the browser render it inside an SVG <foreignObject>. Where they differ, and how to move between them.

TL;DR

Both render cloned DOM through foreignObject and export SVG, PNG, JPEG, WebP, Canvas and Blob. modern-screenshot has a TypeScript API. SnapDOM adds a plugin system for HTML, structured context and maps, searchable PDF, editable vector, GIF and video. Both are MIT-licensed.

SnapDOM vs modern-screenshot, head to head

Each library exports the same element to PNG five times. The average includes fresh and repeated calls; SnapDOM can reuse the unchanged capture. The gap depends on your hardware, content and capture pattern.

Test element to be captured by both libraries.
SnapDOM
Waiting to start…
modern-screenshot
Waiting to start…

Same approach, different scope

modern-screenshot and SnapDOM belong to the same family as html-to-image. Where html2canvas re-implements the CSS painter, they deep-clone the DOM, inline styles, fonts and images, and wrap the clone in an SVG <foreignObject> for the browser to render. A shared approach does not mean identical output or timing; test the content and browsers you use.

Core output formats overlap. SnapDOM exposes a capture and export lifecycle, with official plugins for other representations and transformations. Both have browser-specific rendering behavior worth checking on complex pages.

Feature matrix

FeatureSnapDOMmodern-screenshot
Rendering approachClone + foreignObjectClone + foreignObject
Output formatsSVG · PNG · JPG · WebP · Canvas · BlobPNG · JPEG · WebP · SVG · Canvas · Blob
Plugin systemYesNo
Web fonts (@font-face)EmbeddedYes
Pseudo-elementsYesYes
Shadow DOMOpen rootsOpen roots
TypeScript-first APITyped, JS coreYes
Runtime dependencies00
LicenseMITMIT

Feature support in other libraries changes. For anything version-specific, check their docs, or run the live benchmark above and compare the output.

When to use which

Choose SnapDOM when…

  • You need fast captures, including repeats of the same element (live benchmark).
  • Your output depends on browser-rendered CSS, fonts or open Shadow DOM; test those elements in your target browsers.
  • You need PDF, editable vector, HTML or agent context, through plugins or your own.

Check your existing workflow…

  • Decide whether post-processing or lifecycle hooks suit your transformations.
  • Test your Web Components in the browsers you support.
  • Check Safari output and complex @font-face setups with your assets.
  • Image formats overlap; optional SnapDOM plugins add HTML, context, PDF and animation exports.

Same task, side by side

Capture #card as a PNG and add the image to the page:

modern-screenshot

import { domToPng } from 'modern-screenshot';

const dataUrl = await domToPng(document.querySelector('#card'));
const img = new Image();
img.src = dataUrl;
document.body.appendChild(img);

SnapDOM

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

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

modern-screenshot's domToPng resolves to a data-URL string; SnapDOM's toPng resolves to a ready-to-append HTMLImageElement. For a PNG data URL, read (await snapdom.toPng(el)).src; snapdom.toRaw(el) returns an SVG data URL.

Migration map

Check format and return type at each call site. SnapDOM image helpers return HTMLImageElement; read .src for a data URL. Its default Blob format is SVG, so request PNG when migrating a PNG Blob export.

modern-screenshotSnapDOM
domToPng(node)(await snapdom.toPng(node)).src
domToJpeg(node)(await snapdom.toJpg(node)).src
domToWebp(node)(await snapdom.toWebp(node)).src
domToSvg(node)snapdom.toRaw(node)
domToCanvas(node)snapdom.toCanvas(node)
domToBlob(node)snapdom.toBlob(node, { format: 'png' })

Frequently asked questions

Is SnapDOM or modern-screenshot faster?

It depends on the element, assets, browser and whether the capture is fresh or repeated. Run the live lab with its listed versions, then test both on your own content.

What does SnapDOM offer that modern-screenshot doesn't?

A plugin lifecycle and the official plugins listed above. The two share the core SVG, raster image, Canvas and Blob outputs.

Can I migrate from modern-screenshot without rewriting everything?

Common exports have equivalents; return types and options need review. See the migration map above for the PNG string, SVG and Blob cases.

Are both libraries free for commercial use?

Yes. Both are MIT-licensed. Neither charges per capture or needs a screenshot server.

Try it here

Live element

Hard parts

transform + shadow

Result

Nothing captured yet

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