Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Use Puppeteer -- Error: Failed to launch chrome

This is the error I get. This occurs when the test code is run in the Gitlab CI.

However, it works fine locally. Someone please help?

2036 $ npm test

2037 > [email protected] test /builds/brhanuh/domestic-repair

2038 > jest --coverage 'unitTests/'

2039 Error: Failed to launch chrome!

2040 /builds/brhanuh/domestic-repair/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory

like image 390
Hanibal Brhanu Avatar asked Nov 30 '19 03:11

Hanibal Brhanu


People also ask

How do I use puppeteer to open Chrome?

By default, Puppeteer downloads and uses a specific version of Chromium so its API is guaranteed to work out of the box. To use Puppeteer with a different version of Chrome or Chromium, pass in the executable's path when creating a Browser instance: const browser = await puppeteer.

Does puppeteer work with Chrome?

Puppeteer is a Node library which provides a high-level API to control headless Chrome or Chromium over the DevTools Protocol. It can also be configured to use full (non-headless) Chrome or Chromium.

Does puppeteer work in Linux?

Running Puppeteer on AWS EC2 instance running Amazon-Linux Now Puppeteer can launch Chromium to run your tests. If you do not enable EPEL and if you continue installing chromium as part of npm install , Puppeteer cannot launch Chromium due to unavailablity of libatk-1.0. so. 0 and many more packages.


4 Answers

Install the missing packages using

sudo apt install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

Credits to @coldner on the puppetteer issue tracker for assembling the required pkgs.

If you encounter E: Unable to locate package errors, run sudo apt-get update.

like image 192
mohammad javad ahmadi Avatar answered Oct 14 '22 01:10

mohammad javad ahmadi


I just wanted to add to @mohammad's answer, that now Puppetteer now has an official troublshooting guide that helps you determine what to install.

Also, they recommend running the following command to tell which particular packages need installing on *nix systems:

ldd chrome | grep not

Or, if you have Chrome installed via Puppetteer via NPM like me:

ldd ./node_modules/puppeteer/.local-chromium/linux-756035/chrome-linux/chrome | grep not

Then, I was able to see what libraries were still missing, and install accordingly.

like image 32
Robert Dundon Avatar answered Oct 14 '22 01:10

Robert Dundon


you need to install required dependencies

here

https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md

under Chrome headless doesn't launch on UNIX you can find

Debian (e.g. Ubuntu) Dependencies
CentOS Dependencies
like image 42
hretic Avatar answered Oct 13 '22 23:10

hretic


For those that are still having this problem, you can try this.

sudo apt update && sudo apt install -y ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils

like image 43
IsuNas Labs Avatar answered Oct 13 '22 23:10

IsuNas Labs