From c3f62e9692e8a97db243ca0112a90c8ea1c67f80 Mon Sep 17 00:00:00 2001 From: Louis-Michel Couture Date: Thu, 9 Jul 2020 14:17:23 -0400 Subject: [PATCH 1/2] Update documentation and remove unsupported options networkIdleInflight and networkIdleTimeout options are gone from Puppeteer. https://github.com/puppeteer/puppeteer/commit/ce8a952044ef318baf3d9ff25157e41571293de5 --- README.md | 4 +--- src/http/render-http.js | 2 -- src/util/validation.js | 4 ---- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/README.md b/README.md index 543c86b8..9ce78635 100644 --- a/README.md +++ b/README.md @@ -184,9 +184,7 @@ cookies[0][httpOnly] | boolean | - | Cookie httpOnly cookies[0][secure] | boolean | - | Cookie secure cookies[0][sameSite] | string | - | `Strict` or `Lax` goto.timeout | number | `30000` | Maximum navigation time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout. -goto.waitUntil | string | `networkidle` | When to consider navigation succeeded. Options: `load`, `networkidle`. `load` = consider navigation to be finished when the load event is fired. `networkidle` = consider navigation to be finished when the network activity stays "idle" for at least `goto.networkIdleTimeout` ms. -goto.networkIdleInflight | number | `2` | Maximum amount of inflight requests which are considered "idle". Takes effect only with `goto.waitUntil`: 'networkidle' parameter. -goto.networkIdleTimeout | number | `2000` | A timeout to wait before completing navigation. Takes effect only with waitUntil: 'networkidle' parameter. +goto.waitUntil | string | `networkidle2` | When to consider navigation succeeded. Options: `load`, `domcontentloaded`, `networkidle0`, `networkidle2`. `load` - consider navigation to be finished when the load event is fired. `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. `networkidle2` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms. pdf.scale | number | `1` | Scale of the webpage rendering. pdf.printBackground | boolean | `false`| Print background graphics. pdf.displayHeaderFooter | boolean | `false` | Display header and footer. diff --git a/src/http/render-http.js b/src/http/render-http.js index de7aa8a4..b182293e 100644 --- a/src/http/render-http.js +++ b/src/http/render-http.js @@ -155,8 +155,6 @@ function getOptsFromQuery(query) { goto: { timeout: query['goto.timeout'], waitUntil: query['goto.waitUntil'], - networkIdleInflight: query['goto.networkIdleInflight'], - networkIdleTimeout: query['goto.networkIdleTimeout'], }, pdf: { scale: query['pdf.scale'], diff --git a/src/util/validation.js b/src/util/validation.js index c8e0cd33..afefc518 100644 --- a/src/util/validation.js +++ b/src/util/validation.js @@ -39,8 +39,6 @@ const sharedQuerySchema = Joi.object({ 'viewport.isLandscape': Joi.boolean(), 'goto.timeout': Joi.number().min(0).max(60000), 'goto.waitUntil': Joi.string().min(1).max(2000), - 'goto.networkIdleInflight': Joi.number().min(0).max(1000), - 'goto.networkIdleTimeout': Joi.number().min(0).max(1000), 'pdf.scale': Joi.number().min(0).max(1000), 'pdf.displayHeaderFooter': Joi.boolean(), 'pdf.landscape': Joi.boolean(), @@ -94,8 +92,6 @@ const renderBodyObject = Joi.object({ goto: Joi.object({ timeout: Joi.number().min(0).max(60000), waitUntil: Joi.string().min(1).max(2000), - networkIdleInflight: Joi.number().min(0).max(1000), - networkIdleTimeout: Joi.number().min(0).max(1000), }), pdf: Joi.object({ scale: Joi.number().min(0).max(1000), From e57b5ae365a253852ba4f6948562690d54a93d7c Mon Sep 17 00:00:00 2001 From: Louis-Michel Couture Date: Thu, 9 Jul 2020 14:21:42 -0400 Subject: [PATCH 2/2] Update the default for waitUntil to networkidle0 networkidle0 seems the most logical choice here, because it consider navigation to be finished when there are no more than 0 network connections for at least 500 ms. Using networkidle2 would allow 2 requests to be pending and still render the page. --- README.md | 2 +- src/core/render-core.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9ce78635..9d20663c 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ cookies[0][httpOnly] | boolean | - | Cookie httpOnly cookies[0][secure] | boolean | - | Cookie secure cookies[0][sameSite] | string | - | `Strict` or `Lax` goto.timeout | number | `30000` | Maximum navigation time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout. -goto.waitUntil | string | `networkidle2` | When to consider navigation succeeded. Options: `load`, `domcontentloaded`, `networkidle0`, `networkidle2`. `load` - consider navigation to be finished when the load event is fired. `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. `networkidle2` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms. +goto.waitUntil | string | `networkidle0` | When to consider navigation succeeded. Options: `load`, `domcontentloaded`, `networkidle0`, `networkidle2`. `load` - consider navigation to be finished when the load event is fired. `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. `networkidle2` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms. pdf.scale | number | `1` | Scale of the webpage rendering. pdf.printBackground | boolean | `false`| Print background graphics. pdf.displayHeaderFooter | boolean | `false` | Display header and footer. diff --git a/src/core/render-core.js b/src/core/render-core.js index bb74a38d..9fad5e03 100644 --- a/src/core/render-core.js +++ b/src/core/render-core.js @@ -36,7 +36,7 @@ async function render(_opts = {}) { height: 1200, }, goto: { - waitUntil: 'networkidle2', + waitUntil: 'networkidle0', }, output: 'pdf', pdf: { @@ -171,7 +171,7 @@ async function render(_opts = {}) { const selElement = await page.$(opts.screenshot.selector); if (!_.isNull(selElement)) { data = await selElement.screenshot(); - } + } } } } catch (err) { @@ -184,7 +184,7 @@ async function render(_opts = {}) { await browser.close(); } } - + return data; }