Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions capture/engine_scripts/puppet/clickAndHoverHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,34 @@ module.exports = async (page, scenario) => {
}
}

// Force-load lazy images.
await page.evaluate(async(scenario) => {
let images = [];
const lazyImages = document.querySelectorAll('[loading="lazy"]');
lazyImages.forEach((image) => {
images.push(image);
});

async function loadImages(images) {
await images.reduce(async(promise, image) => {
// This line will wait for the last async function to finish.
// The first iteration uses an already resolved Promise
// so, it will immediately continue.
// https://stackoverflow.com/a/49499491/231914
await promise;
image.removeAttribute('loading');
const result = await image.decode();
}, Promise.resolve());
}

if (images.length) {
console.log('Loading ' + images.length + ' lazy elements.');
}
return loadImages(images);

}, scenario);


if (postInteractionWait) {
await new Promise(resolve => {
setTimeout(resolve, postInteractionWait);
Expand Down