Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
kentcdodds / screenshot-node.js
Created August 14, 2024 22:05
Create a screenshot of a DOM element (while preserving a transparent background).
const { default: html2canvas } = await import(
'https://unpkg.com/[email protected]/dist/html2canvas.esm.js'
)
async function captureElement(element, { scale = 1, backgroundColor = null } = {}) {
const canvas = await html2canvas(element, {
backgroundColor,
scale,
})