html-pdf-chrome
Version:
HTML to PDF and image converter via Chrome/Chromium
43 lines • 1.4 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Element = void 0;
const CompletionTrigger_1 = require("./CompletionTrigger");
/**
* Waits for a DOM element to appear.
*
* @export
* @class Element
* @extends {CompletionTrigger}
*/
class Element extends CompletionTrigger_1.CompletionTrigger {
/**
* Creates an instance of the Element CompletionTrigger.
* @param {string} cssSelector the element to listen for.
* @param {number} [timeout] ms to wait until timing out.
* @memberof Element
*/
constructor(cssSelector, timeout) {
super(timeout);
this.cssSelector = cssSelector;
}
async wait(client) {
const { Runtime } = client;
return Runtime.evaluate({
awaitPromise: true,
expression: `
new Promise((resolve, reject) => {
new MutationObserver((mutations, observer) => {
mutations.forEach((mutation) => {
if ([...mutation.addedNodes].find((node) => node.matches('${this.cssSelector}'))) {
observer.disconnect();
resolve();
}
});
}).observe(document.body, { childList: true });
setTimeout(() => reject('${this.timeoutMessage}'), ${this.timeout});
})`,
});
}
}
exports.Element = Element;
//# sourceMappingURL=Element.js.map
;