Puppeteer on CentOS 7 - knowingharsh/automated-chromium-cluster GitHub Wiki

Its not always straight forward to install and run puppeteer on linux. I was stuck for almost 2 days because code was working perfectly on Windows and MacOS but not in CentOS 7. I hope this page has what you are looking for. I found the solution here .

Installation

I hope you have installed node in CentOS already.

Step 1. Install puppeteer using --unsafe-perm=true

sudo npm install -g puppeteer --unsafe-perm=true

Step 2. Install missing Chromium dependencies

sudo yum install pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64 libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXtst.x86_64 cups-libs.x86_64 libXScrnSaver.x86_64 libXrandr.x86_64 GConf2.x86_64 alsa-lib.x86_64 atk.x86_64 gtk3.x86_64 ipa-gothic-fonts xorg-x11-fonts-100dpi xorg-x11-fonts-75dpi xorg-x11-utils xorg-x11-fonts-cyrillic xorg-x11-fonts-Type1 xorg-x11-fonts-misc

Step 3. Create test.js

'use strict';
const puppeteer = require('puppeteer');
const fs = require('fs');
(async () => {
  console.info("Starting browser");
  let browser;
  try {
    browser = await puppeteer.launch({});
  } catch (e) {
    console.info("Unable to launch browser mode in sandbox mode. Lauching Chrome without sandbox.");
    browser = await puppeteer.launch({args:['--no-sandbox']});
  }
  console.info("Browser successfully started");
  console.info("Closing browser");
  await browser.close();
  console.info("Done");
})();

Step 4: Execute test.

$ node test.js

Starting browser
Unable to launch browser mode in sandbox mode. Lauching Chrome without sandbox.
Browser successfully started
Closing browser
Done

The browser cannot be launched without --no-sandbox

Special Instructions

For SUID sandboxing to work, "standard" chromium uses a process called "chrome-sandbox".

If you navigate to node_modules/puppeteer/.local-chromium/linux-549031, (549031 can be anything) go inside, follow your intuitions you notice that for puppeteer there is a file named chrome_sandbox (with an underscore).

Renaming this file to chrome-sandbox, making it owned by root and with attributes 4755 does the trick.

sudo mv chrome_sandbox chrome-sandbox
sudo chown root chrome-sandbox
sudo chmod 4755 chrome-sandbox

Now, run the test again

$ node test.js

Starting browser
Browser successfully started
Closing browser
Done

Happy Automations!!!