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

Chrome Headless doesn't launch on Debian #290

Closed
fortes opened this issue Aug 16, 2017 · 199 comments
Closed

Chrome Headless doesn't launch on Debian #290

fortes opened this issue Aug 16, 2017 · 199 comments
Labels

Comments

@fortes
Copy link

fortes commented Aug 16, 2017

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"
  }
}
@Garbee
Copy link
Contributor

Garbee commented Aug 16, 2017

This is working fine here on Elementary OS. I'm downloading a Debian installer now to try this out in a VM.

@aslushnikov
Copy link
Contributor

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

@fortes
Copy link
Author

fortes commented Aug 16, 2017

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?

@Garbee
Copy link
Contributor

Garbee commented Aug 16, 2017

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.

@Garbee
Copy link
Contributor

Garbee commented Aug 16, 2017

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

@fortes
Copy link
Author

fortes commented Aug 16, 2017

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.

@aslushnikov
Copy link
Contributor

@fortes so do dependencies from #290 (comment) help?

@fortes
Copy link
Author

fortes commented Aug 16, 2017

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.

@Garbee
Copy link
Contributor

Garbee commented Aug 16, 2017

Check the sandbox docs linked to in that error and see if they can help you get it working. Either the security sandbox is messed up on Debian right now or something funky is happening to trigger it to need a non-kernel one. I'm looking into this once this VM server gets installed.

@aslushnikov
Copy link
Contributor

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

@paulirish
Copy link
Contributor

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.

@Garbee
Copy link
Contributor

Garbee commented Aug 16, 2017

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.

@aslushnikov aslushnikov changed the title Unhandled Promise Rejection Chrome Headless doesn't launch on Debian Aug 16, 2017
@fortes
Copy link
Author

fortes commented Aug 16, 2017

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

@Garbee
Copy link
Contributor

Garbee commented Aug 16, 2017

Just as a quick update, I'm like 20-40ish minutes out from starting on testing the install procedure. Downloading packages now for a fresh net install of Debian 9. So, I should get back to you shortly with exact steps to reproduce. It just won't be as fast as something that doesn't require a full OS install. 😄

@fortes
Copy link
Author

fortes commented Aug 16, 2017

Thanks for going through effort @Garbee! Will you be testing a headless Debian install, or using via ssh?

@Garbee
Copy link
Contributor

Garbee commented Aug 16, 2017

SSH is not relevant to the problem. Only a Debian server without any X/wayland system pre-installed (like any remote web server) will be enough to fully recreate the problem and steps to reproduce. So, that's what I'll be working with locally in a VM.

@maxschmeling
Copy link

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

@Garbee
Copy link
Contributor

Garbee commented Aug 16, 2017

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

@maxschmeling
Copy link

@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.

@Garbee
Copy link
Contributor

Garbee commented Aug 16, 2017

@fortes Are you running this as root by chance?

@Garbee
Copy link
Contributor

Garbee commented Aug 16, 2017

If you're running as root (after having all the required deps installed as listed earlier) you need to run without a sandbox since Chromium requires that (no clue why exactly yet.) If running as a normal user, then it should run just fine on a fresh debian install with the required dependencies.

@fortes
Copy link
Author

fortes commented Aug 16, 2017

Not running as root

@Garbee
Copy link
Contributor

Garbee commented Aug 16, 2017

That's interesting. I setup a fresh Linode box on Debian 9. Installed the packages listed above, then setup nodesource to install node 8. Then the yarn repository. New folder, yarn add puppeteer and then created the index.js and ran it. Everything works perfectly fine without a sandbox error.

Is the box you're running on under you complete control or is it someone else's like a VPS/shared host? If it is a remote host could you share the provider so I can look into if they do anything funny with their kernel configurations.

@Garbee
Copy link
Contributor

Garbee commented Aug 16, 2017

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.

@Garbee
Copy link
Contributor

Garbee commented Aug 16, 2017

@fortes If you could, please try running this script on your server to see if you have user namespacing enabled. https://gist.githubusercontent.com/Garbee/dfd33ba0a62f1cbc023b8d57de18efca/raw/f82ed513014062554a3536980a67390b57f1f858/user-namespace-check-linux.sh

