puppeteer: Headless Chromium with Puppeteer doesn't work on Amazon Linux AMI

Environment:

  • Amazon Linux AMI version 2017.03
  • $ cat /etc/system-release Amazon Linux AMI release 2017.03
  • $ uname -a Linux ip-10-64-65-42 4.9.43-17.38.amzn1.x86_64 #1 SMP Thu Aug 17 00:20:39 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Issue: Applying the default configuration for Headless Chromium with Puppeteer from the README manual doesn’t work.

Thrown error: 13 09 2017 09:07:50.677:ERROR [launcher]: Cannot start ChromiumHeadless /home/ec2-user/portals-frontend/frontend/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: error while loading shared libraries: libXss.so.1: cannot open shared object file: No such file or directory

Karma config:

// ChromiumHeadless BROWSER
// https://github.com/karma-runner/karma-chrome-launcher#headless-chromium-with-puppeteer
const ChromiumRevision = require('puppeteer/package.json').puppeteer.chromium_revision;
const Downloader = require('puppeteer/utils/ChromiumDownloader');

const revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), ChromiumRevision);

process.env.CHROMIUM_BIN = revisionInfo.executablePath;

// ...

karmaConfig = {
        // Configuration for the ChromiumHeadless BROWSER
        // https://github.com/GoogleChrome/puppeteer/issues/290#issuecomment-324448524
        // https://github.com/karma-runner/karma-chrome-launcher/issues/73#issuecomment-247323225
        customLaunchers: {
            ChromiumHeadlessConfigured: {
                base: 'ChromiumHeadless',
                flags: ['--no-sandbox', '--disable-setuid-sandbox']
            }
        },

        browsers: ['ChromiumHeadlessConfigured'],
        /// ....
}

Tried options:

  • running $ sudo yum install libXss.so.1 gives:
No package libXss.so.1 available.
Error: Nothing to do

Reviewed and possibly related issues:

Other tried solution, which didn’t work:

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 19
  • Comments: 57 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Just got chrome headless with puppeteer run successfully on Amazon Linux AMI 2017.09, and here’s the how-to: https://mockingbot.com/blog/run-puppeteer-chrome-headless-on-ec2-amazon-linux

We’ve updated the https://intoli.com/blog/installing-google-chrome-on-centos/ article to include to include a universal installer script for tracking down all of the missing Google Chrome dependencies from the CentOS 7 repos and installing them in /opt/google/chrome/lib. The linker will resolve them there when running the Google Chrome executable, but they won’t create potential conflicts with system packages (which can happen when installing the other RPMs directly). The tl;dr is that you can run

# This installs Chrome on any RHEL/CentOS/Amazon Linux variant.
curl https://intoli.com/install-google-chrome.sh | bash

and it will install the latest version of Google Chrome on both 6.X and 7.X variants of Amazon Linux, CentOS, and RHEL. You’ll want to take a look through the script before running it like that. What it’s doing is explained in detail here.

@sangaline: It works! You are fantastic! Thank you

Summary for others

  • Platform: AWS Amplify continuous deployment
  • OS: Amazon Linux Docker image
  • Purpose: Use puppeteer on CI/CD to prerender a React app with react-snap

Step 1: Add the following steps to your amplify.yml config file to install Chrome

frontend:
  phases:
    preBuild:
      commands:
        - '# This installs Chrome on any RHEL/CentOS/Amazon Linux variant.'
        - curl https://intoli.com/install-google-chrome.sh | bash

Step 2: Add the following configuration to your package.json

'reactSnap': {
    'puppeteerArgs': ['--no-sandbox', '--disable-setuid-sandbox'],
    'puppeteerExecutablePath': '/opt/google/chrome/google-chrome'
  }

@mithung, if you run the script from https://intoli.com/blog/installing-google-chrome-on-centos/ , it will install all of the necessary dependencies in /opt/google/chrome/lib/. You can then set the LD_LIBRARY_PATH environment variable before running your script so that the linker knows where to look.

# Run this once to install Google Chrome.
curl https://intoli.com/install-google-chrome.sh | bash

