Puppeteer-Puppeteer served by pm2 doesn’t work

September 22, 2021 . 2 MIN READ

https://github.com/Unitech/pm2/issues/3933

Puppeteer served by pm2 doesn’t work. #3933

itsTeknas commented 

What’s going wrong?

Puppeteer crashes when running on app served by pm2.

API >     { TimeoutError: Navigation Timeout Exceeded: 30000ms exceeded
API >     at Promise.then (/home/ubuntu/node_modules/puppeteer/lib/NavigatorWatcher.js:94:21)
API >     at <anonymous> name: 'TimeoutError' }

Puppeteer is a wrapper around google headless chrome, when you try to spin up a puppeteer instance inside of an app running pm2, not only does puppeteer fail but also the cpu usage spikes and the entire server becomes unresponsive.

I tried running the same code on nodemon and forever and that works fine with only ~40mb of ram usage and the request completes within 5 seconds.

How could we reproduce this issue?

Run any puppeteer instance inside of an app served by pm2


.then(url => {
    return puppeteer.launch({
      defaultViewport: {
        width: 1920,
        height: 1080,
        isMobile: false
      },
      printBackground: true
    }).then(browser => {
      return browser.newPage().then(page => {
        return page.goto(url).then(resp => {
          return page.screenshot({
            type: "jpeg"
          })
        }).then(buffer => {
          browser.close();
          return buffer;
        })
      })
    })

Supporting information

===============================================================================
--- PM2 REPORT (Sun Sep 30 2018 05:41:19 GMT+0000 (UTC)) ----------------------
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 2.10.4
node version         : 8.11.3
node path            : /home/ubuntu/.nvm/versions/node/v8.11.3/bin/pm2
argv                 : /home/ubuntu/.nvm/versions/node/v8.11.3/bin/node,/home/ubuntu/.nvm/versions/node/v8.11.3/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : ubuntu
uid                  : 1000
gid                  : 1000
uptime               : 945min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 2.10.4
node version         : 8.11.3
node path            : /home/ubuntu/.nvm/versions/node/v8.11.3/bin/pm2
argv                 : /home/ubuntu/.nvm/versions/node/v8.11.3/bin/node,/home/ubuntu/.nvm/versions/node/v8.11.3/bin/pm2,report
argv0                : node
user                 : ubuntu
uid                  : 1000
gid                  : 1000
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
cpus nb              : 1
freemem              : 8552448
totalmem             : 503242752
home                 : /home/ubuntu
===============================================================================
--- PM2 list -----------------------------------------------
┌──────────┬────┬─────────┬───────┬────────┬─────────┬────────┬─────┬────────────┬────────┬──────────┐
│ App name │ id │ mode    │ pid   │ status │ restart │ uptime │ cpu │ mem        │ user   │ watching │
├──────────┼────┼─────────┼───────┼────────┼─────────┼────────┼─────┼────────────┼────────┼──────────┤
│ API      │ 0  │ cluster │ 20796 │ online │ 1       │ 15h    │ 0%  │ 112.5 MB   │ ubuntu │ disabled │
│ QUEUE    │ 1  │ fork    │ 20797 │ online │ 1       │ 15h    │ 0%  │ 51.4 MB    │ ubuntu │ disabled │
└──────────┴────┴─────────┴───────┴────────┴─────────┴────────┴─────┴────────────┴────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
┌──────────┬────┬─────────┬───────┬────────┬─────────┬────────┬─────┬────────────┬────────┬──────────┐
│ App name │ id │ mode    │ pid   │ status │ restart │ uptime │ cpu │ mem        │ user   │ watching │
├──────────┼────┼─────────┼───────┼────────┼─────────┼────────┼─────┼────────────┼────────┼──────────┤
│ API      │ 0  │ cluster │ 20796 │ online │ 1       │ 15h    │ 0%  │ 112.5 MB   │ ubuntu │ disabled │
│ QUEUE    │ 1  │ fork    │ 20797 │ online │ 1       │ 15h    │ 0%  │ 51.4 MB    │ ubuntu │ disabled │
└──────────┴────┴─────────┴───────┴────────┴─────────┴────────┴─────┴────────────┴────────┴──────────┘

Leave a Reply

Your email address will not be published. Required fields are marked *