Exception encountered: Could not find Chromium (rev. 1095492) when running puppeteer script in Jenkins (Has Debian as machine) - jenkins

I have developed a nodeJS based project using puppeteer and lighthouse. I am using puppeteer to login to any of the websites where user needs to login. After login, i navigate to any pages like my order, account info, ordered page, etc.
Note- I have this as a free style project on jenkins.
Exact Error in Details-
Exception encountered: Could not find Chromium (rev. 1095492). This can occur if either
you did not perform an installation before running the script (e.g. npm install) or
your cache path is incorrectly configured (which is: /root/.cache/puppeteer).
Tried below 3 scripts to run before calling my script-->
apt-get update
apt-get 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 libgbm-dev
npm install -g
npm run MyScriptName
Package.json-->
"devDependencies": {
"chromedriver": "^108.0.0",
"date-and-time": "^2.4.1",
"lighthouse": "^9.6.8",
"log4js": "^6.7.1",
"puppeteer": "^19.7.1"
},

Related

Failed to launch browser process using puppeter and docker image

We have used timesnap library for capture frames of html pages.
It's working on an ubuntu system, but we pushed this code in aws batch using docker image, then we return the error message below:
/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome:
error while loading shared libraries: libX11-xcb.so.1: cannot open
shared object file: No such file or directory
(node:77) UnhandledPromiseRejectionWarning: Error: Failed to launch
the browser process!
Below is my docker image sample:
FROM ubuntu:18.04
# Create app directory
WORKDIR /var/www/html/aws-batch-node/
RUN apt update && apt install -y \
chromium-browser \
chromium-chromedriver
RUN apt-get install -y libgbm-dev
RUN 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
FROM node:13.11.0
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package*.json ./
RUN npm install
RUN node ./node_modules/puppeteer/install.js
# Bundle app source
COPY . .
EXPOSE 8080
ENTRYPOINT [ "node", "index.js" ]

Laravel Sail install puppeteer chromium

I have setup a Laravel Sail environment and I am trying to save a webpage as a pdf using puppeteer.
I am currently using this package to run puppeteer via laravel - https://packagist.org/packages/spatie/browsershot
There requirements section specifies you need to download puppeteer via npm.
Laravel Sail has npm setup so I have installed the puppeteer package but when I try and save a webpage as a screenshot I get the following error
The command "PATH=$PATH:/usr/local/bin NODE_PATH=`npm root -g` node '/var/www/html/vendor/spatie/browsershot/src/../bin/browser.js' '{"url":"https:\/\/google.com","action":"screenshot","options":{"type":"png","path":"\/var\/www\/html\/storage\/app\/public\/screenshot.png","args":[],"viewport":{"width":800,"height":600}}}'" failed. Exit Code: 1(General error) Working directory: /var/www/html/public Output: ================ Error Output: ================ Error: Could not find expected browser (chrome) locally. Run `npm install` to download the correct Chromium revision (856583). at ChromeLauncher.launch (/var/www/html/node_modules/puppeteer/lib/cjs/puppeteer/node/Launcher.js:80:27) at async callChrome (/var/www/html/vendor/spatie/browsershot/bin/browser.js:69:23)
Its basically saying it can't find my local version of chromium and I'm not sure how to resolve this, if it wasn't running via docker I could install it locally and point to it but I don't think this is the best solution while using docker.
You need to install puppeteer with chromium inside the docker container.
I've currently the exact same setup for Browsershot with Sail.
You'll need to publish the sail config files which will allow you to edit the docker container.
sail artisan sail:publish
Then you can find the docker files in the root of your Laravel project under docker/8.0 or docker/7.4 depending on your PHP version.
Edit the docker file and add the installation command for puppeteer with chromium:
RUN apt-get update \
&& apt-get install -y gconf-service libasound2 libappindicator3-1 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 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 libgbm-dev libatk-bridge2.0-0 \
&& npm install --global --unsafe-perm puppeteer \
&& chmod -R o+rx /usr/lib/node_modules/puppeteer/.local-chromium
Then rebuild the dockerfile:
sail build --no-cache
Because puppeteer is running in docker we need to disable the sandbox. Bear in mind that docker will be a lot slower to generate the PDF then on your host machine so it might be wise to up the default timeout a bit as well.
use Spatie\Browsershot\Browsershot;
Browsershot::html($html)
->noSandbox()
->timeout(360)
->save('your.pdf');

