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

Most upvoted comments

image

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-xcb1 Then run the following command Xvfb -ac :99 -screen 0 1280x1024x16 & export DISPLAY=:99

this worked for me

@InanisV @jnalbert @vvolodin Solution for me which worked on Debian 11, first find the display variable with printenv DISPLAY on the terminal session which open on RDP or whatever … It works!

I am on Ubuntu 22.04 and the chromium can launch in the rdp session via rdp terminal, or via remote ssh with DISPLAY set 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 using

puppeteer.launch(
    ...,
    env: {
        ...,
        DISPLAY: ":10.0"
    }
)

solved 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 DISPLAY on the terminal session which open on RDP or whatever, it was like that for me:

luc1d@luc1dx:~/Desktop$ printenv DISPLAY
:10.0

then put that into your crontab code as,

export DISPLAY=$HOST_IP:10.0 && /usr/bin/google-chrome

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 xvfb Dependencies to make “headless” chrome/selenium work:

sudo apt-get -y install xorg xvfb gtk2-engines-pixbuf sudo apt-get -y install dbus-x11 xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic xfonts-scalable Optional but nifty: For capturing screenshots of Xvfb display:

sudo apt-get -y install imagemagick x11-apps Make sure that Xvfb starts every time the box/vm is booted:

Xvfb -ac :99 -screen 0 1280x1024x16 & export DISPLAY=:99 Run Google Chrome

google-chrome

Are you all running in headless mode 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.

Error: Failed to launch the browser process!
[67:67:0727/113208.603833:ERROR:ozone_platform_x11.cc(247)] Missing X server or $DISPLAY
[67:67:0727/113208.603871:ERROR:env.cc(226)] The platform failed to initialize.  Exiting.


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

    at onClose (/app/ts-helpers/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:289:20)
    at ChildProcess.<anonymous> (/app/ts-helpers/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:280:24)
    at ChildProcess.emit (node:events:525:35)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12)

@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

image image

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-chrome into 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

const pptrConf = {
    executablePath,
    headless,
    defaultViewport: null, // ensure Puppeteer doesn't override your viewport settings
    args: [
      '--start-maximized', // this flag maximizes the browser window
      `--display=${process.env.DISPLAY ?? ':0'}` // fix for LXDE desktops
    ],
    ignoreDefaultArgs: ['--enable-automation'] // remove "Chrome is being controlled by automated test software"
  };
  const browser = await lib.puppeteer.launch(pptrConf).catch(err => echo.error(err));

Development mode Install xvfb apt-get install xvfb x11-apps x11-xkb-utils libx11-6 libx11-xcb1 Then run the following command Xvfb -ac :99 -screen 0 1280x1024x16 & export DISPLAY=:99

this worked for me

thanks worked, i’m running it on node.js using command xvfb-run --auto-servernum node index.js

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

# project/docker-compose.yml
version: '3.8'
services:
  puppeteer:
    image: ghcr.io/puppeteer/puppeteer:latest
    # the exact image for working example
    # image: ghcr.io/puppeteer/puppeteer@sha256:a244c6196f0e59de79a2c109d9830dc75a8b133cbdcf4a1f25e69c1e0825ff20
    volumes:
      - ./test.js:/home/pptruser/test.js
    command: "node test.js"

They key was to launch the browser with --no-sandbox headless: true and using google-chrome-stable. Here is a working example ran using: docker compose run puppeteer:

// project/test.js
const puppeteer = require("puppeteer");

(async () => {
    const browser = await puppeteer.launch({
        args: ["--no-sandbox"],
        headless: true,
        executablePath: "/usr/bin/google-chrome-stable",
    });
    const page = await browser.newPage();
    await page.goto("https://www.google.com");
    const logoUrl = await page.evaluate(() => document.querySelector(".lnXdpd").src);
    console.log(logoUrl);
    await browser.close();
})();

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.

env: {
  DISPLAY : ":0.0"
},

Now running from my remote shell & it works fine ! thanks @rainb3rry @mkmark

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

how can i upvote this answer with recursion that have no limit?

export DISPLAY=:1 && /usr/bin/google-chrome works 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:

Xvfb -ac :99 -screen 0 1280x1024x16 & export DISPLAY=:99 && /root/.nvm/versions/node/v20.1.0/bin/node /home/user/script.js

                         [1] 40812
(EE)
Fatal server error:
(EE) Server is already active for display 99
        If this server is no longer running, remove /tmp/.X99-lock
        and start again.
(EE)
/home/roman/node_modules/@puppeteer/browsers/lib/cjs/launch.js:262
                reject(new Error([
                       ^

Error: Failed to launch the browser process! undefined
Maximum number of clients reached[40824:40824:0531/204715.097597:ERROR:ozone_platform_x11.cc(239)] Missing X server or $DISPLAY
[40824:40824:0531/204715.097638:ERROR:env.cc(255)] The platform failed to initialize.  Exiting.

TROUBLESHOOTING: https://pptr.dev/troubleshooting

    at ChildProcess.onClose (/home/roman/node_modules/@puppeteer/browsers/lib/cjs/launch.js:262:24)
    at ChildProcess.emit (node:events:523:35)
    at ChildProcess._handle.onexit (node:internal/child_process:293:12)

Node.js v20.1.0

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