@mrbar42
Copy link

mrbar42 commented Aug 16, 2017

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"]

@Garbee
Copy link
Contributor

Garbee commented Aug 16, 2017

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.

@aymather
Copy link

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!

@rigwild
Copy link

rigwild commented Apr 26, 2020

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.

@ndurner
Copy link

ndurner commented Jun 1, 2020

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

@AtiqGauri
Copy link

Getting this error:

error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory

electron 9.1.0
node js 12.x
electron builder 22.7.0

I have tried all the option mentioned above...
Sand boxing and installing libraries nothing seems to work

My app works perfectly in dev mode and even on x64 build
This error pops only after build for ia32...

@deepaktatineni
Copy link

@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

@aborruso
Copy link

aborruso commented Oct 4, 2020

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

@Kvintus
Copy link

Kvintus commented Nov 28, 2020

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 !

jonhaddow pushed a commit to jonhaddow/read-it that referenced this issue Jan 5, 2021
nitinthewiz pushed a commit to nitinthewiz/puppetcam that referenced this issue Mar 4, 2021
A few issues show up -
1. Chrome's security notifications show up, and need to be resolved.
    Possible solutions -
    - puppeteer/puppeteer#290
    - https://github.com/Zenika/alpine-chrome#-the-best-with-seccomp
    - https://security.stackexchange.com/questions/219577/how-to-securely-run-puppeteer-chromium-in-a-docker-container
    - https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#setting-up-chrome-linux-sandbox

2. The choppiness still remains. This is a major problem. This tells me that it's possibly either Chrome-on-Linux or ffmpeg based screencasting, which is broken. Either ways, no point trying to fix this.

3. Color schema was fine, but getting high quality was a pain. This is a problem, though solved.
@mraxus
Copy link

mraxus commented Sep 2, 2021

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

@demmorou
Copy link

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.

works for me

ikidd added a commit to ikidd/invoice-ninja that referenced this issue Dec 20, 2022
As per discussion:

puppeteer/puppeteer#290

snappdf needs to use headless chrome which has dependencies not satisfied in the current build.
@JhulerCode
Copy link

/app/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:241
Error: Failed to launch the browser process!
/app/node_modules/puppeteer/.local-chromium/linux-982053/chrome-linux/chrome: error while loading shared libraries: libgobject-2.0.so.0: cannot open shared object file: No such file or directory
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

@gestj
Copy link

gestj commented Apr 20, 2023

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

Any update on this?

I just got this by myself ... (I start from a python slim image)

@juanpablo64
Copy link

on debian 8.5 I get this error: TimeoutError: Timed out after 30000 ms while waiting for the WS endpoint URL to appear in stdout!

when executing chromium 57 that has been installed with apt install.

When using the chromium inside puppeteer, I get this error:

error while loading shared libraries: libatk-2.0 cannot open shared object file: No such file or directory

@Rah1x
Copy link

Rah1x commented May 22, 2023

any updates on this? cant get pass this

@sharafat
Copy link

on debian 8.5 I get this error: TimeoutError: Timed out after 30000 ms while waiting for the WS endpoint URL to appear in stdout!

when executing chromium 57 that has been installed with apt install.

When using the chromium inside puppeteer, I get this error:

error while loading shared libraries: libatk-2.0 cannot open shared object file: No such file or directory

I'm getting the same error sometimes on AWS lambda: Timed out after 30000 ms while waiting for the WS endpoint URL to appear in stdout!. Looks like a new issue. Using Puppeteer v20.7.2 with Chrome v114.0.0. Any help would be greatly appreciated!

psibre added a commit to psibre/puppeteer that referenced this issue May 6, 2024
psibre added a commit to psibre/puppeteer that referenced this issue May 6, 2024
OrKoN pushed a commit to psibre/puppeteer that referenced this issue May 6, 2024
@Strooss
Copy link

Strooss commented Jun 17, 2024

Im getting

Error: Failed to launch the browser process!
/root/bot/node_modules/puppeteer/.local-chromium/linux-1036745/chrome-linux/chrome: error while loading shared libraries: libcups.so.2: cannot open shared object file: No such file or directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests