UNPKG

node-image-from-html

Version:

This single-dependency library provides a simple API to render HTML content using <a href="https://github.com/puppeteer/puppeteer">Puppeteer</a> (A headless chromium brower) into png and jpeg images, insuring security and efficiency in the process. Writte

44 lines (43 loc) 1.75 kB
/// <reference types="node" /> import { PuppeteerLaunchOptions } from "puppeteer"; import { BrowserHandlerOptions, ExtendedScreenshotOptions } from "../types.js"; /** * @class BrowserHandler * This class is used to handle the browser and pages, allocating pages for use and releasing them back to the handler when idle. * To start rendering, <BrowserHandler>.start() must first be called. */ export declare class BrowserHandler { private options; private _browser; private pages; /** * Constructor for the BrowserHandler class. * @param options The options for the BrowserHandler. */ constructor(options?: BrowserHandlerOptions); /** * Returns the underlying Puppeteer browser instance, throwing an exception if it's not started. */ private get browser(); /** * Starts the BrowserHandler engine & launches a new browser. * @param puppeteerOptions The options for the launched instance of Puppeteer. */ start(puppeteerOptions?: PuppeteerLaunchOptions): Promise<void>; /** * Returns a page, waiting for one to be free if necessary. * @returns A promise that resolves to an ExtendedPage object. */ private waitForPage; /** * Closes the browser and cleans up any resources. */ dispose(): Promise<void>; /** * Renders an HTML string to an image format using the first available page, waiting for one to be free if necessary. * @param html HTML to render * @param screenshotOptions The options for the screenshot. * @returns Your rendered HTML as a Buffer. */ render(html: string, screenshotOptions: ExtendedScreenshotOptions): Promise<string | Buffer>; }