UNPKG

@remotion/renderer

Version:

Render Remotion videos using Node.js or Bun

52 lines (51 loc) 1.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.screenshotDOMElement = void 0; const puppeteer_evaluate_1 = require("./puppeteer-evaluate"); const puppeteer_screenshot_1 = require("./puppeteer-screenshot"); const screenshotDOMElement = async ({ page, imageFormat, jpegQuality, opts, height, width, timeoutInMilliseconds, scale, }) => { const { path } = opts; if (imageFormat === 'png' || imageFormat === 'pdf' || imageFormat === 'webp') { await (0, puppeteer_evaluate_1.puppeteerEvaluateWithCatch)({ pageFunction: () => { document.body.style.background = 'transparent'; }, args: [], frame: null, page, timeoutInMilliseconds, }); } else { await (0, puppeteer_evaluate_1.puppeteerEvaluateWithCatch)({ pageFunction: () => { document.body.style.background = 'black'; }, args: [], frame: null, page, timeoutInMilliseconds, }); } // @ts-expect-error if (imageFormat === 'none') { throw new TypeError('Tried to make a screenshot with format "none"'); } const buf = await (0, puppeteer_screenshot_1.screenshot)({ page, omitBackground: imageFormat === 'png', path: path !== null && path !== void 0 ? path : undefined, type: imageFormat, jpegQuality, width, height, scale, }); if (typeof buf === 'string') { throw new TypeError('Expected a buffer'); } return buf; }; exports.screenshotDOMElement = screenshotDOMElement;