← 返回
未分类

DOM Capture Engine

DOM capture engine that can export any DOM subtree as SVG, PNG, JPG, WebP, Canvas, or Blob, supporting inline styles, fonts, background images, pseudo-elemen...
DOM捕获引擎,支持将任意DOM子树导出为SVG、PNG、JPG、WebP、Canvas或Blob,并保留内联样式、字体、背景图片及伪元素。
openlark
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 281
下载
💾 0
安装
1
版本
#latest

概述

snapdom — DOM Capture Engine

Use Cases

Use this skill when users request to take a screenshot of a web page element, DOM node, or HTML fragment, export it as an image, generate a web page snapshot, or convert any DOM element to an image/Canvas.

Installation

NPM:

npm i @zumer/snapdom

CDN (script tag):

<script src="https://unpkg.com/@zumer/snapdom/dist/snapdom.js"></script>

Quick Start

Shortcuts (One-off export)

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

// Export a DOM element as PNG
const png = await snapdom.toPng(document.querySelector('#card'));
document.body.appendChild(png);

// Other formats
const blob = await snapdom.toBlob(document.querySelector('#card'));
const svgImg = await snapdom.toSvg(document.querySelector('#card'));

Reusable Capture (Clone once, export multiple times)

const result = await snapdom(document.querySelector('#card'));
const png = await result.toPng();
const jpg = await result.toJpg({ quality: 0.92 });
await result.download({ format: 'jpg', filename: 'card.jpg' });

Common Options

OptionTypeDefaultDescription
------------------------------------
scalenumber1Output scale multiplier
width / heightnumber-Force output dimensions
qualitynumber1JPG/WebP quality 0~1
backgroundColorstring"#fff"Background color for JPG/WebP
embedFontsbooleanfalseEmbed non-icon fonts
useProxystring''CORS proxy URL
excludestring[]-CSS selectors to exclude
filterfunction-Filter function (el) => boolean
debugbooleanfalseOutput silent errors to console.warn

Examples

// High-definition screenshot (2x)
await snapdom.toPng(el, { scale: 2 });

// CORS cross-origin images
await snapdom.toPng(el, { useProxy: 'https://proxy.corsfix.com/?' });

// Exclude elements
await snapdom.toPng(el, { exclude: ['.cookie-banner', '.tooltip'] });

// Filter out display:none elements
await snapdom.toPng(document.body, {
  filter: el => window.getComputedStyle(el).display !== 'none'
});

xbrowser Integration

When capturing in a xbrowser environment, SnapDOM must be run through the browser's execution context. Recommended pattern:

// After an xbrowser snapshot, execute in the page via evaluate
await browser.evaluate(async (selector) => {
  const { snapdom } = window._snapdom || await import('https://unpkg.com/@zumer/snapdom/dist/snapdom.mjs');
  const el = document.querySelector(selector);
  if (!el) throw new Error(`Element not found: ${selector}`);
  const result = await snapdom(el, { scale: 2, embedFonts: true });
  const dataUrl = await result.toPng();
  return dataUrl;
}, selector);

See references/api_reference.md for detailed API documentation and full options list.

Plugins

Install official plugins:

npm install @zumer/snapdom-plugins

Register and use:

import { snapdom } from '@zumer/snapdom';
import { filter, timestampOverlay } from '@zumer/snapdom-plugins';

snapdom.plugins(
  [filter, { preset: 'grayscale' }],
  [timestampOverlay, { position: 'bottom-right' }]
);

const out = await snapdom(element);
const png = await out.toPng();

Plugin lifecycle hooks: beforeSnapbeforeCloneafterClonebeforeRenderafterRenderbeforeExportafterExport.

Example Reference assets/demo.html

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-08 03:23 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

Sqlite Client

openlark
SQLite 数据库操作技能。当用户需要创建、读取、查询或修改 SQLite 数据库(.db 文件)时使用。
★ 0 📥 678

Toutiao Graphic Publisher

openlark
通过浏览器自动化在头条发布图文内容,支持智能排版、自动生成热门标签等功能。
★ 2 📥 939

Chartjs

openlark
Chart.js 图表技能,用于生成折线图、柱状图、饼图、雷达图、散点图等可视化图表。
★ 0 📥 654