puppeteer: Headful mode doesn't launch (Unable to open X display.)

"version": "2.1.1"
Distributor ID: Debian
Description:    Debian GNU/Linux 9.11 (stretch)
Release:        9.11
Codename:       stretch

$ node -v
v12.14.1

Steps to reproduce

$ mkdir test && cd test && npm install puppeteer

> puppeteer@2.1.1 install /home/dun/_workspace/test/node_modules/puppeteer
> node install.js

Downloading Chromium r722234 - 121.1 Mb [====================] 100% 0.0s
Chromium downloaded to /home/dun/_workspace/test/node_modules/puppeteer/.local-chromium/linux-722234
npm WARN saveError ENOENT: no such file or directory, open '/home/dun/_workspace/test/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/dun/_workspace/test/package.json'
npm WARN test No description
npm WARN test No repository field.
npm WARN test No README data
npm WARN test No license field.

+ puppeteer@2.1.1
added 43 packages from 24 contributors and audited 51 packages in 13.217s

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities

$ touch test.js && echo "const puppeteer = require('puppeteer');
>
> (async () => {
>     const browser = await puppeteer.launch({
>         headless: false,
>         args: ['--no-sandbox']
>     });
> })();" >> test.js

$ node test.js
(node:24628) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
Fontconfig warning: "/etc/fonts/fonts.conf", line 100: unknown element "blank"
[24639:24639:0219/092954.631392:ERROR:browser_main_loop.cc(1512)] Unable to open X display.
[0219/092954.642321:ERROR:nacl_helper_linux.cc(308)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly


TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md

    at onClose (/home/dun/_workspace/test/node_modules/puppeteer/lib/Launcher.js:750:14)
    at Interface.<anonymous> (/home/dun/_workspace/test/node_modules/puppeteer/lib/Launcher.js:739:50)
    at Interface.emit (events.js:228:7)
    at Interface.close (readline.js:402:8)
    at Socket.onend (readline.js:180:10)
    at Socket.emit (events.js:228:7)
    at endReadableNT (_stream_readable.js:1185:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
(node:24628) 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:24628) [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.

What is the expected result? Puppeteer should launch in headful mode.

What happens instead? Puppeteer throws error and exits.

I ran $ sudo apt install gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 l ibgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 li bx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libx ss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils and restarded my server but it didn’t help.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 15
  • Comments: 34

Commits related to this issue

Most upvoted comments

@dundunn Set headless to true 😃

@dundunn Set headless to true 😃

That would be counterproductive if I wanted to start puppeteer in headful mode wouldn’t it?

I’ve spent countless days searching the internet on a solution for this. Everyone with this issue (including me) is probably using Windows and possibly WSL2. Issue is a compatibility issue with WSL2. Not sure how to fix as I still have the issue.

Edit: Solution seems to be to setup an X Display like vcXsrv so that the linux subsystem (WSL2) has a monitor to display on. But making it work with WSL2 is still not clear as many tutorials online are based on WSL1. I tried many tutorials to setup vcXsrv with latest WSL2 but couldn’t get it to work. Alternatively, you can try running your script using a windows based terminal instead of wsl2.

+1 to https://github.com/puppeteer/puppeteer/issues/5429#issuecomment-633785854, seems to be a compatibility issue with WSL. Switching from running the code on the WSL to Windows Powershell solved it for me.

@kevin8988

Set headless to true 😃

Can’t believe I spent an hour on this :XD

what is the status on this one? EDIT: I also have the “Unable to open X display” problem. I am using Xubuntu 18 (Desktop version with display and stuff) but still get this error. Puppeteer version 3.1.0

my solution was to allow xhost from remote with the command “xhost +” before puppeteer ececution

On Wed, 30 Jun 2021, 18:46 Juveria Manzar, @.***> wrote:

I’m facing a similar error when I try to run Puppeteer locally via cron:

Error: Failed to launch the browser process! [6630:6630:0505/185507.905416:ERROR:browser_main_loop.cc(1485)] Unable to open X display.

TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md

at onClose (/home/vaibhav/projects/myproject/node_modules/puppeteer/lib/Launcher.js:615:20)
at ChildProcess.<anonymous> (/home/vaibhav/projects/myproject/node_modules/puppeteer/lib/Launcher.js:606:67)
at ChildProcess.emit (events.js:215:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)

script.js

How did you resolve?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/puppeteer/puppeteer/issues/5429#issuecomment-871566560, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABT7X5C3D53RQCQ6VDBYG3DTVNC5FANCNFSM4KXUQ6VQ .

Same issue here, I am not able to solve it

I set up a piece of code, so it won’t work:

env: { TZ: 'Europe/London', },

Normal operation after removal.

export $DISPLAY

Chrome launch options need to set as below.

args: [ '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-extensions-except=' + this.extensionPathBuildPath, '--load-extension=' + this.extensionPathBuildPath ]

Got it working following those steps with vcXsrv Windows X Server:

  • Install vcXsrv
    • Once installed, run the LaunchX shortcut on your desktop.
    • You will have a choice of four viewport options. Let’s choose ‘Multiple Windows’ for now and press Next.
    • “Start no client” and press Next.
    • Change the default options: uncheck NATIVE OPENGL and check the DISABLE ACCESS CONTROL box. That way you won’t see permission problems.
    • Before Finalizing, you can save your settings for later adjustments.

You will likely be asked if you want to allow VcXsrv to access your network, you will have to click on the ‘Public network’ option and allow it through Windows Firewall or whatever firewall you use.

Now, I think this is the most important instruction I found in Stackoverflow, in the best answer section:

The networking subsystem in WSL2 is different than the used in WSL1. You must consider the differences to access networking apps running on Windows and on Linux:

In WSL1, Linux uses the same IP addresses than the Windows host, then, you can access the applications using localhost or 127.0.0.1 In WSL2, Linux runs on a lightweight virtual machine and has a different IP address. To access networking apps running on the Windows Host you must use the Windows IP address. Checking the IP address of the Windows host There are many ways to determine the IP addresses in the Windows host. You may run the following commands in your WSL Linux: […]

So, the only configuration I had to do in this moment, was setting my local Windows IP with route.exe print. To do it, edit your ./bashrc adding these two lines:

export DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0`
export LIBGL_AWAYS_INDIRECT=1

After that, try running your Puppeteer script to see if it works. This was the only solution I found in two days, hope it helps someone else.

Best regards, Marcelo

maven users!

I added below dependencies in pom.xml

	<dependency>
		<groupId>org.seleniumhq.selenium</groupId>
		<artifactId>selenium-support</artifactId>
		<version>3.141.59</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
	<dependency>
		<groupId>org.seleniumhq.selenium</groupId>
		<artifactId>selenium-chrome-driver</artifactId>
		<version>3.141.59</version>
		<scope>main</scope>
	</dependency>
	<dependency>
		<groupId>org.seleniumhq.selenium</groupId>
		<artifactId>selenium-api</artifactId>
		<version>3.141.59</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
	<dependency>
		<groupId>com.google.guava</groupId>
		<artifactId>guava</artifactId>
		<version>25.0-jre</version>
	</dependency>

and removed below in my webdriver setup file:

options.setHeadless(true); options.setAcceptInsecureCerts(true);

but, I passed these arguments as below then, options.addArguments(“–headless”);

This above error (Unable to open X display) was gone! However, I have new error as “NoClassDefFoundError: org/openqa/selenium/virtualauthenticator/HasVirtualAuthenticator”. Good luck!