diff --git a/src/renderers/chrome/index.js b/src/renderers/chrome/index.js index 3939565..6ad47f2 100644 --- a/src/renderers/chrome/index.js +++ b/src/renderers/chrome/index.js @@ -114,7 +114,7 @@ export class ChromeRenderer extends Renderer { } async renderPage(page, options = {}) { - let { path: filepath, type } = options; + let { path: filepath, type, waitForNavigation } = options; let buffer; if (!isString(type)) { @@ -122,6 +122,19 @@ export class ChromeRenderer extends Renderer { type = type.length > 0 ? type : 'html'; } + if (waitForNavigation !== false) { + if (waitForNavigation === Object(waitForNavigation)) { + await page._chromePage.waitForNavigation(waitForNavigation); + } else { + await page._chromePage.waitForNavigation({ + waitUntil: 'networkidle', + networkIdleInflight: 0, + timeout: 0 + }); + } + delete options.waitForNavigation; + } + switch (type) { case 'html': buffer = await page._chromePage.content(); @@ -134,12 +147,6 @@ export class ChromeRenderer extends Renderer { delete options.emulateMedia; } - await page._chromePage.waitForNavigation({ - waitUntil: 'networkidle', - networkIdleInflight: 0, - timeout: 0 - }); - buffer = await page._chromePage.pdf(options); break; default: