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

Record the element as video.

Adds toMp4(), which records the live element through MediaRecorder. The returned Blob's type identifies the recorded container.

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

Usage

import { snapdom } from '@zumer/snapdom';
import { videoExport } from '@zumer/snapdom-plugins/video-export';

const el = document.querySelector('#target');
const result = await snapdom(el, { plugins: [videoExport({ fps: 30, duration: 4000 })] });
const blob = await result.toMp4();

// Or download directly:
await result.toMp4({ download: true });

The plugin tries supported MP4 codecs first, then WebM. A WebM fallback logs a warning; the default download filename matches the recorded .mp4 or .webm container. Explicit filenames and download strings are used as supplied.

Options

OptionTypeDefaultDescription
fpsnumber10Frames per second
durationnumber2000Total duration in ms (ignored if frames is set)
framesnumbernoneExplicit frame count (overrides duration)
backgroundstring'#ffffff'Color composited under transparent pixels
scalenumbercapture's scaleCapture scale
bitratenumbernonevideoBitsPerSecond passed to MediaRecorder
filenamestringnoneDownload filename; the default follows the recorded .mp4 / .webm container

Requires MediaRecorder and canvas.captureStream(), which may be unavailable in headless environments. Per-call opts override constructor options and accept download (boolean | string). Recording starts at the call and preserves capture options as GIF recording does. MediaRecorder uses a real-time clock, so slow captures can stretch duration.

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.