Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ubuntu 18.04 Headless Chrome Node API - Puppeteer - Installation Guide #3443

Closed
JohnDotOwl opened this issue Oct 25, 2018 · 29 comments
Closed

Comments

@JohnDotOwl
Copy link

JohnDotOwl commented Oct 25, 2018

I ran sudo npm i puppeteer on Ubuntu 18.04

Sample Script


const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.screenshot({path: 'example.png'});

  await browser.close();
})();


Error
(node:23835) UnhandledPromiseRejectionWarning: Error: Chromium revision is not downloaded. Run "npm install" or "yarn install"
    at Launcher.launch (/var/www/puppeteer/node_modules/puppeteer/lib/Launcher.js:112:15)
    at <anonymous>
(node:23835) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:23835) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Node
v8.10.0

Fix for Above Error
sudo npm install --unsafe-perm

New Error Below

(node:25272) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
/var/www/puppeteer/node_modules/puppeteer/.local-chromium/linux-594312/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory

Fix new Error with 
gconf-service libasound2 libatk1.0-0 libatk-bridge2.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

@JohnDotOwl
Copy link
Author

Based on https://github.com/GoogleChrome/puppeteer

You only have to run the following command in Ubuntu 18.04

npm i puppeteer

Unfortunately this is not enough.

You will require the following Dependencies

sudo apt-get install gconf-service libasound2 libatk1.0-0 libatk-bridge2.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

After which if you run it as per their example , you will receive an error

    (node:28469) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
[1025/150325.817887:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

The solution to this is

const browser = await puppeteer.launch({args: ['--no-sandbox']});

Adding --no-sandbox

It will work accordingly then. The full working source code is below

    const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({args: ['--no-sandbox']});
  const page = await browser.newPage();
  await page.goto('http://owlcommand.com');
  await page.screenshot({path: 'example.png'});

  await browser.close();
})();

@JohnDotOwl JohnDotOwl changed the title Ubuntu 18.04 Error - Chromium revision is not downloaded. Ubuntu 18.04 Headless Chrome Node API - Puppeteer - Installation Guide Oct 25, 2018
@sandysandeepkumar
Copy link

how to handle captcha with headless chrome puppeteer

@shubhamdixit863
Copy link

This works :)

@2yk
Copy link

2yk commented May 6, 2019

Based on https://github.com/GoogleChrome/puppeteer

You only have to run the following command in Ubuntu 18.04

npm i puppeteer

Unfortunately this is not enough.

You will require the following Dependencies

sudo apt-get install gconf-service libasound2 libatk1.0-0 libatk-bridge2.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

After which if you run it as per their example , you will receive an error

    (node:28469) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
[1025/150325.817887:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

The solution to this is

const browser = await puppeteer.launch({args: ['--no-sandbox']});

Adding --no-sandbox

It will work accordingly then. The full working source code is below

    const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({args: ['--no-sandbox']});
  const page = await browser.newPage();
  await page.goto('http://owlcommand.com');
  await page.screenshot({path: 'example.png'});

  await browser.close();
})();

Thanks a lot, it works.

@fireairforce
Copy link

i think you can also try this way:

 const broswer = await puppteer.launch({
        executablePath:path.resolve(__dirname,'../node_modules/puppeteer/.local-chromium/linux-650583/chrome-linux/chrome')
    });

my enviroment is ubuntu 16.04,you can add the path to the puppteer

@aleexaib
Copy link

@fireairforce this never worked for me :/

i think you can also try this way:

 const broswer = await puppteer.launch({
        executablePath:path.resolve(__dirname,'../node_modules/puppeteer/.local-chromium/linux-650583/chrome-linux/chrome')
    });

my enviroment is ubuntu 16.04,you can add the path to the puppteer

@fireairforce
Copy link

@fireairforce this never worked for me :/

i think you can also try this way:

 const broswer = await puppteer.launch({
        executablePath:path.resolve(__dirname,'../node_modules/puppeteer/.local-chromium/linux-650583/chrome-linux/chrome')
    });

my enviroment is ubuntu 16.04,you can add the path to the puppteer

 const browser = await puppeteer.launch({args: ['--no-sandbox']});

you can try this way?

@aleexaib
Copy link

aleexaib commented Jun 11, 2019

@fireairforce Yes now going to try that one 🦅 and for that i have do first
sudo apt-get install gconf-service libasound2 libatk1.0-0 libatk-bridge2.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

@fireairforce this never worked for me :/

i think you can also try this way:

 const broswer = await puppteer.launch({
        executablePath:path.resolve(__dirname,'../node_modules/puppeteer/.local-chromium/linux-650583/chrome-linux/chrome')
    });

my enviroment is ubuntu 16.04,you can add the path to the puppteer

 const browser = await puppeteer.launch({args: ['--no-sandbox']});

you can try this way?

