puppeteer: [Bug]: Missing X server or $DISPLAY
Bug description
Steps to reproduce the problem:
I am running crawlsite.js function from puppeteer/examples/crawlsite.js path in their git repo and i am seeing the exact same issue - [186875:186875:0318/202225.133327:ERROR:ozone_platform_x11.cc(234)] Missing X server or $DISPLAY [186875:186875:0318/202225.133388:ERROR:env.cc(225)] The platform failed to initialize. Exiting.
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md[](https://github.com/pankhiprasher)
at onClose (/root/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:237:20) at Interface.<anonymous> (/root/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:227:68) at Interface.emit (node:events:539:35) at Interface.close (node:internal/readline/interface:529:10) at Socket.onend (node:internal/readline/interface:258:10) at Socket.emit (node:events:539:35) at endReadableNT (node:internal/streams/readable:1342:12) at processTicksAndRejections (node:internal/process/task_queues:83:21) I dont know why it works in headless true but as soon as i change it to headless false it doesnt launch chrome browser and gives this error. Can anyone please help?
Puppeteer version
13.5.2
Node.js version
17.0.0
npm version
8.5.2
What operating system are you seeing the problem on?
Linux
Relevant log output
I am running crawlsite.js function from puppeteer/examples/crawlsite.js path in their git repo and i am seeing the exact same issue -
[186875:186875:0318/202225.133327:ERROR:ozone_platform_x11.cc(234)] Missing X server or $DISPLAY
[186875:186875:0318/202225.133388:ERROR:env.cc(225)] The platform failed to initialize. Exiting.
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
at onClose (/root/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:237:20)
at Interface.<anonymous> (/root/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:227:68)
at Interface.emit (node:events:539:35)
at Interface.close (node:internal/readline/interface:529:10)
at Socket.onend (node:internal/readline/interface:258:10)
at Socket.emit (node:events:539:35)
at endReadableNT (node:internal/streams/readable:1342:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
I dont know why it works in headless true but as soon as i change it to headless false it doesnt launch chrome browser and gives this error.
Can anyone please help?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 17
- Comments: 62
Still happening
We’re marking this issue as unconfirmed because it has not had recent activity and we weren’t able to confirm it yet. It will be closed if no further activity occurs within the next 30 days.
Development mode Install xvfb
apt-get install xvfb x11-apps x11-xkb-utils libx11-6 libx11-xcb1Then run the following commandXvfb -ac :99 -screen 0 1280x1024x16 & export DISPLAY=:99this worked for me
I am on Ubuntu 22.04 and the chromium can launch in the rdp session via rdp terminal, or via remote ssh with
DISPLAYset to:10.0. But puppeteer gives the error nonetheless on both occasions. It seems it is launching the chrome/chromium in a different way.Later I noticed
env?: Record<string, string | undefined>;so usingsolved my problem
Are you running this remotely or in a VM where there isn’t a display to view? This issue usually occurs when chromium is trying to launch a GUI but doesn’t have a display to hook into. In Linux, you can usually remediate this issue with software like
xvfb.Same here…got it working on my Windows machine … doesn’t work on Linux (Debian 10) Following…
@InanisV @jnalbert @vvolodin Solution for me which worked on Debian 11, first find the display variable with
printenv DISPLAYon the terminal session which open on RDP or whatever, it was like that for me:then put that into your
crontabcode as,It works!
export XAUTHORITY=$HOME/.Xauthority && chromium-browser
This worked for me, I did it like crazy, xd I was already desperate and it worked
Install Xvfb if you didn’t install it yet and do the following steps.
sudo apt-get install -y xvfbDependencies to make “headless” chrome/selenium work:sudo apt-get -y install xorg xvfb gtk2-engines-pixbufsudo apt-get -y install dbus-x11 xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic xfonts-scalableOptional but nifty: For capturing screenshots of Xvfb display:sudo apt-get -y install imagemagick x11-appsMake sure that Xvfb starts every time the box/vm is booted:Xvfb -ac :99 -screen 0 1280x1024x16 &export DISPLAY=:99Run Google Chromegoogle-chrome
Are you all running in
headlessmode on the VM?I got this error when I forgot to set:
puppeteer.launch({ headless: true })I had same issue while using $code . in ubuntu 18.04.6 I having local machine problem not in remote server. I have solved by just changing DISPLAY variable in .bashrc Try this steps, 1.vim ~/.bashrc 2.edit using “i” 3.change value in line “export DISPLAY=$(some_value)” to “export DISPLAY=:0” 4.source ~/.bashrc
Hope this will help somebody.
Can someone state definitively whether puppeteer is designed to be used on a machine that does not have any sort of display software (such as X) or display (AKA a headless machine)?
I’m having the same issue running on Ubuntu 20.04 in docker via xfvb, I have a $DISPLAY set.
@OrKoN I saw you closed both #8148 and 7743
Is there no explanation why this will not get fixed? it is obvious that many people run into this issue and the majority is not really able to solve it.
Would you be so kind and elaborate what we should do now?
THX!
Im using Arch in Wsl2 and I’m getting the same error (installing with yay -S chromium): ❯ chromium [3335:3335:1025/005623.218894:ERROR:ozone_platform_x11.cc(244)] Missing X server or $DISPLAY [3335:3335:1025/005623.219001:ERROR:env.cc(258)] The platform failed to initialize. Exiting.
I found this --ozone-platform param that It permit me to open chromium. And my $DISPLAY = :0
chromium --ozone-platform=wayland
If u having the same error yet try to change the param: chromium --ozone-platform=headless chromium --ozone-platform=wayland chromium --ozone-platform=x11
@pankhiprasher I think you have to set headlees to true
const browser = await puppeteer.launch({ args: ['--no-sandbox'], headless: true, // !! true executablePath: '/usr/bin/chromium-browser', });I was able to partially resolve this issue using VcXsrv Windows X Server, and with the help of this guide, and this answer.
I say “partially” as the terminal is still throwing up a bunch of errors for files and tags not found. But as far as I can tell everything is working correctly i.e. now when I enter
google-chromeinto my WSL Ubuntu terminal, it launches and works just fine.Hope this helps 😃
(For reference, I’m running Ubuntu through WSL2 on Windows 11)
I’m here because of an unrelated framework giving me the exact same error. I’m running Ubuntu 18 in WSL on Windows 10.
I solved with
--display=${process.env.DISPLAY ?? ':0'}in
thanks worked, i’m running it on node.js using command
xvfb-run --auto-servernum node index.jsI was getting different errors trying to run on WSL2 Ubuntu 22.04 in Docker, including this one. Fortunately managed to get it running. Hope someone will find it helpful as I spent waaay to much time trying to get chrome running in docker.
They key was to launch the browser with
--no-sandboxheadless: trueand usinggoogle-chrome-stable. Here is a working example ran using:docker compose run puppeteer:I solved this with this link: https://pptr.dev/guides/headless-modes
using:
const browser = await puppeteer.launch({headless: 'shell'});I’m working with nodejs 20 and red hat 8, I don’t use any GUI, just needed to create a file and read it to get the base64 code.
Had this issue on Ubuntu server 22.04 but on remote shell. I tried to launch browser with headless mode false (so would have a GUI) . But there is no $DISPLAY on remote shell.
So getting $DISPLAY value from host terminal and applied it to my puppeteer config.
Now running from my remote shell & it works fine ! thanks @rainb3rry @mkmark
how can i upvote this answer with recursion that have no limit?
export DISPLAY=:1 && /usr/bin/google-chromeworks for me on Ubuntu 22.04.1 LTS@BioPhoton Unfortunately, it’s not something that can be fixed in Puppeteer. A headful browser requires an x server or a display: see for various solutions depending on a operating system/docker etc https://stackoverflow.com/questions/60304251/unable-to-open-x-display-when-trying-to-run-google-chrome-on-centos-rhel-7-5
The issue also affects a whole range of programs not just chrome: see https://www.baeldung.com/linux/no-x11-display-error
For anyone who still having this issue on linux desktop environments and wan’t to use without headless mode (I’m using ubuntu 24 desktop as non-remote desktop environment), check if your desktop uses wayland. Switching from wayland to xorg was in my case the solution.
I use this tip and I can run 37 scripts with Puppeteer. But when I run 38 script, I see:
Why?
Encountered this today on WSL2 and the issue was that I had multiple instances of VcXsrv running. Closed them all, started from the top and hey presto <google-chrome> opened the browser. I followed this article to get set up initially: https://www.gregbrisebois.com/posts/chromedriver-in-wsl2/
Hope that might help someone