# Invoke your script with `LD_LIBRARY_PATH` set.
LD_LIBRARY_PATH=/opt/google/chrome/lib/:${LD_LIBRARY_PATH} node your-script.js

Are you able to install the google-chrome-unstable package? That should install all shared libs for you.

yum install google-chrome-unstable

The solutions provided there don’t work anymore (ATK steps)

https://mockingbot.com/posts/run-puppeteer-chrome-headless-on-ec2-amazon-linux

here is update

sudo rpm -ivh --nodeps http://mirror.centos.org/centos/7/os/x86_64/Packages/atk-2.28.1-1.el7.x86_64.rpm
sudo rpm -ivh --nodeps http://mirror.centos.org/centos/7/os/x86_64/Packages/at-spi2-atk-2.26.2-1.el7.x86_64.rpm
sudo rpm -ivh --nodeps http://mirror.centos.org/centos/7/os/x86_64/Packages/at-spi2-core-2.28.0-1.el7.x86_64.rpm
sudo rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/g/GConf2-3.2.6-7.fc20.x86_64.rpm
sudo rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/l/libXScrnSaver-1.2.2-6.fc20.x86_64.rpm
sudo rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/l/libxkbcommon-0.3.1-1.fc20.x86_64.rpm
sudo rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/l/libwayland-client-1.2.0-3.fc20.x86_64.rpm
sudo rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/l/libwayland-cursor-1.2.0-3.fc20.x86_64.rpm
sudo rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/g/gtk3-3.10.4-1.fc20.x86_64.rpm
sudo rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/16/Fedora/x86_64/os/Packages/gdk-pixbuf2-2.24.0-1.fc16.x86_64.rpm

curl https://intoli.com/install-google-chrome.sh | bash it worked for me. my os is ami2 linux.

@SmtOmega This is what I use in Elastic Beanstalk:

File: ´.ebextensions/packages.config´

commands:
  install-chrome:
    command: |
      google-chrome --version || { wget -O google-chrome-stable.rpm https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm && sudo yum -y install ./google-chrome-stable.rpm; }

@falco467 Thanks so much this works fine

@malyw We you able to run google-chrome-stable using Puppeteer?

It appears that Puppeteer is unable to establish the WS connection and then times out. Do you have the same behavior?

However I am able to use google-chrome-stable to take screenshots through the CLI.

google-chrome-stable --headless --disable-gpu --screenshot https://google.com

I think that you probably need to specify the full executable path:

  'reactSnap': {
    'puppeteerArgs': ['--no-sandbox', '--disable-setuid-sandbox'],
    'puppeteerExecutablePath': '/opt/google/chrome/google-chrome'
  }

curl https://intoli.com/install-google-chrome.sh | bash solves the problem for me

@yzhang After running below line sudo yum install cups-libs dbus-glib libXrandr libXcursor libXinerama cairo cairo-gobject pango

I could see that all dependencies are resolved screen shot 2018-01-12 at 10 01 07 am

I am getting this error while running tests

Failed to launch chrome! /home/ec2-user/******/node_modules/puppeteer/.local-chromium/linux-508693/chrome-linux/chrome: symbol lookup error: /usr/lib64/libgtk-3.so.0: undefined symbol: g_type_add_instance_private

@awilson28

did you have to do anything else after running

no

Were any other packages required?

I didn’t receive message about it.

sudo yum --nogpgcheck localinstall https://intoli.com/blog/installing-google-chrome-on-centos/google-chrome-stable-60.0.3112.113-1.x86_64.rpm

didn’t help me. (Linux ip-172-31-31-178 4.9.43-17.38.amzn1.x86_64 #1 SMP Thu Aug 17 00:20:39 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux)

google-chrome-stable
/usr/bin/google-chrome-stable: symbol lookup error: /opt/google/chrome/lib/libgtk-3.so.0: undefined symbol: g_log_structured

Thanks for pointing to the troubleshooting document, same as the previous, it doesn’t help for Cent OS 6

Because CentOS/RHEL 6 isn’t supported by Chromium anymore. It hasn’t been for a good while.