Chrome Headless puppeteer too much CPU Chrome Headless puppeteer too much CPU google-chrome google-chrome

Chrome Headless puppeteer too much CPU


my default args, please test it and tell me if this run smoothly.

  const options = {    args: [      '--no-sandbox',      '--disable-setuid-sandbox',      '--disable-dev-shm-usage',      '--disable-accelerated-2d-canvas',      '--no-first-run',      '--no-zygote',      '--single-process', // <- this one doesn't works in Windows      '--disable-gpu'    ],    headless: true  }  return await puppeteer.launch(options)


There's a few factors that can play into this. First, check if the site(s) that you're visiting using a lot of CPU. Things like canvas and other scripts can easily chew through your CPU, especially when it comes to using canvas.

If you're using docker to do your deployment then make sure you use dumb-init. There's a nice repo here that goes into why you'd use such a thing, but essentially the process ID that gets assigned in your docker image has some hiccups when it comes to handling termination:

EXPOSE 8080ENTRYPOINT ["dumb-init", "--"]CMD ["yarn", "start"]

This is something I've witnessed and fixed on browserless.io as I use docker to handle deployments, CPU usage being one of them.


To avoid parallel execution which causes high CPU usage , i had to execute jobs sequentially using

p-iteration NPM package. In my case it's not a problem because my jobs don't take too much time.

You can use either forEachSeries or mapSeries function depending on you scenario.