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

Export the frozen HTML.

Adds toHtml(), which returns the frozen clone with its captured styles and fonts as an HTML document. You can reopen the captured layout without exporting it as a bitmap.

npm install @zumer/snapdom@latest @zumer/snapdom-plugins@latest

Usage

import { snapdom } from '@zumer/snapdom';
import { htmlExport } from '@zumer/snapdom-plugins/html-export';

const el = document.querySelector('#target');
const result = await snapdom(el, { plugins: [htmlExport()] });
const html = await result.toHtml();              // full <!DOCTYPE html> string

// Or download a .html file:
await result.toHtml({ download: 'snapshot.html' });

Options

OptionTypeDefaultDescription
fullDocumentbooleantrueWrap output in <!DOCTYPE html>…; if false, return just <style> + the fragment
filenamestring'capture.html'Download filename when opts.download is true
titlestring'Captured interface'Escaped document title
langstring'en'Escaped document language

Per-call opts accepts fullDocument, filename and download. Set download: true to download, or pass a filename string. The method returns the HTML string either way.

The document retains source markup, including event-handler attributes; it is not sanitized.

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.