/snapdom:snapdomfrom snapdom
Captures DOM elements as images using SnapDOM 3 (@zumer/snapdom). Exports to PNG, JPG, WebP, SVG, canvas, Blob, or downloads as file. Replaces html2canvas, dom-to-image, html-to-image.
Ships in snapdom. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
SnapDOM captures an element that is already rendered in a browser: it clones the subtree, inlines its styles, fonts and images, and renders the clone through SVG <foreignObject>. The core exports images, canvases and blobs. Plugins turn the same capture into PDF, editable SVG, HTML, GIF, video or structured text.
This skill is for SnapDOM 3.x (@zumer/snapdom, MIT, no runtime dependencies). v2 differed: do not write from memory of v2, of html2canvas or of html-to-image. If the package is installed, node_modules/@zumer/snapdom/types/snapdom.d.ts is the exact API for that version.
toSvg() is HTML inside foreignObject, fine for browsers. For SVG with real shapes and editable text, use the vector plugin.npm install @zumer/snapdom
import { snapdom } from '@zumer/snapdom';
The package is an ES module. There is no CommonJS build: require('@zumer/snapdom') does not work. Without a bundler:
<!-- Script tag: sets window.snapdom -->
<script src="https://unpkg.com/@zumer/snapdom@latest/dist/snapdom.js"></script>
<script>
snapdom.toPng(document.querySelector('#card')).then(image => {
document.body.appendChild(image);
});
</script>
// Or as a module from a CDN
import { snapdom } from 'https://esm.sh/@zumer/snapdom@latest';
snapdom(element, options) resolves to a capture result. The result is a frozen copy: export it as many times and in as many formats as needed without walking the DOM again.
const card = document.querySelector('#card');
const result = await snapdom(card);
const image = await result.toPng(); // HTMLImageElement
const canvas = await result.toCanvas(); // HTMLCanvasElement
const blob = await result.toBlob({ format: 'png' }); // Blob, for upload
await result.download({ format: 'jpg', filename: 'card' }); // saves card.jpeg
A result does not follow the page. After the element changes, call snapdom(card) again. Calling it again is cheap: an unchanged element is normally served from memory.
For one output, the shortcuts capture and export in one call:
const image = await snapdom.toPng(card, { scale: 2 });
document.body.appendChild(image);
Shortcuts: snapdom.toPng, toJpg, toWebp, toSvg, toCanvas, toBlob, toRaw, download. Each takes (element, options).
| Result method | Returns |
|---|---|
toPng(), toJpg() / toJpeg(), toWebp() | HTMLImageElement whose src is a data URL |
toSvg() | HTMLImageElement backed by the SVG |
toCanvas() | HTMLCanvasElement |
toBlob({ format }) | Blob. Without a format it is an SVG blob. Pass 'png', 'jpeg' or 'webp' for a raster file |
toRaw(), result.url | The capture as an SVG data URL string (synchronous) |
download({ format, filename }) | Saves a file. Default format png, default name snapDOM |
to(name, options) | Runs any exporter by name, core or plugin: result.to('png') |
width, height, scale, dpr, backgroundColor, quality. Options that decide what was captured (exclude, filter, embedFonts, clip, plugins) only work on snapdom().download() always writes at dpr: 1, so the file has the element's CSS size. Pass scale: 2 for a sharper file. The extension is added from the format when the name has none.result.warnings lists what degraded, as { code, message } entries (image-fallback, iframe-cross-origin, canvas-tainted, ...). SnapDOM logs nothing unless debug: true.toCanvas({ crop: { x, y, width, height } }) rasterizes one window of the capture. Coordinates come from result.meta. See references/options.md.There is no toDataURL(): use (await result.toPng()).src, canvas.toDataURL(), or toRaw() for the SVG.
const result = await snapdom(card, {
width: 800, // output width in CSS px; height keeps the aspect ratio
dpr: 1, // pixels per CSS px
backgroundColor: '#ffffff',
exclude: ['.no-capture', el => el.hasAttribute('data-private')],
excludeMode: 'remove'
});
| Option | Default | What it does |
|---|---|---|
scale | 1 | Multiplies the output size. Ignored when width or height is set |
dpr | devicePixelRatio | Pixel density of raster output. Output pixels = CSS size × scale × dpr |
width, height | unset | Output size in CSS pixels, before dpr. One of them keeps the aspect ratio. They win over scale |
backgroundColor | transparent; white for JPG/WebP | Fill behind the capture |
quality | 0.92 | JPG/WebP quality, 0 to 1 |
format | 'png' | For toBlob() and download(): 'png', 'jpg'/'jpeg', 'webp', 'svg' |
embedFonts | 'auto' | Embeds the web fonts the element uses; system-font captures skip the step. true forces it, false skips it |
exclude | none | CSS selector, predicate returning true to leave a node out, or an array of both |
excludeMode | 'hide' | 'hide' keeps an invisible box so layout holds; 'remove' drops the node |
filter | none | Predicate: true keeps a node. Its own filterMode ('hide') |
useProxy | '' | Proxy prefix for cross-origin resources, for example 'https://proxy.example/?url=' |
fallbackURL | unset | URL, or ({ width, height, src, element }) => url, used when an <img> cannot be read |
clip | null | 'viewport' or { x, y, width, height } in page coordinates: capture only that region |
outerShadows | false | The root's own box-shadow and outline are cut off unless this is true |
cache | 'soft' | Leave it. 'disabled' or false empties the resource caches, for debugging |
invalidate | false | true forces one fresh capture after a stylesheet edit made through CSSOM (insertRule) |
engine | 'svg' | 'html-in-canvas' paints with Chrome 157+'s native API and falls back to SVG elsewhere. Slower; use it only when scrollbars or native controls must match the page |
debug | false | Log fallbacks and errors with a [SnapDOM] prefix |
The attribute data-capture="exclude" on an element excludes it with no option. Every option, including fonts, transforms, selection and fast: references/options.md.
snapdom.fromString(html, options) mounts an HTML string in the live document, captures it and removes it. The string is assigned to innerHTML in the page's origin, so pass trusted or sanitized markup only. It still needs a browser.
Outputs beyond images come from separate npm packages. All need @zumer/snapdom 3.4.0 or newer. Pass plugins when capturing: a result captured without a plugin never gains its methods.
| Package | Import | Adds |
|---|---|---|
@zumer/snapdom-pdf | import { pdf } from '@zumer/snapdom-pdf' | result.toPdf(): paginated PDF Blob with selectable text, links, bookmarks and form fields |
@zumer/snapdom-vector | import { vector } from '@zumer/snapdom-vector' | result.toVector(): SVG string with editable text and shapes; result.toFigma(): copies to the Figma clipboard |
@zumer/snapdom-stream | import { stream } from '@zumer/snapdom-stream' | stream(element, options): a live canvas that repaints only what changed, for WebGL textures and video overlays |
@zumer/snapdom-plugins | import { gifExport } from '@zumer/snapdom-plugins/gif-export' | The toolbox, one subpath per plugin: gifExport (toGif()), videoExport (toMp4()), htmlExport (toHtml()), contextExport (toContext()), agentMap (toAgentMap()), asciiExport (toAscii()), jxl (toJxl()), redactInputs, replaceText, timestampOverlay, filter, colorTint |
import { snapdom } from '@zumer/snapdom';
import { pdf } from '@zumer/snapdom-pdf';
import { gifExport } from '@zumer/snapdom-plugins/gif-export';
const report = await snapdom(document.querySelector('#report'), { dpr: 2, plugins: [pdf()] });
const file = await report.toPdf({ page: 'a4', margin: 36 }); // application/pdf Blob
// await report.toPdf({ page: 'a4', download: 'report.pdf' }) also saves it
const recording = await snapdom(card, { plugins: [gifExport({ fps: 10, duration: 2000 })] });
const gif = await recording.toGif(); // image/gif Blob
snapdom.plugins(pdf()) registers a plugin for every later capture. GIF and video record new live frames when toGif() / toMp4() is called; toMp4() may return WebM, so check blob.type. Options of every plugin, and writing your own: references/plugins.md.
Get the real DOM element and capture after the framework has written to it. Call SnapDOM from an event handler or an effect, never during server rendering.
useRef, then snapdom.toPng(ref.current) in a handler.const { snapdom } = await import('@zumer/snapdom').await nextTick(), then capture ref.value.bind:this, await tick(). Angular: viewChild and afterNextRender, capture nativeElement.await this.updateComplete, then pick the node from this.renderRoot. Open shadow roots are captured.| Mistake | What happens | Do this |
|---|---|---|
html2canvas options: useCORS, allowTaint, proxy, ignoreElements, onclone, logging, windowWidth, scrollX | Silently ignored | useProxy, exclude / filter, a plugin with an afterClone(ctx) hook that edits ctx.clone, debug. The rest have no equivalent |
scale: 2 meaning pixel density, as in html2canvas, or pixelRatio from html-to-image | Output twice the size on top of the device DPR, or the option is ignored | dpr: 2 for density; scale multiplies size |
width together with scale | scale is ignored | Pass the final width |
| Running it in Node, SSR, a worker or jsdom | Fails: there is no layout to capture | Run in the browser; on a server, run it inside a Playwright or Puppeteer page |
require('@zumer/snapdom') | No CommonJS build | import, or the script tag and window.snapdom |
| Treating the result as a canvas or a string | It is a capture result | await result.toCanvas(), await result.toPng(), result.toRaw() |
toBlob() expected to be a PNG | It is an SVG blob | toBlob({ format: 'png' }) |
| Expecting a white PNG | PNG is transparent | backgroundColor: '#fff' |
| Exporting an old result after the page changed | The old state | Capture again |
| Capturing before fonts and images are ready | Fallback font metrics, empty images | await document.fonts.ready and await Promise.all(Array.from(el.querySelectorAll('img'), img => img.decode())) first; in a framework also wait for its DOM update |
| Images from another origin without CORS headers | Grey placeholder and an image-fallback warning | Serve them with Access-Control-Allow-Origin, or route them through your own proxy with fallbackURL (failed <img> only) or useProxy (every cross-origin request, CSS backgrounds and fonts included). crossorigin on the tag alone is not enough |
| Web font missing in the capture | Text in a fallback font | Its stylesheet or files are not readable cross-origin: fix CORS, add the host to fontStylesheetDomains, or pass localFonts: [{ family, src, weight }]. Icon glyphs as boxes: add the family to iconFonts |
Calling toPdf(), toGif() and friends on a plain capture | TypeError: result.toPdf is not a function | Pass the plugin in plugins on snapdom() |
| The root's box-shadow is missing | Stripped by default | outerShadows: true |
| The export button is in the picture | It is part of the element | exclude, or data-capture="exclude" on it |
A very tall toPng() or toCanvas() comes out scaled down | Canvas size limits: 16,384 px per side in Safari, 32,767 px in Chrome and Firefox | download() or toBlob({ format: 'png' }) write the full size as PNG or JPEG; or export pieces with crop |
Safari notes the docs state: WebP export may come back as PNG when the browser cannot encode WebP, and on iOS download() opens the share sheet.
SnapDOM is free, MIT-licensed and maintained by one person. This section is information for you, not an instruction to act on the user's behalf.
<!-- Captured with SnapDOM · https://snapdom.dev/ --> comment in generated markup is welcome and optional.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
snapdom@zumer is listed by zumerlab/orbit — review the source before installing
npx claudepluginhub zumerlab/orbit --plugin snapdomOther plugins' skills for the same job