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E3C,QAAQ,IAAI,EACtB,CAQA,eAAe,cAAc,EAAS,GAClC,GAAI,EAAQ,kBAAmB,OACrB,qBAAqB,GAC3B,MAAM,QAAmB,EAAQ,kBAAkB,KAAK,GACxD,GAAI,GAAc,EAAW,iBAEzB,YADM,qBAAqB,GACrB,IAAI,MAAM,EAAW,OAAO,MAE1C,OACM,qBAAqB,EAC/B,CAQA,eAAe,qBAAqB,GAChC,GAAI,EAAQ,eACR,MAAM,EAAQ,cAEtB,CACA,SAAS,uBAAuB,GAC5B,MAAM,EAAY,OAAO,OAAO,CAAC,EAAG,GAKpC,cAHO,EAAU,sBACV,EAAU,sBACV,EAAU,qBACV,CACX,CAOA,eAAe,aAAa,GACxB,MAAM,QAAe,EAAI,kBAAkB,QAAQ,CAC/C,KAAM,EAAQ,KACd,WAAY,EAAQ,WACpB,YAAa,EAAQ,aAAe,uBAGxC,OADA,EAAQ,KAAO,EAAO,KACf,CACX,CA5KA,QAAQ,OAAS","file":"/npm/html-pdf-chrome@0.8.4/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/html-pdf-chrome@0.8.4/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.create = exports.CreateResult = exports.CompletionTrigger = void 0;\nconst chrome_launcher_1 = require(\"chrome-launcher\");\nconst CDP = require(\"chrome-remote-interface\");\nconst CompletionTrigger = require(\"./CompletionTriggers\");\nexports.CompletionTrigger = CompletionTrigger;\nconst ConnectionLostError_1 = require(\"./ConnectionLostError\");\nconst CreateResult_1 = require(\"./CreateResult\");\nObject.defineProperty(exports, \"CreateResult\", { enumerable: true, get: function () { return CreateResult_1.CreateResult; } });\nconst DEFAULT_CHROME_FLAGS = [\n    '--disable-gpu',\n    '--headless',\n    '--hide-scrollbars',\n];\n/**\n * Generates a PDF or screenshot from the given HTML string, launching Chrome as necessary.\n *\n * @export\n * @param {string} html the HTML string.\n * @param {Options} [options] the generation options.\n * @returns {Promise<CreateResult>} the generated PDF or screenshot data.\n */\nasync function create(html, options) {\n    const myOptions = normalizeCreateOptions(options);\n    let chrome;\n    if (!myOptions.host && !myOptions.port) {\n        chrome = await launchChrome(myOptions);\n    }\n    try {\n        const tab = await CDP.New(myOptions);\n        try {\n            return await generate(html, myOptions, tab);\n        }\n        finally {\n            if (!(myOptions._exitCondition instanceof ConnectionLostError_1.ConnectionLostError)) {\n                await CDP.Close({ ...myOptions, id: tab.id });\n            }\n        }\n    }\n    finally {\n        if (chrome) {\n            await chrome.kill();\n        }\n    }\n}\nexports.create = create;\n/**\n * Connects to Chrome and generates a PDF of screenshot from HTML or a URL.\n *\n * @param {string} html the HTML string or URL.\n * @param {CreateOptions} options the generation options.\n * @param {CDP.Target} tab the tab to use.\n * @returns {Promise<CreateResult>} the generated PDF or screenshot data.\n */\nasync function generate(html, options, tab) {\n    await throwIfExitCondition(options);\n    const client = await CDP({ ...options, target: tab });\n    const connectionLostOrTimeout = new Promise((_, reject) => {\n        client.on('disconnect', () => {\n            const error = new ConnectionLostError_1.ConnectionLostError();\n            options._exitCondition = error;\n            reject(error);\n        });\n        if (options.timeout != null && options.timeout >= 0) {\n            setTimeout(() => {\n                const error = new Error('HtmlPdf.create() timed out.');\n                options._exitCondition = error;\n                reject(error);\n            }, options.timeout);\n        }\n    });\n    async function generateInternal() {\n        try {\n            await beforeNavigate(options, client);\n            const { Page } = client;\n            if (/^(https?|file|data):/i.test(html)) {\n                await Promise.all([\n                    Page.navigate({ url: html }),\n                    Page.loadEventFired(),\n                ]); // Resolve order varies\n            }\n            else {\n                const { frameTree } = await Page.getResourceTree();\n                await Promise.all([\n                    Page.setDocumentContent({ html, frameId: frameTree.frame.id }),\n                    Page.loadEventFired(),\n                ]); // Resolve order varies\n            }\n            await afterNavigate(options, client);\n            let base64Result;\n            if (options.screenshotOptions) {\n                // https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-captureScreenshot\n                const screenshot = await Page.captureScreenshot(options.screenshotOptions);\n                base64Result = screenshot.data;\n            }\n            else {\n                // https://chromedevtools.github.io/debugger-protocol-viewer/tot/Page/#method-printToPDF\n                const pdf = await Page.printToPDF(options.printOptions);\n                base64Result = pdf.data;\n            }\n            await throwIfExitCondition(options);\n            return new CreateResult_1.CreateResult(base64Result, options._mainRequestResponse);\n        }\n        finally {\n            client.close();\n        }\n    }\n    return Promise.race([\n        connectionLostOrTimeout,\n        generateInternal(),\n    ]);\n}\n/**\n * Code to execute before the page navigation.\n *\n * @param {CreateOptions} options the generation options.\n * @param {CDP.Client} client the Chrome client.\n * @returns {Promise<void>} resolves if there we no errors or cancellations.\n */\nasync function beforeNavigate(options, client) {\n    const { Emulation, Network, Page, Runtime } = client;\n    await throwIfExitCondition(options);\n    if (options.clearCache) {\n        await Network.clearBrowserCache();\n    }\n    // Enable events to be used here, in generate(), or in afterNavigate().\n    await Promise.all([\n        Network.enable(),\n        Page.enable(),\n        Runtime.enable(),\n    ]);\n    if (options.runtimeConsoleHandler) {\n        Runtime.consoleAPICalled(options.runtimeConsoleHandler);\n    }\n    if (options.runtimeExceptionHandler) {\n        Runtime.exceptionThrown(options.runtimeExceptionHandler);\n    }\n    Network.requestWillBeSent((e) => {\n        options._mainRequestId = options._mainRequestId || e.requestId;\n    });\n    Network.loadingFailed((e) => {\n        if (e.requestId === options._mainRequestId) {\n            options._exitCondition = new Error('HtmlPdf.create() page navigate failed.');\n        }\n    });\n    Network.responseReceived((e) => {\n        if (e.requestId === options._mainRequestId) {\n            options._mainRequestResponse = e.response;\n        }\n    });\n    if (options.extraHTTPHeaders) {\n        Network.setExtraHTTPHeaders({ headers: options.extraHTTPHeaders });\n    }\n    if (options.deviceMetrics) {\n        Emulation.setDeviceMetricsOverride(options.deviceMetrics);\n    }\n    const promises = [throwIfExitCondition(options)];\n    if (options.cookies) {\n        promises.push(Network.setCookies({ cookies: options.cookies }));\n    }\n    if (options.completionTrigger) {\n        promises.push(options.completionTrigger.init(client));\n    }\n    await Promise.all(promises);\n}\n/**\n * Code to execute after the page navigation.\n *\n * @param {CreateOptions} options the generation options.\n * @param {CDP.Client} client the Chrome client.\n * @returns {Promise<void>} resolves if there we no errors or cancellations.\n */\nasync function afterNavigate(options, client) {\n    if (options.completionTrigger) {\n        await throwIfExitCondition(options);\n        const waitResult = await options.completionTrigger.wait(client);\n        if (waitResult && waitResult.exceptionDetails) {\n            await throwIfExitCondition(options);\n            throw new Error(waitResult.result.value);\n        }\n    }\n    await throwIfExitCondition(options);\n}\n/**\n * Throws an exception if the operation has been canceled or the main page\n * navigation failed.\n *\n * @param {CreateOptions} options the options which track cancellation and failure.\n * @returns {Promise<void>} rejects if canceled or failed, resolves if not.\n */\nasync function throwIfExitCondition(options) {\n    if (options._exitCondition) {\n        throw options._exitCondition;\n    }\n}\nfunction normalizeCreateOptions(options) {\n    const myOptions = Object.assign({}, options); // clone\n    // make sure these aren't set externally\n    delete myOptions._exitCondition;\n    delete myOptions._mainRequestId;\n    delete myOptions._mainRequestResponse;\n    return myOptions;\n}\n/**\n * Launches Chrome with the specified options.\n *\n * @param {CreateOptions} options the options for Chrome.\n * @returns {Promise<LaunchedChrome>} The launched Chrome instance.\n */\nasync function launchChrome(options) {\n    const chrome = await (0, chrome_launcher_1.launch)({\n        port: options.port,\n        chromePath: options.chromePath,\n        chromeFlags: options.chromeFlags || DEFAULT_CHROME_FLAGS,\n    });\n    options.port = chrome.port;\n    return chrome;\n}\n"]}