I am using Puppeteer to try to take a screenshot of a website after all images have loaded but can\'t get it to work.
Here is the code I\'ve got so far, I am using h
I found a solution which is applicable to multiple sites using the page.setViewPort(...) method as given below:
const puppeteer = require('puppeteer');
async(() => {
const browser = await puppeteer.launch({
headless: true, // Set to false while development
defaultViewport: null,
args: [
'--no-sandbox',
'--start-maximized', // Start in maximized state
],
});
const page = await = browser.newPage();
await page.goto('https://www.digg.com/', {
waitUntil: 'networkidle0', timeout: 0
});
// Get scroll width and height of the rendered page and set viewport
const bodyWidth = await page.evaluate(() => document.body.scrollWidth);
const bodyHeight = await page.evaluate(() => document.body.scrollHeight);
await page.setViewport({ width: bodyWidth, height: bodyHeight });
await page.waitFor(1000);
await page.screenshot({path: 'digg-example.png' });
})();