Puppeteer in Gitlab CI/CD, testing in Headfull browser not working

I have a puppeteer project for testing my main application, that has some features that relies on visiblity, so have to be tested in headful mode.
I wanted to be able to start the testing script from gitlab (so that i can chain the pipeline to the main app), but seems that i cannot force the headless property to true: in fact, when I run the same script with healess: true, it works, while it fails for headless: false.
The error is:
> jest --runInBand
Error: Failed to launch the browser process!
Fontconfig warning: "/etc/fonts/fonts.conf", line 100: unknown element "blank"
[1485:1485:0908/113752.573573:ERROR:browser_main_loop.cc(1512)] Unable to open X display.
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md
at onClose (/builds/tests-puppeteer/node_modules/puppeteer/lib/Launcher.js:750:14)
at ChildProcess.<anonymous> (/builds/tests-puppeteer/node_modules/puppeteer/lib/Launcher.js:740:61)
at ChildProcess.emit (events.js:326:22)
at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
my jest-puppeteerconfig file:
module.exports = {
launch: {
headless: false,
slowMo: process.env.SLOWMO ? process.env.SLOWMO : 0,
devtools: false,
ignoreHTTPSErrors: true,
args: ['--no-sandbox', '--window-size=1920,1040']
}
}
And my .gitlab-CI.yaml:
# https://hub.docker.com/r/library/node/tags/
image: node:latest
cache:
paths:
- node_modules/
stages:
- test
- deploy
Integration_Tests:
stage: test
script:
- apt-get update
- apt-get install -yq 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
- npm install
- npm test
when: manual
allow_failure: false
artifacts:
paths:
- public

Error when running Headless Chrome in Jenkins Docker using puppeteer

I run Jenkins in Docker(Debian9) to test Angular 7 app by using ChromeHeadless browser.
I've the following in karma.conf.js
process.env.CHROME_BIN = require('puppeteer').executablePath()
karmaConfig.customLaunchers = {
ChromeHeadlessCI: {
base: 'ChromeHeadless',
flags: ['--no-sandbox',
'--disable-setuid-sandbox',
'--disable-gpu']
}
};
I've installed the following in my Docker:
RUN apt-get install -yq libc6-i386 libXss1 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
When running the tests in Jenkins I get the following:
[39mChromeHeadless stderr: /var/jenkins_home/workspace/new-sample-
project/node_modules/puppeteer/.local-chromium/linux-662092/chrome-linux/chrome:
error while loading shared libraries: libX11.so.6: cannot open shared object
file: No such file or directory
I don't know what the problem is? Is it related to the installed packages in Debain? What should I do?
the libX11.so.6 library is provided by the libx11-6 package.
so make sure you have that installed.

running Puppeteer headfull (headless false) inside docker

I need to launch Puppeteer headfull (headless false) inside docker with Chrome and I get the same error: "can't launch chrome".
I install all dependencies but it's falls anytime
Error: Failed to launch chrome!
TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
at onClose (/app/node_modules/puppeteer/lib/Launcher.js:339:14)
at ChildProcess.helper.addEventListener (/app/node_modules/puppeteer/lib/Launcher.js:329:60)
at emitTwo (events.js:131:20)
at ChildProcess.emit (events.js:214:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
Dockerfile
FROM node:8
RUN apt-get update && apt-get install -yq --no-install-recommends tightvncserver xfce4 xfce4-goodies apt-utils 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 x11vnc x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps xvfb apt-utils openvpn fping nano
RUN mkdir -p /app
WORKDIR /app
COPY . /app
# Install Chrome
#RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
#RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install
# Disable puppeteer chromium installation
#ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
# Install Puppeteer under /node_modules so it's available system-wide
ADD package.json package-lock.json /
RUN npm install
# Start server on port 3000
EXPOSE 3000
# Start script on Xvfb
CMD xvfb-run --server-args="-screen 0 1024x768x24" npm start
# VNC Server
CMD vncserver
CMD nc localhost 5901
CMD export DISPLAY=:1
CMD xhost +
# Running app
CMD node app.js

Resources