puppeteer: Chrome Headless doesn't launch on Debian

Running this example code from the README:

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'});

browser.close();
})();

I get the following error output:

(node:30559) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Failed to connect to chrome!
(node:30559) [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.

Platform info:

% uname -a
Linux localhost 3.14.0 #1 SMP PREEMPT Thu Jul 13 12:08:15 PDT 2017 x86_64 GNU/Linux
% lsb_release -a
Distributor ID: Debian
Description:    Debian GNU/Linux 9.0 (stretch)
Release:        9.0
Codename:       stretch
% node --version
v8.1.1
% cat package.json
{
  "dependencies": {
    "puppeteer": "^0.9.0"
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 101
  • Comments: 198 (49 by maintainers)

Commits related to this issue

Most upvoted comments

for the dockerisers amongst us - i’ve launched successfully with this setup:

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

RUN npm i puppeteer

RUN echo "\
const puppeteer = require('puppeteer');\n\
(async () => {\n\
  const browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});\n\
  const page = await browser.newPage();\n\
  await page.goto('https://example.com');\n\
  await page.screenshot({path: 'example.png'});\n\
  browser.close();\n\
})();\
" > index.js

CMD ["node", "index.js"]

The action to resolve this (which I’m working on now) is getting a list of all the required dependencies to run Chromium. Straight from the Debian the requirements are below. Documenting this for a PR shortly.

Dependencies for debian
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

This should be solved with the ‘–no-sandbox’ flag:

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

Can’t launch the local chrome:

% ~/p /home/fortes/p/node_modules/puppeteer/.local-chromium/linux-494755/chrome-linux/chrome --help
/home/fortes/p/node_modules/puppeteer/.local-chromium/linux-494755/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory

I should have mentioned that this is a headless machine that I’m ssh’d into. Given that this is for headless Chrome, I assume that scenario is still supported?

It’s worth considering adding both --no-sandbox --disable-setuid-sandbox to the default flags on linux.

In chrome-launcher/lighthouse we’re already including --disable-setuid-sandbox and plan to add --no-sandbox soon for this reason.

sudo apt-get install 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

For some reason I was missing the libxcb-dri3.so.0 shared lib (I installed every packages mentioned in the troubleshooting guide previously). On Puppeteer 3.0.1.

Fixed by adding the libxcb-dri3-0 package.

sudo apt install libxcb-dri3-0

I don’t know if it an isolated issue, if future readers have the same problem, it may be added to the packages list.

Works perfectly on ubuntu xenial - no gtk - remote - ssh - non root Linux ip---- 4.4.0-1022-aws #31-Ubuntu SMP Tue Jun 27 11:27:55 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux Ubuntu Xenial

update sudp apt-get update node v8.4.0 curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - sudo apt-get install -y nodejs

Install npm sudo apt-get install npm

Install puppeteer npm i puppeteer

Installed all the dependencies sudo apt-get install 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

pass this to launch ({args: [‘–no-sandbox’, ‘–disable-setuid-sandbox’]}

running as non root

Works perfectly.

On Ubuntu 18.04 we had to install these:

sudo apt-get install -y libx11-xcb1 libxrandr2 libasound2 libpangocairo-1.0-0 libatk1.0-0 libatk-bridge2.0-0 libgtk-3-0 libnss3 libxss1

Strangely enough, on CentOS 7.4.1708 we just had to install:

# yum provides '*/libXss.so.1'
sudo yum install libXScrnSaver

Still no luck w/ those two flags:

febian:~/p /home/fortes/p/node_modules/puppeteer/.local-chromium/linux-494755/chrome-linux/chrome --no-sandbox --disable-setuid-sandbox

(chrome:12521): Gtk-WARNING **: cannot open display:
[0816/111850.260959:ERROR:nacl_helper_linux.cc(310)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly

Same warning when just with --no-sandbox

In my opinion this isn’t solved - the libraries should be delivered with puppeteer and work out of the box.

I have always strongly urged people to never turn off the sandbox without a good cause, even in tests. It is a major part of the security system from what I understand.

I’m setting up a squeaky clean and fresh Debian VM to run some install steps in. We should be able to have it well documented how to get it operating without compromising system security.

I recall PHPStorm for example having an issue where it was serving on localhost, so a remote code execution exploit was opened up for any site including code that would look for the port in use and take advantage of a flaw in that server. Let’s not open people up to security issues by disabling the sandbox here. Where they could be visiting any number of sites including code that looks for exploits to abuse.

This may or may not be helpful…

I run Electron in a Docker instance on Docker Cloud.

I run this command:

xvfb-run -a --server-args="-screen 0 1024x1024x24" ./node_modules/.bin/electron ./index.js

and my Dockerfile contains the following commands to install dependencies:

RUN apt-get update -y -q
RUN apt-get install -y -q xvfb libgtk2.0-0 libxtst6 libxss1 libgconf-2-4 libnss3 libasound2

It doesn’t work out of the box, that’s the issue. And there’s zero decent documentation that’s straight forward in the Install instructions in the README. Also, these options didn’t even work and this thread has 100’s of comments. I think it’d be appropriate to post a comment here and lock the issue/thread.

@campbecf @danielsantiago I’ve hacked together a fork of Heroku’s Chrome buildpack that appears to work with Puppeteer. heroku buildpacks:add https://github.com/mikeraimondi/heroku-buildpack-google-chrome. { args: ['--no-sandbox'] } is required in the call to launch()

try this code on ubuntu server. i’m ok.

 sudo 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

I run into this problem trying to use puppeteer in Heroku

Shoot @earshinov you were right, I missed the 1 when trying to install it. I ran sudo apt-get update sudo apt-get install libgbm1 and now everything works. Thanks for the help!

Running into the problem using Windows Subsystem for Linux (WSL), as the “emulated” kernel doesn’t support namespacing, and its not possible to upgrade the kernel. No combination of flags seemed to work, I switched to native Node.js on Windows and everything works fine.

Hopefully this helps everyone running Debian.

The following works for me on Debian Jessie (without disabling sandbox!).

  1. Dependencies.
  1. Puppeteer needs the following kernel feature enabled “user namespacing” (if you want to run without disabling sandbox).
  • Check your kernel supports the feature (it does if this shows CONFIG_USER_NS=y) cat /boot/config-$(uname -r) | grep CONFIG_USER_NS
  • Command to permanently enable: sudo su; echo 'kernel.unprivileged_userns_clone=1' > /etc/sysctl.d/00-local-userns.conf; service procps restart
  • Note: it is disabled by default in Debian Jessie because of a local security issue. This is safely patched as of 3.16.51-3+deb8u1 (see https://security-tracker.debian.org/tracker/CVE-2017-17448)

For anyone experiencing the same NaCl helper process running without a sandbox error with the sandbox flags and all of the proper dependencies - make sure you aren’t accidentally running with headless: false. Running with that parameter gave me the same error (totally didn’t take me an hour to figure it out 🙃)

Already have that installed, perhaps a different package is needed?

% ~/p sudo apt-get install libx11-xcb1
Reading package lists... Done
Building dependency tree
Reading state information... Done
libx11-xcb1 is already the newest version (2:1.6.4-3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

The package is actually named libgbm1 (I made a typo). Did you try installing that as well (and apt-get update before installing just in case)?

Haha, but how do I write the list if I can’t copy and paste ? That was my question 😉 In fact, I ended up using an ssh server and connecting to it from another machine just to copy and paste things more easily !

Doing both of the following fix it for me

Installing following dependencies (thanks @zhaopengme ) sudo 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

launching in no sandbox mode

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

Error message: Screenshot failed Error: Failed to launch chrome! puppeteer/.local-chromium/linux-
/chrome-linux/chrome: error while loading shared libraries: libX11 : cannot open shared object file: No such file or directory

Solution: To get Chromium screenshots working on Ubuntu 16.04 I had to install the missing libx11 package plus several others which I determined by trail and error. Ultimately installed all these: (command line: sudo apt install <name>)

  • libx11-xcb1
  • libx11composite1
  • libx11cursor1
  • libx11damage1
  • libcups2
  • libxss1
  • libxrandr2
  • libpangocairo-1.0-0
  • libatk1.0-0
  • libatk-bridge2.0-0
  • libgtk-3-0

I finally get it work on centos 7.3.

  1. install all dependencies:
yum install pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64 libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXtst.x86_64 cups-libs.x86_64 libXScrnSaver.x86_64 libXrandr.x86_64 GConf2.x86_64 alsa-lib.x86_64 atk.x86_64 gtk3.x86_64 -y

yum install ipa-gothic-fonts xorg-x11-fonts-100dpi xorg-x11-fonts-75dpi xorg-x11-utils xorg-x11-fonts-cyrillic xorg-x11-fonts-Type1 xorg-x11-fonts-misc -y
  1. modify the example script as follow:
const puppeteer = require('puppeteer');

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

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

To run chromium from command line, you should add --headless to prevent GUI related error, like this:

node_modules/puppeteer/.local-chromium/linux-499413/chrome-linux/chrome -v --headless --no-sandbox --disable-setuid-sandbox

That’s interesting. Could you please:

  1. try launching chromium manually (chromium is downloaded at node_modules/puppeteer/.local-chromium)
  2. if chromium launches for you, run the following (notice the added dumpio flag to the puppeteer.launch) and check what’s in the stderr:
const puppeteer = require('puppeteer');
(async() => {
  const browser = await puppeteer.launch({dumpio: true});
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.screenshot({path: 'example.png'});
  browser.close();
})();

Hi folks, I’m running an AWS EC2 instance with Ubuntu and I can’t get it to work with or without sandboxing.

With args: ['--no-sandbox', '--disable-setuid-sandbox'],:

Error: Failed to launch chrome!
[0813/115451.196200:ERROR:nacl_helper_linux.cc(310)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly

Without args: ['--no-sandbox', '--disable-setuid-sandbox'],

Error: Failed to launch chrome!

…And that’s it.

I’ve confirmed that all my dependencies are installed and Chrome appears to work from the command line. The configuration of Chrome itself came from yarn install puppeteer.

Tried running node_modules/puppeteer/.local-chromium/linux-674921/chrome-linux/chrome -v as @fortes did above, but this produced no console output. The same with --help instead of -v produced: “No manual entry for chrome”.

It is now 5 in the morning so I think I’d better tap out, but any direction as to what I can test would be deeply appreciated.

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

Please try above command for installing all dependencies.

Using an external build is already detailed in the api docs and in the main README under Default Runtime Settings. I don’t think we need to go adding that anywhere else for the time being.

How about providing a Docker image or something like that with the correct libs preinstalled? Would that be feasible?

IMO a Docker image while nice, should be something internally waited on until after a stable tag. Right now we should focus on the issues with getting it running directly on machines. Improve this experience. And then once we are stable, we can assess how to best provide a docker image for people to use.

headless exists to not need xvfb to virtualize the X instance for Chrome. Since it is all done in software internally.

In addition to libxcb-dri3-0, as @rigwild pointed out, I had to also: apt-get install libgbm1

It was also not working for me on Debian.

This is what solved the problem for me: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#setting-up-chrome-linux-sandbox

I had to enable the user namespace cloning: sudo sysctl -w kernel.unprivileged_userns_clone=1

Hi folks, I’m running an AWS EC2 instance with Ubuntu and I can’t get it to work with or without sandboxing.

With args: ['--no-sandbox', '--disable-setuid-sandbox'],:

Error: Failed to launch chrome!
[0813/115451.196200:ERROR:nacl_helper_linux.cc(310)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly

Without args: ['--no-sandbox', '--disable-setuid-sandbox'],

Error: Failed to launch chrome!

…And that’s it.

I’ve confirmed that all my dependencies are installed and Chrome appears to work from the command line. The configuration of Chrome itself came from yarn install puppeteer.

Tried running node_modules/puppeteer/.local-chromium/linux-674921/chrome-linux/chrome -v as @fortes did above, but this produced no console output. The same with --help instead of -v produced: “No manual entry for chrome”.

It is now 5 in the morning so I think I’d better tap out, but any direction as to what I can test would be deeply appreciated.

Hi,

I am on Debian 10 (Buster) and I have followed this recommended solution to make it : sudo sysctl -w kernel.unprivileged_userns_clone=1

@Garbee I personally had to use a Docker image for my application to work and after trying many of the images I found on the internet none of them simply “just work” without installing extra dependencies to the system libs.

If someone knows of a Docker image that runs Puppeteer out of the box, I would be thrilled to know what it is.

I agree with @egoroof. If this was an edge case OS, I’d say close it - but this affects Windows users with WSL and Ubuntu (and other Debian) users. That’s a huge base of users that need to troubleshoot.

Here’s a neat alternative to copy-pasting the dependency list:

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

apt-get install $( \
  dpkg -I google-chrome-stable_current_amd64.deb | \
  awk '/^ Depends: / { gsub(/Depends:|,|\([^\)]*\)/, ""); print }' \
)

Probably doesn’t cover all edge cases, but at least removes the hardcoding. Tested on node:10 image.

Just in case, Chromium’s dependencies don’t cut it, unfortunately, so can’t get by with apt-cache.

Not sure if either of you can/want to use docker to do the provisioning, but I’ve open-sourced all the work to running on linux here.

I don’t see anything in the README for puppeteer that tell you about this. npm install puppeteer does not leave you with a working chrome, as you’d expect it to (and as the README implies it will).

Hmm that is unfortunate. 🤔

How about providing a Docker image or something like that with the correct libs preinstalled? Would that be feasible?

Addendum: Thanks a lot for the info @JoelEinbinder - I couldn’t run it on my machine, either, so I installed =www-client/google-chrome-unstable-62.0.3178.0 (on Gentoo GNU/Linux). I am running a grsec kernel, which is known to break the Chrome sandbox.

So I pass options to launch():

const options = { executablePath: '/usr/bin/google-chrome-unstable' };
const browser = await puppeteer.launch(options);

I would add this to the docs, but I’m unsure where to put it. I just signed up for the CLA. Can anyone guide me there?

Ah yea, that’s it. Your box host is messing you up. It has a very old Kernel. Debian 9 ships with 4.9.0-3 and you’re running 3.14.0. So the security features of the kernel are extremely different. So, you may be in a case where you need to fallback to using the older file-based sandbox to have some level of security.

Although, in all honesty… Upgrade the kernel or get a host that doesn’t keep you back. It’s very important that the kernel gets updated for the best security and you’re being left vulnerable.

The command to install deps has been posted at least half a dozen times now.

Please DO NOT post the packages to install again. They are located in the troubleshooting guide and are here plenty. If you find an error in the package list, please submit a pull request to address that issue.

Works fine on Ubuntu 18.10 after manual installation of the following packages:

  1. libx11-xcb1
  2. libxcomposite
  3. libxcursor1
  4. libxdamage1
  5. libxss1
  6. libxrandr2
  7. libasound2
  8. libpangocairo-1.0-0
  9. libatk1.0-0
  10. libatk-bridge2.0-0
  11. libgtk-3-0

To resolve sandbox security issue, the server sysctl needs to have kernel.unprivileged_userns_clone=1 flag enabled.

For other issues, make sure all required dependencies are installed from this list.

thats resolve my problem. OS -Linux 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u3 (2017-08-06) x86_64 GNU/Linux npm - 5.3.0 node - v8.4.0

  1. set packages
  2. Run with root echo 1 > /proc/sys/kernel/unprivileged_userns_clone (work untill reboot, i guess)
  3. run example node example.js
const puppeteer = require( 'puppeteer' );

(async () =>{

	const browser = await puppeteer.launch( ) // , '--no-sandbox', '--disable-setuid-sandbox'
	const page    = await browser.newPage()
	await page.goto( 'https://google.com', {waitUntil :'networkidle'} )
// Type our query into the search bar
	await page.type( 'puppeteer' )

	await page.click( 'input[type="submit"]' )

// Wait for the results to show up
	await page.waitForSelector( 'h3 a' )

// Extract the results from the page
	const links = await page.evaluate( () =>{
		const anchors = Array.from( document.querySelectorAll( 'h3 a' ) )
		return anchors.map( anchor => anchor.textContent )
	} )
	console.log( links.join( '\n' ) )
	browser.close()

})()

description

P.S. for ubuntu kernel:

It is turned on by default, but can be turned off if admins prefer or,
more importantly, if a security vulnerability is found.

The intent is to use this as mitigation so long as Ubuntu is on the
cutting edge of enablement for things like unprivileged filesystem
mounting.

(This patch is tweaked from the one currently still in Debian sid, which
in turn came from the patch we had in saucy)

source

I’ve installed those and can now run chrome --help. However, if I try to run chrome -v, I get the following:

febian:~/p /home/fortes/p/node_modules/puppeteer/.local-chromium/linux-494755/chrome-linux/chrome -v
[11104:11104:0816/105455.434188:FATAL:zygote_host_impl_linux.cc(123)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux_suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live dangerously and need an immediate workaround, you can try using --no-sandbox.
#0 0x556f97804657 base::debug::StackTrace::StackTrace()
#1 0x556f97818311 logging::LogMessage::~LogMessage()
#2 0x556f96a091f1 content::ZygoteHostImpl::Init()
#3 0x556f966a3da0 content::BrowserMainLoop::EarlyInitialization()
#4 0x556f966aa4c3 content::BrowserMainRunnerImpl::Initialize()
#5 0x556f966a3532 content::BrowserMain()
#6 0x556f9750f7fd content::ContentMainRunnerImpl::Run()
#7 0x556f97517314 service_manager::Main()
#8 0x556f9750e462 content::ContentMain()
#9 0x556f9614eb74 ChromeMain
#10 0x7fa1f27c92b1 __libc_start_main
#11 0x556f9614e9d0 <unknown>

Received signal 6
#0 0x556f97804657 base::debug::StackTrace::StackTrace()
#1 0x556f978041cf base::debug::(anonymous namespace)::StackDumpSignalHandler()
#2 0x7fa1f8b690c0 <unknown>
#3 0x7fa1f27dbfcf gsignal
#4 0x7fa1f27dd3fa abort
#5 0x556f97803202 base::debug::BreakDebugger()
#6 0x556f978187cc logging::LogMessage::~LogMessage()
#7 0x556f96a091f1 content::ZygoteHostImpl::Init()
#8 0x556f966a3da0 content::BrowserMainLoop::EarlyInitialization()
#9 0x556f966aa4c3 content::BrowserMainRunnerImpl::Initialize()
#10 0x556f966a3532 content::BrowserMain()
#11 0x556f9750f7fd content::ContentMainRunnerImpl::Run()
#12 0x556f97517314 service_manager::Main()
#13 0x556f9750e462 content::ContentMain()
#14 0x556f9614eb74 ChromeMain
#15 0x7fa1f27c92b1 __libc_start_main
#16 0x556f9614e9d0 <unknown>
  r8: 0000000000000000  r9: 00007fff8e2bda50 r10: 0000000000000008 r11: 0000000000000246
 r12: 00007fff8e2be160 r13: 000000000000016d r14: 00007fff8e2be158 r15: 00007fff8e2be150
  di: 0000000000000002  si: 00007fff8e2bda50  bp: 00007fff8e2bdd00  bx: 0000000000000006
  dx: 0000000000000000  ax: 0000000000000000  cx: 00007fa1f27dbfcf  sp: 00007fff8e2bdac8
  ip: 00007fa1f27dbfcf efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
 trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]
Calling _exit(1). Core file will not be generated.

I’m disappointed that installing X-related dependencies are the most upvoted answers. Chrome Headless is made to avoid that dependency so it sounds like a terrible workaround.

PR #311 is open to start looking at expanding the install script to make it much more interactive and friendly to help catch installation problems. You can check the code out from that PR and give it a spin. Please report on the PR of any problems you face or things you think could improve the flow.

@Garbee awesome. This stuff isn’t my strong suit.

I’m going to attempt to replace the Electron usage with puppeteer, so hopefully this will simplify our environment.

RUN apt-get update -y -q RUN apt-get install -y -q xvfb libgtk2.0-0 libxtst6 libxss1 libgconf-2-4 libnss3 libasound2

You are the best dude. Thank you !

I arrived here from the troubleshooting.md page, recommended due to the ELF: not found puppeteer startup error, on Raspbian Buster. In the end I found a good-enough solution in using puppeteer-core with chromium(as described here):

sudo apt install chromium-browser chromium-codecs-ffmpeg
npm i puppeteer-core
const puppeteer = require('puppeteer-core');
const browser = await puppeteer.launch({executablePath: '/usr/bin/chromium-browser'});

This helped me test pdf generation with non-english fonts.


RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
    && apt-get update \
    && apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf \
      --no-install-recommends \
    && rm -rf /var/lib/apt/lists/*

RUN npm i puppeteer

RUN echo "\
const puppeteer = require('puppeteer');\n\
(async () => {\n\
  const browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});\n\
  const page = await browser.newPage();\n\
  await page.goto('https://www.baidu.com/');\n\
  const pdf = await page.pdf({path: 'example.pdf'});\n\
  console.log(pdf.toString('base64'));\n\
  browser.close();\n\
})();\
" > index.js

CMD ["node", "index.js"]```

@CoVoCre If you use the list in the troubleshooting guide (or most of them here that are a single line.) They’ll all install with just copy and pasting the command. So no, you don’t need to copy every single one manually to install. A simple apt-get install {pack1} {pack2} ... works just fine.

Am I seriously supposed to copy every one of those packages by hand ?!?!?! Is there no smarter way ?

Has anyone worked around this problem in the CircleCI pre-build Docker images? I can use --no-sandbox but would prefer a proper fix.

Maybe it can help someone , but for me on debian 9 I had to enable namespace in kernel : Enable user namespaces in Debian kernel echo 1 > /proc/sys/kernel/unprivileged_userns_clone

Just add this to your Dockerfile

RUN apt-get update && apt-get install -y chromium-browser

ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true

This will install Chromium with all the necessary dependencies and then we let Puppeteer know that it doesn’t need to re-download Chromium.

Then in your code, launch Puppeteer like so

puppeteer.launch({executablePath: '/usr/bin/chromium-browser'})

@mrbar42 for president!!

If it helps, I followed the advice found in the URL given in the error message (https://chromium.googlesource.com/chromium/src/+/master/docs/linux_suid_sandbox_development.md) and changed the file “chrome_sandbox” so that it was owned by root and had setuid set. Now the sandbox error is gone and chrome launches. To summarize:

chown root:root chrome_sandbox
chmod 4755 chrome_sandbox
setenv CHROME_DEVEL_SANDBOX <path>/node_modules/puppeteer/.local-chromium/linux-555668/chrome-linux/chrome_sandbox
# Or use export CHROME_DEVEL_SANDBOX=... if bash

Why is @coldner’s comment not in the docs? Thanks

For CentOS 7.4, kernel 3.10.0-693.5.2 (I’m running on VirtualBox):

yum install pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64 libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXtst.x86_64 cups-libs.x86_64 libXScrnSaver-1.2.2-6.1.el7.x86_64 libXrandr.x86_64 GConf2 alsa-lib.x86_64 atk.x86_64 gtk3.x86_64 -y

yum install ipa-gothic-fonts xorg-x11-fonts-100dpi xorg-x11-fonts-75dpi xorg-x11-utils xorg-x11-fonts-cyrillic xorg-x11-fonts-Type1 xorg-x11-fonts-misc -y

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

Is this still the recommended solution as a lib author where I can’t control the actual Linux setup of my clients?

No, this would be wrong and a security risk. The proper solution is to enable the sandboxing in your OS:

Run echo 1 > /proc/sys/kernel/unprivileged_userns_clone as root and add kernel.unprivileged_userns_clone=1 to /etc/sysctl.conf. This works on debian, may be different on other distributions.

We really need this documentation for required options to run added to the README in an “Ubuntu/Debian/Linux” section:

await puppeteer.launch({
  args: ['--no-sandbox', '--disable-setuid-sandbox']
})

I anticipate a lot of users don’t know to search GitHub issues for this issue, therefore can’t find this thread, and are then not using this package because “it doesn’t work”.

Edit: I didn’t even see https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#chrome-headless-fails-due-to-sandbox-issues at first despite it being in the warning error message:

  Error {
    message: `Failed to launch chrome!␊
    /var/www/foobar/source/node_modules/puppeteer/.local-chromium/linux-499413/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory␊
    ␊
    ␊
    TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md␊
    `,
  }

I think putting this in the Install section would be appropriate to prevent people from wasting so much time here with this.

Edit: These options didn’t work, see my comment below https://github.com/GoogleChrome/puppeteer/issues/290#issuecomment-335793154

doesn’t seem to work on nixos even with all the solutions above. dumpio shows no output 😦

@jasondonnette I just got it running on Heroku an hour ago or so.

I used the google chrome buildpack even though it downloads Chrome in addition to just installing the dependencies. It’s probably a little more bloat than the absolute bare minimum (since puppeteer downloads it’s own chromium…) but it works without any extra effort on my part.

EDIT: I am using the two flags also…

await puppeteer.launch({
  args: ['--no-sandbox', '--disable-setuid-sandbox']
})

Don’t use untrusted, prebuilt binaries. Use the trusted package from your distro: https://packages.debian.org/stretch/chromium

Install it and then you can run chromium --headless. Puppeteer should also use it instead of bloating your home directory.

I think in the case of Debian systems you still need https://packages.debian.org/sid/libx11-xcb1 to run headless. That way the system has some of the API calls it needs to to do the rendering calculations.

for the dockerisers amongst us - i’ve launched successfully with this setup:

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

RUN npm i puppeteer

RUN echo "\
const puppeteer = require('puppeteer');\n\
(async () => {\n\
  const browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});\n\
  const page = await browser.newPage();\n\
  await page.goto('https://example.com');\n\
  await page.screenshot({path: 'example.png'});\n\
  browser.close();\n\
})();\
" > index.js

CMD ["node", "index.js"]

This worked even for node 14.17. Thank you so much for the help @mrbar42 . This did not, however, work for node 16.8

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

Hi, when I try to run it, in my debian, I have this:

[1003/225046.733084:ERROR:bus.cc(393)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory

DevTools listening on ws://127.0.0.1:45019/devtools/browser/e1e75c8d-c24a-454e-b4ca-83b1fdb42941

Do you have any idea on how to solve it?

Thank you

@AtiqGauri I have also got some shared library missing error on CI. Installing all fonts, libraries explicitly helped resolve the issue.

I have used this as a reference.

https://github.com/puppeteer/puppeteer/blob/main/.ci/node10/Dockerfile.linux

Hey @earshinov sorry I left that out on accident. I already tried that with sudo apt-get install libgbm and got this same response:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package libgbm

I’ve managed to get libx11 installed on Ubuntu 18 via Docker but for some reason Puppeteer doesn’t seem to be utilizing it. When I initialize my node app do I need to run it within x11 or is it sufficient to just install the live and run the node app that’s depending on Puppeteer?

Also I have no-sandbox enabled. Matter of fact these are the arguments I’m passing in:

    '--no-sandbox',
    '--disable-setuid-sandbox',
    '--disable-gpu',
    `--window-size=${resolution[0]}x${resolution[1]}`,
    `--user-agent=${agent}`

Anyone have a similar issue? PS I’m running this on a microdevice (Odroid XU-4 which has no video out ability).

@dkommineni Yes, I have the issue resolved.

Basically you are missing dependencies when you are using CF. Then you will face a second issue once you install the dependencies. That issue is that Puppeteer needs to be ran with options passed to it.

There is a solution you could use if you have control over the CF environment you are deploying to. I was deploying to a large company and did not have control.

If you have control, you could install the missing dependencies into your CF environment with this,

https://github.com/cloudfoundry/apt-buildpack

If you are like me and do not have control, you can take 3 steps to solve this issue.

  1. Put the project in a Docker image.

  2. Update the code to pass options to Puppeteer

  3. Deploy the Docker image to CF

You will find 100 examples of Dockerfiles on line and none of them worked for me. The way I finally got the Dockerfile right was using this,

FROM node:8
ENV HOST 0.0.0.0
EXPOSE 8080
RUN apt-get update

# for https
RUN apt-get install -yyq ca-certificates
# install libraries
RUN apt-get install -yyq libappindicator1 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 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
# tools
RUN apt-get install -yyq gconf-service lsb-release wget xdg-utils
# and fonts
RUN apt-get install -yyq fonts-liberation

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN mkdir -p /usr/src/app/views

# install the necessary packages
RUN npm install

CMD npm run start

You will need to make sure you update the Dockerfile to have the correct values for port, host and start command. That is up to you and your deployment.

The second thing I had to do was change puppeteer to launch like this,

const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'], ignoreHTTPSErrors: true, dumpio: false });

Originally I was launching it like this which will not work on Debian using the Dockerfile mentioned above,

const browser = await puppeteer.launch();

At that point I was able to create the Docker Image and test that Puppeteer was working on my localhost inside of the Docker Image. Once I could see that it was working, I deployed the Docker Image to CF and it worked like a charm on my first try.

This took me 3 or 4 days to figure out AFTER I had failed for a week to get it to work in CF without Docker. I truly hope this helps a ton of people.

i did this as a workaround ln -s /mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe node_modules/puppeteer/.local-chromium/linux-515411/chrome-linux/chrome to get it working on windows linux subsystem (wsl)

Hello there,

I’m still struggling in trying to make things work on Ubuntu 16.04 Server. I have installed all @coldner 's dependencies and here’s the result:

Running as root:

google-chrome --headless --dump-dom http://www.perdu.com/

[0313/102503.396335:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

google-chrome --headless --dump-dom --no-sandbox http://www.perdu.com/

[0313/102635.889632:ERROR:gpu_process_transport_factory.cc(1019)] Lost UI shared context. <html><head><title>Vous Etes Perdu ?</title></head><body><h1>Perdu sur l’Internet ?</h1><h2>Pas de panique, on va vous aider</h2><strong><pre> * <----- vous êtes ici</pre></strong> </body></html>

Running as non-root:

google-chrome --headless --dump-dom http://www.perdu.com/

[0313/102832.114783:ERROR:gpu_process_transport_factory.cc(1019)] Lost UI shared context. <html><head></head><body></body></html>

google-chrome --headless --dump-dom --no-sandbox http://www.perdu.com/

[0313/102914.693612:ERROR:gpu_process_transport_factory.cc(1019)] Lost UI shared context. <html><head></head><body></body></html>


As you can see, it will only work as root, with the --no-sandbox flag. I have also tried with chromium-browser, same result.

Any ideas?

Thank you, Ben

@joelgriffith looks really interesting! Let us know when that goes out.

One word of caution are the Chrome logos on the site. Distorting, changing it’s orientation, etc. is technically against the brand trademark usage. The colored line versions are probably ok if you made those, but I’d be cautious about the altering the official logo.

It’s not a work around. Chrome requires these things to operate. The API calls to them still need to be made even to emulate the environment.

thanks, it work perfectly @girishpatil

Same on Debian GNU/Linux 8. node.js v6.11.2 Works without sandbox…

@Garbee that list of dependencies wasn’t sufficient. It was missing libcairo-gobject2 at the very least.

Adding libcairo-gobject2 to the list may have solved it, but I found the buildpack to be a more palatable solution that required less configuration on my end.

https://github.com/GoogleChrome/puppeteer/issues/390 same ubuntu 16.04 DO VPS

Now using node v7.10.1 (npm v4.2.0)

@AndrewBarba You’re missing a dependency there.

/pipeline/source/node_modules/puppeteer/.local-chromium/linux-494755/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory

Please reference the full list I posted earlier and make sure they are installed.


Also, do not disable the sandbox. Do not disable the sandbox. We need to debug why things are happening with the sandbox and address those via documentation so you have a secure system to run tests on. Disabling the sandbox will leave your applications vulnerable to exploit the host machines if any malicious code ever makes it inside of them.