20

Im trying to start puppeteer in headless:false mode. It's working on my local machine but when i push it to my server and try to start it i get this error:

4|scraperP | You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
4|scraperP | Error: Failed to launch chrome!
4|scraperP | [0620/073557.986542:ERROR:nacl_helper_linux.cc(310)] NaCl helper process running without a sandbox!
4|scraperP | Most likely you need to configure your SUID sandbox correctly
4|scraperP | TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
4|scraperP |     at onClose (/home/pjotr/scrapermmcreation/node_modules/puppeteer/lib/Launcher.js:285:14)
4|scraperP |     at Interface.helper.addEventListener (/home/pjotr/scrapermmcreation/node_modules/puppeteer/lib/Launcher.js:274:50)
4|scraperP |     at Interface.emit (events.js:165:20)
4|scraperP |     at Interface.close (readline.js:381:8)
4|scraperP |     at Socket.onend (readline.js:154:10)
4|scraperP |     at Socket.emit (events.js:165:20)
4|scraperP |     at endReadableNT (_stream_readable.js:1101:12)
4|scraperP |     at process._tickCallback (internal/process/next_tick.js:152:19)

When i start in headless:true mode i dont get htis error. Any idea how to solve this? This is how im launching puppeteer:

var browser = await puppeteer.launch({
   args: [
   '--ignore-certificate-errors',
   '--no-sandbox',
   '--disable-setuid-sandbox',
   '--window-size=1920,1080',
   "--disable-accelerated-2d-canvas",
   "--disable-gpu"],
   ignoreHTTPSErrors: true,
   headless: false,
 });
Pjotr Raskolnikov
  • 1,558
  • 2
  • 15
  • 27

5 Answers5

15

You can try tricking headless chrome to run with the GPU enabled:

const browser = await puppeteer.launch({
   headless: false,
   args: ['--headless'],
 })
kuceb
  • 16,573
  • 7
  • 42
  • 56
14

1. You have to install some lib package.

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 \
xvfb x11vnc x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps

2.Then start xvfb with your script

Example:

xvfb-run --server-args="-screen 0 1024x768x24" npm start

If you using Docker then follow this docker file

FROM node:8
RUN 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 \
xvfb x11vnc x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
EXPOSE 8081
CMD xvfb-run --server-args="-screen 0 1024x768x24" npm start

Here is an example of puppeteer with xvfb https://github.com/nsourov/Puppeteer-with-xvfb

Community
  • 1
  • 1
Naimur Rahman
  • 697
  • 4
  • 15
  • Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package libexpat1 E: Unable to locate package libpango-1.0-0 E: Couldn't find any package by glob ' libpango-1.0-0' E: Couldn't find any package by regex ' libpango-1.0-0' E: Unable to locate package libxcursor1 E: Unable to locate package ca-certificates E: Unable to locate package xvfb – Pjotr Raskolnikov Jun 21 '18 at 12:20
  • i tried to install all packages bt still have same problem – Pjotr Raskolnikov Jun 21 '18 at 14:09
  • I see how people went to that repo. You should add this inside the answer. – Md. Abu Taher Feb 24 '19 at 05:29
  • 1
    I followed the link and successfully resolved this problem on Ubuntu 16.04. This answer does not deserve a down vote. – Codism May 14 '19 at 13:49
  • 1
    How is this not the right answer / upvoted? Works like a charm, thanks – cviejo Sep 26 '19 at 11:05
  • 1
    I have been going from error to error in effort to get the puppeteer up and running on nodeJs digitalocean droplet and this was the last hurdle. Thanks! As for the lib packages if ```ldd chrome | grep not``` shows nothing in your node_modules/puppeteer/.../chrome-linux it is enought to ```sudo apt-get xvfb``` and then run the command with ```xvfb-run``` that Naimur said. Thanks again! – fedjedmedjed Mar 19 '21 at 07:19
1

The following worked for me

const puppeteer = require("puppeteer");
async function getData() {
   const browser = await puppeteer.launch({ headless: false });
}
getData();

Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
iliess-np
  • 35
  • 5
1

If you are running inside docker that time it's not worked so add the following code in browser lunch args and try it's worked fine

    var browser = await puppeteer.launch({
   args: [
   '--ignore-certificate-errors',
   '--no-sandbox',
   '--disable-setuid-sandbox',
   '--window-size=1920,1080',
   "--disable-accelerated-2d-canvas",
   "--disable-gpu"],
   ignoreHTTPSErrors: true,
 });

remove headless from browser lunch args

Armenia
  • 95
  • 1
  • 8
0

For me it works:

const puppeteer = require('puppeteer');

(async () => {
        const browser = await puppeteer.launch({ headless: false });

        console.log(await browser.userAgent());

        await browser.close();
})();
Ferrarezi
  • 801
  • 10
  • 12
  • This doesn't appear to do much of anything special that an ordinary launch wouldn't do. What's the user agent being logged good for? – ggorlen Nov 20 '22 at 17:18