From 7aee56db998d01bb11575c9c15f74f3248f507ef Mon Sep 17 00:00:00 2001 From: Kimmo Brunfeldt Date: Fri, 13 Oct 2017 13:01:33 +0300 Subject: [PATCH] Fix issue where resource loading was not finished before rendering direct html. More here https://github.com/GoogleChrome/puppeteer/issues/728 --- README.md | 2 +- src/core/pdf-core.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 375ae6c0..a86143a7 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ is really simple, check it out. Render flow: 3. Render url **or** html. If `url` is defined, **`page.goto(url, options)`** is called and options match `goto.*`. - Otherwise **`page.setContent(html)`** is called where html is taken from request body. + Otherwise **`page.goto(\`data:text/html,${html}\`, options)`** is called where html is taken from request body. This workaround was found from [Puppeteer issue](https://github.com/GoogleChrome/puppeteer/issues/728). 4. *Possibly* **`page.waitFor(numOrStr)`** if e.g. `waitFor=1000` is set. 5. *Possibly* **Scroll the whole page** to the end before rendering if e.g. `scrollPage=true` is set. diff --git a/src/core/pdf-core.js b/src/core/pdf-core.js index 1f1bfb61..9784cfd9 100644 --- a/src/core/pdf-core.js +++ b/src/core/pdf-core.js @@ -62,7 +62,8 @@ async function render(_opts = {}) { if (opts.html) { logger.info('Set HTML ..'); - await page.setContent(opts.html); + // https://github.com/GoogleChrome/puppeteer/issues/728 + await page.goto(`data:text/html,${opts.html}`, opts.goto); } else { logger.info(`Goto url ${opts.url} ..`); await page.goto(opts.url, opts.goto);