From 863f2e065d83f7221ad68d82dc8f8657776353fe Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 21 Jun 2019 17:22:23 -0400 Subject: [PATCH 1/4] Await network idle before generating PDF --- src/renderers/chrome/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/renderers/chrome/index.js b/src/renderers/chrome/index.js index 9ee03f3..3939565 100644 --- a/src/renderers/chrome/index.js +++ b/src/renderers/chrome/index.js @@ -134,6 +134,12 @@ 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: From 5203313d2d50623b37069e89c621ff4cca6d5a5d Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 1 Aug 2019 18:38:24 -0400 Subject: [PATCH 2/4] Accept waitForNavigation options --- src/renderers/chrome/index.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/renderers/chrome/index.js b/src/renderers/chrome/index.js index 3939565..7b55de1 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,21 @@ export class ChromeRenderer extends Renderer { type = type.length > 0 ? type : 'html'; } + if (waitForNavigation !== null && waitForNavigation !== undefined) { + if (waitForNavigation === false) { + return; + } else 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 +149,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: From 0e1744fe289ce81be0c2840ac317427d8fe41046 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 21 Aug 2019 16:02:19 -0400 Subject: [PATCH 3/4] Make waitForNavigation default option --- src/renderers/chrome/index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/renderers/chrome/index.js b/src/renderers/chrome/index.js index 7b55de1..e764d56 100644 --- a/src/renderers/chrome/index.js +++ b/src/renderers/chrome/index.js @@ -122,10 +122,8 @@ export class ChromeRenderer extends Renderer { type = type.length > 0 ? type : 'html'; } - if (waitForNavigation !== null && waitForNavigation !== undefined) { - if (waitForNavigation === false) { - return; - } else if (waitForNavigation === Object(waitForNavigation)) { + if (waitForNavigation !== false) { + if (waitForNavigation === Object(waitForNavigation)) { await page._chromePage.waitForNavigation(waitForNavigation); } else { await page._chromePage.waitForNavigation({ @@ -134,8 +132,8 @@ export class ChromeRenderer extends Renderer { timeout: 0 }); } - delete options.waitForNavigation; } + delete options.waitForNavigation; switch (type) { case 'html': From 919a9a25aca493dc9586e6c8bd97c0c0b64568bf Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 22 Aug 2019 14:28:57 -0400 Subject: [PATCH 4/4] Reverse making waitForNavigation default behaviour --- src/renderers/chrome/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/renderers/chrome/index.js b/src/renderers/chrome/index.js index e764d56..7b55de1 100644 --- a/src/renderers/chrome/index.js +++ b/src/renderers/chrome/index.js @@ -122,8 +122,10 @@ export class ChromeRenderer extends Renderer { type = type.length > 0 ? type : 'html'; } - if (waitForNavigation !== false) { - if (waitForNavigation === Object(waitForNavigation)) { + if (waitForNavigation !== null && waitForNavigation !== undefined) { + if (waitForNavigation === false) { + return; + } else if (waitForNavigation === Object(waitForNavigation)) { await page._chromePage.waitForNavigation(waitForNavigation); } else { await page._chromePage.waitForNavigation({ @@ -132,8 +134,8 @@ export class ChromeRenderer extends Renderer { timeout: 0 }); } + delete options.waitForNavigation; } - delete options.waitForNavigation; switch (type) { case 'html':