@nomi-shah
Copy link

works :)

@aleexaib
Copy link

works :)

Which one worked for you?

@nomi-shah
Copy link

**i just install dependencies; on my ubuntu live server **
sudo apt-get install gconf-service libasound2 libatk1.0-0 libatk-bridge2.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

@EnetoJara
Copy link

EnetoJara commented Jan 30, 2020

Im running BugBuntu 18.04 and none of that is need it
all you need to do is to tell headless: false
wrap the whole thing in a try catch

const puppeteer = require('puppeteer');

(async () => {
    try {

  const browser = await puppeteer.launch({
      headless: false
  })
  const page = await browser.newPage();
  await page.goto('https://www.instagram.com');
  await page.screenshot({path: 'example.png'});

} catch (error) {
    console.log('error: ', error);
}
})();

@rannooo
Copy link

rannooo commented May 7, 2020

With puppeteer 3.0.0+ I also had to install libgbm-dev as a dependency

sudo apt install libgbm-dev

@impressto
Copy link

I found that with the latest version of puppeteer 3+ which uses the latest chromium, I had to do the following on Ubuntu 20.

sudo apt-get update && apt-get install -y libgtk2.0-0 libgtk-3-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb libgbm-dev

In docker I had to add the following to my Docker file:

RUN apt-get update && \
  apt-get install -y libgtk2.0-0 libgtk-3-0 libnotify-dev \
  libgconf-2-4 libnss3 libxss1 \
  libasound2 libxtst6 xauth xvfb \
  libgbm-dev

I also had to add the argument '--no-sandbox' when calling puppeteer.

@EnetoJara
Copy link

EnetoJara commented May 18, 2020

It is easier if you just install $ sudó apt install build-essential also if you have a fresh version of bugbuntu probably you are missing typhon2.7 so install it as well
sudo apt install python.
Make sure it is 2.. even Though NodeJS supports python 3.. node-gyp stills runs on python 2..
Couple of days ago I created a puppeteer script on the latest bugbuntu version and it ran 😌👌

@onemans-battle
Copy link

onemans-battle commented May 22, 2020

I tried a simple and crude way, it works:
apt install chromium-browser
Let it install all the dependencies by itself ... Although I don't use chromium installed in this way

@gosua
Copy link

gosua commented Jun 2, 2020

I tried a simple and crude way, it works:
apt install chromium-browser
Let it install all the dependencies by itself ... Although I don't use chromium installed in this way

This was the only solution working within my rabbitmq:management container. I like your solution because it's simple and short.

@justekoro
Copy link

Hello, it also won't work for me, I get the same error (Error: Could not find browser revision 737027. Run "npm install" or "yarn install" to download a browser binary.)

Could you please help me? I did everything you told ^ up...

@marxros
Copy link

marxros commented Jun 3, 2020

@Rainbowhat
works... thanks!!

@martintali
Copy link

With puppeteer 3.0.0+ I also had to install libgbm-dev as a dependency

sudo apt install libgbm-dev
@rannooo
This worked for me! Thanks!

@maksim36ua
Copy link

In docker I had to add the following to my Docker file:

RUN apt-get update && \
  apt-get install -y libgtk2.0-0 libgtk-3-0 libnotify-dev \
  libgconf-2-4 libnss3 libxss1 \
  libasound2 libxtst6 xauth xvfb \
  libgbm-dev

I also had to add the argument '--no-sandbox' when calling puppeteer.

Worked for me, thanks @impressto

@IvanSafonov
Copy link

I've had the same problem on Ubuntu 20.04. Fixed with installing these packages

sudo apt-get update
sudo apt-get -y --no-install-recommends install libxrandr2 libatk1.0-0 libatk-bridge2.0-0 libx11-xcb1 libxcb-dri3-0 libxcomposite1 libxcursor1 libxdamage1 libcups2 libdrm2 libgbm1 libgtk-3-0 

And it's possible to see the list of missing libraries with ldd

ldd ./node_modules/puppeteer/.local-chromium/linux-782078/chrome-linux/chrome | grep "not found"

@josem32
Copy link

josem32 commented Sep 1, 2020

With puppeteer 3.0.0+ I also had to install libgbm-dev as a dependency

sudo apt install libgbm-dev

this worked for me

@yonish3
Copy link

yonish3 commented Sep 8, 2020

I found that with the latest version of puppeteer 3+ which uses the latest chromium, I had to do the following on Ubuntu 20.

sudo apt-get update && apt-get install -y libgtk2.0-0 libgtk-3-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb libgbm-dev

In docker I had to add the following to my Docker file:

RUN apt-get update && \
  apt-get install -y libgtk2.0-0 libgtk-3-0 libnotify-dev \
  libgconf-2-4 libnss3 libxss1 \
  libasound2 libxtst6 xauth xvfb \
  libgbm-dev

