Here is my code. I am using AdBlock Plus Extension.
I have a task to take a screenshot for the web page(Have used lazy loading) with images in the right sidebar under the heading PAID CONTENT and images on the bottom under the heading PAID CONTENT.
const puppeteer = require('puppeteer');
const fs = require('fs');
(async () => {
const pathToExtension = require('path').join(__dirname, 'abp_chrome');
const browser = await puppeteer.launch({
headless: true,
args: [
`--disable-extensions-except=${pathToExtension}`,
`--load-extension=${pathToExtension}`
]
});
const page = await browser.newPage();
await timeout(5000);
await page.setViewport({width: 1200, height: 1200});
await page.goto('https://edition.cnn.com/2015/07/31/world/mh370-debris-
investigation/index.html', {waitUntil: 'load', timeout: 0});
await page.evaluate(() => {
window.getDimensions = function(element) {
rect = element.getBoundingClientRect();
return {
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height
};
};
});
await autoScroll(page);
await page.screenshot({path: 'example.png', fullPage: true});
await browser.close();
})();
async function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function autoScroll(page){
await page.evaluate(async () => {
await new Promise((resolve, reject) => {
var totalHeight = 0;
var distance = 100;
var timer = setInterval(() => {
var scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
totalHeight += distance;
if(totalHeight >= scrollHeight){
clearInterval(timer);
resolve();
}
}, 500);
});
});
}
I have used scrolling to load lazy images, but images are not loading as I have seen in screenshot.
Here is captured screenshot from code.
As in screenshot, there is no images tiles, Is there any way I can accomplish this?