What's the way to get puppeteer to wait for the page to fully load?

kellanfaraday

Member
Jul 2, 2021
61
1
8
Atlanta, Georgia
I'm currently working on something that involves taking screenshots with Puppeteer. However, I've encountered an issue where the screenshots are being taken before the page is fully loaded, resulting in incomplete captures (and lots of frustration). I need a reliable method to ensure Puppeteer waits for the page to completely load before taking the screenshot. Any ideas?
 


Making puppeteer wait for page to load is a trickier task than it seems, it depends on page complexity and a bunch of other factors. You can wait for events like 'load' or 'domcontentloaded' to fire or wait for specific DOM elements to be visible/hidden. There are a couple of variations you can test out, check here in detail. I don't know what you've tried so far, so I don't want to suggest something that you know won't work for you. If this is not a one-time thing, and none of the methods work, consider getting a screenshot tool.