Puppeteer wait for all images to load then take screenshot

There is a built-in option for that: await page.goto(‘https://www.digg.com/’, {“waitUntil” : “networkidle0”}); networkidle0 – consider navigation to be finished when there are no more than 0 network connections for at least 500 ms networkidle2 – consider navigation to be finished when there are no more than 2 network connections for at least 500 ms. Of … Read more

puppeteer wait for page/DOM updates – respond to new items that are added after initial loading

You can use exposeFunction to expose a local function: await page.exposeFunction(‘getItem’, function(a) { console.log(a); }); Then you can use page.evaluate to create an observer and listen to new nodes created inside a parent node. This example scrapes (it’s just an idea, not a final work) the python chat in Stack Overflow, and prints new items … Read more

Can I use puppeteer inside chrome extension

I know this is 9 months late but I had the same use case at work on Window machines but you can make it work with Mac. The trick is to use puppeteer-web https://github.com/puppeteer/puppeteer/tree/master/utils/browser#bundling-for-web-browsers Bundle the repository and place it in your chrome extension folder and then reference it in your popup.html with something like … Read more

Puppeteer: How to listen to a specific response?

One option is to do the following: page.on(‘response’, response => { if (response.url().endsWith(“your/match”)) console.log(“response code: “, response.status()); // do something here }); This still catches all requests, but allows you to filter and act on the event emitter. https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#event-response

Can the browser turned headless mid-execution when it was started normally, or vice-versa?

Short answer: It’s not possible Chrome only allows to either start the browser in headless or non-headless mode. You have to specify it when you launch the browser and it is not possible to switch during runtime. What is possible, is to launch a second browser and reuse cookies (and any other data) from the … Read more

Puppeteer – Protocol error (Page.navigate): Target closed

What “Target closed” means When you launch a browser via puppeteer.launch it will start a browser and connect to it. From there on any function you execute on your opened browser (like page.goto) will be send via the Chrome DevTools Protocol to the browser. A target means a tab in this context. The Target closed … Read more