I also had to add the argument '--no-sandbox' when calling puppeteer.

this actually worked for me on Digital Ocean Droplet!
thanks a lot!

@plasmatiger
Copy link

plasmatiger commented Sep 24, 2020

Based on https://github.com/GoogleChrome/puppeteer

You only have to run the following command in Ubuntu 18.04

npm i puppeteer

Unfortunately this is not enough.

You will require the following Dependencies

sudo apt-get install gconf-service libasound2 libatk1.0-0 libatk-bridge2.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

After which if you run it as per their example , you will receive an error

    (node:28469) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
[1025/150325.817887:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

The solution to this is

const browser = await puppeteer.launch({args: ['--no-sandbox']});

Adding --no-sandbox

It will work accordingly then. The full working source code is below

    const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({args: ['--no-sandbox']});
  const page = await browser.newPage();
  await page.goto('http://owlcommand.com');
  await page.screenshot({path: 'example.png'});

  await browser.close();
})();

I am unable to solve the problem with these steps. Pasting the output of npm i puppeteer

npm i puppeteer

> puppeteer@5.3.1 install /home/ubuntu/vendor-module/node_modules/puppeteer
> node install.js

(node:18339) UnhandledPromiseRejectionWarning: /home/ubuntu/vendor-module/node_modules/puppeteer/lib/cjs/puppeteer/install.js:138
                    catch {
                          ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at download (/home/ubuntu/vendor-module/node_modules/puppeteer/install.js:35:7)
(node:18339) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

Refer https://stackoverflow.com/questions/64043249/failed-to-launch-chromium-headless-using-puppeteer-on-ubuntu-16-04-aws-ec2-insta for more details

@Hiba-Ed
Copy link

Hiba-Ed commented Sep 25, 2020

I found that with the latest version of puppeteer 3+ which uses the latest chromium, I had to do the following on Ubuntu 20.

sudo apt-get update && apt-get install -y libgtk2.0-0 libgtk-3-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb libgbm-dev

In docker I had to add the following to my Docker file:

RUN apt-get update && \
  apt-get install -y libgtk2.0-0 libgtk-3-0 libnotify-dev \
  libgconf-2-4 libnss3 libxss1 \
  libasound2 libxtst6 xauth xvfb \
  libgbm-dev

I also had to add the argument '--no-sandbox' when calling puppeteer.

Thank you so much. This worked for me on ubuntu 18.04.

@LucasTejero
Copy link

i fix it!!!
i was open the browser outside a function like this
const browserPromise = puppeteer.use(StealthPlugin()).launch({ args: ["--no-sandbox"], });
i move it inside the function and it works!

@wallaceturner
Copy link

Installing libgbm-dev broke the rescue console (QEMU) for me on Ubuntu 20.04; I was able to get puppeteer working with just the following:

sudo apt-get install xvfb libnss3 libatk1.0-0 libatk-bridge2.0-0 libxcomposite1 libcups2 libxrandr2 libpangocairo-1.0-0 libgtk-3-0 -y

allyusd pushed a commit to allyusd/actionhero that referenced this issue Nov 17, 2020
install puppeteer dependencies
launch puppeteer with no-sandbox

ref: puppeteer/puppeteer#3443 (comment)
allyusd added a commit to allyusd/actionhero that referenced this issue Nov 17, 2020
install puppeteer dependencies
launch puppeteer with no-sandbox

ref: puppeteer/puppeteer#3443 (comment)
evantahler pushed a commit to actionhero/actionhero that referenced this issue Nov 17, 2020
install puppeteer dependencies
launch puppeteer with no-sandbox

ref: puppeteer/puppeteer#3443 (comment)
evantahler pushed a commit to actionhero/actionhero that referenced this issue Nov 17, 2020
install puppeteer dependencies
launch puppeteer with no-sandbox

ref: puppeteer/puppeteer#3443 (comment)
evantahler added a commit to actionhero/actionhero that referenced this issue Nov 17, 2020
* Browser tests with Puppeteer rather than Selenium

* try headless puppeteer

* fixed ci fail (#1654)

install puppeteer dependencies
launch puppeteer with no-sandbox

ref: puppeteer/puppeteer#3443 (comment)

* Update dependencies

* give a title to install steps

* increase sleep time in test

* relax test timing

Co-authored-by: Hong, Jian-Ching <allyusd@users.noreply.github.com>
@caioagiani
Copy link

sudo apt-get update
sudo apt-get -y --no-install-recommends install libxrandr2 libatk1.0-0 libatk-bridge2.0-0 libx11-xcb1 libxcb-dri3-0 libxcomposite1 libxcursor1 libxdamage1 libcups2 libdrm2 libgbm1 libgtk-3-0 

Its works after install chromium: sudo apt install -y chromium-browser

petterigit added a commit to petterigit/TheSir that referenced this issue Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests