Skip to content

Commit

Permalink
Changed image waiting method as per
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtrusty authored Aug 11, 2020
1 parent 0e43315 commit 2fc50fa
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ const parseCookie = (url, cookie) => {
return returnValue;
};

const imagesHaveLoaded = () => [...document.images].map(element => element.complete);

const captureWebsite = async (input, options) => {
options = {
inputType: 'url',
Expand Down Expand Up @@ -340,15 +338,20 @@ const captureWebsite = async (input, options) => {
viewportIncrement += viewportHeight;
}

// Scroll back to top
// Wait for images to be complete and scroll back to top
await page.evaluate(_ => {
const selectors = Array.from(document.images);
await Promise.all(selectors.map(img => {
if (img.complete) return;
return new Promise((resolve, reject) => {
img.addEventListener('load', resolve);
img.addEventListener('error', reject);

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Aug 11, 2020

I think we want to just ignore if an image load fails. So this should be resolve too. Which means you could just use util.promisify on both these.

});
}));
/* eslint-disable no-undef */
window.scrollTo(0, 0);
/* eslint-enable no-undef */
});

// Some extra delay to let images load
await page.waitForFunction(imagesHaveLoaded, {timeout: 60});
}

const buffer = await page.screenshot(screenshotOptions);
Expand Down

0 comments on commit 2fc50fa

Please sign in to comment.