MCPcopy Create free account
hub / github.com/experdot/pointer / screenshotElement

Function screenshotElement

src/renderer/src/utils/screenshot.ts:47–70  ·  view source on GitHub ↗
(
  element: HTMLElement,
  options: ScreenshotOptions = {}
)

Source from the content-addressed store, hash-verified

45 * Take a screenshot of a DOM element
46 */
47export async function screenshotElement(
48 element: HTMLElement,
49 options: ScreenshotOptions = {}
50): Promise<Blob> {
51 const { scale = 2, backgroundColor = '#ffffff' } = options
52
53 const canvas = await html2canvas(element, {
54 scale,
55 backgroundColor,
56 useCORS: true,
57 logging: false,
58 onclone: (_doc, clonedElement) => {
59 // Sanitize colors in the cloned element before rendering
60 sanitizeColors(clonedElement)
61 }
62 })
63
64 return new Promise((resolve, reject) => {
65 canvas.toBlob(
66 (blob) => (blob ? resolve(blob) : reject(new Error('Failed to create blob'))),
67 'image/png'
68 )
69 })
70}
71
72/**
73 * Download a Blob as a file

Callers 1

exportStore.tsFile · 0.90

Calls 1

sanitizeColorsFunction · 0.85

Tested by

no test coverage detected