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,CAAC;YACzB,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,IAAI,aAAa,CAAC;YACnD,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;gBACtB,YAAY,EAAE,IAAI;gBAClB,UAAU,EAAE;;2CAEyB,OAAO;;;qCAGb,IAAI,CAAC,cAAc,OAAO,IAAI,CAAC,OAAO;WAChE;aACN,CAAC,CAAC;QACL,CAAC;KAAA;CACF;AA3BD,4BA2BC","file":"CompletionTrigger.js","sourcesContent":["'use strict';\n\n/**\n * Defines a trigger that signifies page render completion.\n *\n * @export\n * @abstract\n * @class CompletionTrigger\n */\nexport abstract class CompletionTrigger {\n\n /**\n * Creates an instance of CompletionTrigger.\n * @param {number} [timeout=1000] milliseconds until timing out.\n * @param {string} [timeoutMessage='CompletionTrigger timed out.'] The timeout message.\n * @memberof CompletionTrigger\n */\n constructor(\n protected timeout = 1000,\n protected timeoutMessage = 'CompletionTrigger timed out.',\n ) {}\n\n /**\n * Abstracts away the trigger logic.\n *\n * @abstract\n * @param {*} client the Chrome connection information.\n * @returns {Promise} resolves if triggered, rejects on error or timeout.\n * @memberof CompletionTrigger\n */\n public abstract async wait(client: any): Promise;\n}\n\n/**\n * Waits for a specified amount of time.\n *\n * @export\n * @class Timer\n * @extends {CompletionTrigger}\n */\nexport class Timer extends CompletionTrigger {\n\n /**\n * Creates an instance of the Timer CompletionTrigger.\n * @param {number} timeout ms to wait until timing out.\n * @memberof Timer\n */\n constructor(timeout: number) {\n super(timeout);\n }\n\n public async wait(client: any): Promise {\n return new Promise((resolve) => {\n setTimeout(resolve, this.timeout);\n });\n }\n}\n\n/**\n * Waits for an Event to fire.\n *\n * @export\n * @class Event\n * @extends {CompletionTrigger}\n */\nexport class Event extends CompletionTrigger {\n\n /**\n * Creates an instance of the Event CompletionTrigger.\n * @param {string} event the name of the event to listen for.\n * @param {string} [cssSelector] the CSS selector of the element to listen on.\n * Defaults to body.\n * @param {number} [timeout] ms to wait until timing out.\n * @memberof Event\n */\n constructor(protected event: string, protected cssSelector?: string, timeout?: number) {\n super(timeout);\n }\n\n public async wait(client: any): Promise {\n const {Runtime} = client;\n const selector = this.cssSelector ? `querySelector('${this.cssSelector}')` : 'body';\n return Runtime.evaluate({\n awaitPromise: true,\n expression: `\n new Promise((resolve, reject) => {\n document.${selector}.addEventListener('${this.event}', resolve, { once: true });\n setTimeout(() => reject('${this.timeoutMessage}'), ${this.timeout});\n })`,\n });\n }\n}\n\n/**\n * Waits for a callback to be called.\n *\n * @export\n * @class Callback\n * @extends {CompletionTrigger}\n */\nexport class Callback extends CompletionTrigger {\n\n /**\n * Creates an instance of the Callback CompletionTrigger.\n * @param {string} [callbackName] the name of the callback to listen for.\n * Defaults to htmlPdfCb.\n * @param {number} [timeout] ms to wait until timing out.\n * @memberof Callback\n */\n constructor(protected callbackName?: string, timeout?: number) {\n super(timeout);\n }\n\n public async wait(client: any): Promise {\n const {Runtime} = client;\n const cbName = this.callbackName || 'htmlPdfCb';\n return Runtime.evaluate({\n awaitPromise: true,\n expression: `\n new Promise((resolve, reject) => {\n ${cbName} = resolve;\n setTimeout(() => reject('${this.timeoutMessage}'), ${this.timeout});\n })`,\n });\n }\n}\n\n/**\n * Waits for a DOM element to appear.\n *\n * @export\n * @class Element\n * @extends {CompletionTrigger}\n */\nexport class Element extends CompletionTrigger {\n\n /**\n * Creates an instance of the Element CompletionTrigger.\n * @param {string} cssSelector the element to listen for.\n * @param {number} [timeout] ms to wait until timing out.\n * @memberof Element\n */\n constructor(protected cssSelector: string, timeout?: number) {\n super(timeout);\n }\n\n public async wait(client: any): Promise {\n const {Runtime} = client;\n return Runtime.evaluate({\n awaitPromise: true,\n expression: `\n new Promise((resolve, reject) => {\n new MutationObserver((mutations, observer) => {\n mutations.forEach((mutation) => {\n if ([...mutation.addedNodes].find((node) => node.matches('${this.cssSelector}'))) {\n observer.disconnect();\n resolve();\n }\n });\n }).observe(document.body, { childList: true });\n setTimeout(() => reject('${this.timeoutMessage}'), ${this.timeout});\n })`,\n });\n }\n}\n\n/**\n * Waits for a variable to be true.\n *\n * @export\n * @class Variable\n * @extends {CompletionTrigger}\n */\nexport class Variable extends CompletionTrigger {\n\n /**\n * Creates an instance of the Variable CompletionTrigger.\n * @param {string} [variableName] the variable to listen on.\n * Defaults to htmlPdfDone.\n * @param {number} [timeout] ms to wait until timing out.\n * @memberof Variable\n */\n constructor(protected variableName?: string, timeout?: number) {\n super(timeout);\n }\n\n public async wait(client: any): Promise {\n const {Runtime} = client;\n const varName = this.variableName || 'htmlPdfDone';\n return Runtime.evaluate({\n awaitPromise: true,\n expression: `\n new Promise((resolve, reject) => {\n Object.defineProperty(window, '${varName}', {\n set: (val) => { if (val === true) resolve(); }\n });\n setTimeout(() => reject('${this.timeoutMessage}'), ${this.timeout});\n })`,\n });\n }\n}\n"],"sourceRoot":"../.."}