question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ubuntu 18.04 Headless Chrome Node API - Puppeteer - Installation Guide

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:12
  • Comments:29

github_iconTop GitHub Comments

310reactions
JohnDotOwlcommented, Oct 25, 2018

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();
})();
130reactions
sandysandeepkumarcommented, Dec 17, 2018
how to handle captcha with headless chrome puppeteer
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Install and Configure Puppeteer on Ubuntu 18.04 LTS
In this post we are going to learn how to install and configure Puppeteer on top of Ubuntu 18.04 LTS by following few...
Read more >
How to Install & Configure Puppeteer on Ubuntu 18.04 LTS
Today we will learn to install Puppeteer on top of Ubuntu 18.04 LTS by following few easy steps. We assume you don't have...
Read more >
Headless Chrome Node API and Puppeteer installation
Run "npm install" or "yarn install" at Launcher. launch owlcommand.com /puppeteer/node_modules/puppeteer/lib/Launcher. js:112:15) at <anonymous ...
Read more >
Installing Puppeteer on an Ubuntu AWS EC2 Instance
Installing Puppeteer on an Ubuntu AWS EC2 Instance · Go to your project directory · Install NodeJS/npm if you haven't · Run: sudo...
Read more >
How To Scrape a Website Using Node.js and Puppeteer
js on macOS or Ubuntu 18.04, or you can follow this guide to install Node.js on Ubuntu 18.04 using a PPA. Step 1...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found