UNPKG

chromiumly

Version:

A lightweight Typescript library that interacts with Gotenberg's different modules to convert a variety of document formats to PDF files.

78 lines 4.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UrlScreenshot = void 0; const url_1 = require("url"); const common_1 = require("../../common"); const screenshot_utils_1 = require("../utils/screenshot.utils"); const screenshot_1 = require("./screenshot"); const main_config_1 = require("../../main.config"); /** * Class representing a URL screenshot that extends the base screenshot class. * This class is used to screenshot a URL using Gotenberg service. * * @extends Screenshot */ class UrlScreenshot extends screenshot_1.Screenshot { /** * Creates an instance of UrlScreenshot. * Initializes the screenshot with the URL screenshot route. */ constructor() { super(main_config_1.ChromiumRoute.URL); } /** * Screenshots URL. * * @param {Object} options - Screenshot options. * @param {string} options.url - The URL of the content to be screenshoted * @param {ImageProperties} [options.properties] - Image properties for the screenshot. * @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot. * @param {EmulatedMediaFeature[]} [options.emulatedMediaFeatures] - Override CSS media features (e.g. prefers-color-scheme). * @param {string} [options.waitDelay] - Delay before the screenshot process starts. * @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot. * @param {string} [options.waitForSelector] - CSS selector to wait for before completing the screenshot. * @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot. * @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code. * @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot. * @param {number[]} [options.failOnResourceHttpStatusCodes] - Whether to fail on resource HTTP status code. * @param {string[]} [options.ignoreResourceHttpStatusDomains] - Domains to exclude from resource HTTP status code checks. * @param {boolean} [options.failOnResourceLoadingFailed] - Whether to fail on resource loading failed. * @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event. * @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed. * @param {Cookie[]} options.cookies - Cookies to be written. * @param {boolean} [options.generateDocumentOutline] - Whether to generate document outline. * @returns {Promise<Buffer>} A Promise resolving to the image buffer. */ async capture({ url, properties, emulatedMediaType, emulatedMediaFeatures, waitDelay, waitForExpression, waitForSelector, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, failOnResourceHttpStatusCodes, ignoreResourceHttpStatusDomains, failOnResourceLoadingFailed, skipNetworkIdleEvent, skipNetworkAlmostIdleEvent, optimizeForSpeed, cookies, downloadFrom, webhook, generateDocumentOutline, userPassword, ownerPassword, embeds }) { const _url = new url_1.URL(url); const data = new FormData(); data.append('url', _url.href); await screenshot_utils_1.ScreenshotUtils.customize(data, { properties, emulatedMediaType, emulatedMediaFeatures, waitDelay, waitForExpression, waitForSelector, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, failOnResourceHttpStatusCodes, ignoreResourceHttpStatusDomains, failOnResourceLoadingFailed, skipNetworkIdleEvent, skipNetworkAlmostIdleEvent, optimizeForSpeed, cookies, downloadFrom, webhook, generateDocumentOutline, userPassword, ownerPassword, embeds }); return common_1.GotenbergUtils.fetch(this.endpoint, data, main_config_1.Chromiumly.getGotenbergApiBasicAuthUsername(), main_config_1.Chromiumly.getGotenbergApiBasicAuthPassword(), main_config_1.Chromiumly.getCustomHttpHeaders(), main_config_1.Chromiumly.getGotenbergApiKey(), common_1.GotenbergUtils.buildWebhookHeaders(webhook)); } } exports.UrlScreenshot = UrlScreenshot; //# sourceMappingURL=url.screenshot.js.map