UNPKG

html-pdf-chrome

Version:

HTML to PDF and image converter via Chrome/Chromium

45 lines 1.41 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.Variable = void 0; const CompletionTrigger_1 = require("./CompletionTrigger"); /** * Waits for a variable to be true. * * @export * @class Variable * @extends {CompletionTrigger} */ class Variable extends CompletionTrigger_1.CompletionTrigger { /** * Creates an instance of the Variable CompletionTrigger. * @param {string} [variableName] the variable to listen on. * Defaults to htmlPdfDone. * @param {number} [timeout] ms to wait until timing out. * @memberof Variable */ constructor(variableName, timeout) { super(timeout); this.variableName = variableName; } async wait(client) { const { Runtime } = client; const varName = this.variableName || 'htmlPdfDone'; return Runtime.evaluate({ awaitPromise: true, expression: ` new Promise((resolve, reject) => { // check if already set if (window['${varName}'] === true) { resolve(); return; } Object.defineProperty(window, '${varName}', { set: (val) => { if (val === true) resolve(); } }); setTimeout(() => reject('${this.timeoutMessage}'), ${this.timeout}); })`, }); } } exports.Variable = Variable; //# sourceMappingURL=Variable.js.map