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

[Bug]: Missing X server or $DISPLAY #8148

Closed
pankhiprasher opened this issue Mar 18, 2022 · 57 comments
Closed

[Bug]: Missing X server or $DISPLAY #8148

pankhiprasher opened this issue Mar 18, 2022 · 57 comments
Labels

Comments

@pankhiprasher
Copy link

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. (/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?
@pankhiprasher pankhiprasher changed the title [Bug]: [Bug]: Missing X server or $DISPLAY Mar 18, 2022
@kzenman
Copy link

kzenman commented Mar 19, 2022

Same here...got it working on my Windows machine ... doesn't work on Linux (Debian 10)
Following...

@pankhiprasher
Copy link
Author

@kzenman i tried doing that directly onmy windows but i keep getting a lot of error on my windows terminal when i try installing some missing modules required for functions by doing npm install del . how do we fix that and then go over running node example.js command properly? Thanks

@StackedQueries
Copy link

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.

@stale
Copy link

stale bot commented Jun 23, 2022

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.

@stale stale bot added the unconfirmed label Jun 23, 2022
@AlexRudyak
Copy link

image

Still happening

@abhiatmsit
Copy link

I am Having similar issue

vagrant@ubuntu-xenial:/robot$ google-chrome
[13014:13014:0713/051548.616150:ERROR:ozone_platform_x11.cc(247)] Missing X server or $DISPLAY
[13014:13014:0713/051548.616386:ERROR:env.cc(226)] The platform failed to initialize. Exiting.
vagrant@ubuntu-xenial:
/robot$

vagrant@ubuntu-xenial:/robot$ uname -r
4.4.0-210-generic
vagrant@ubuntu-xenial:
/robot$

@stale stale bot removed the unconfirmed label Jul 13, 2022
@ronpicard
Copy link

Same issue here

[3036:3036:0715/115626.763202:ERROR:ozone_platform_x11.cc(247)] Missing X server or $DISPLAY
[3036:3036:0715/115626.763438:ERROR:env.cc(226)] The platform failed to initialize. Exiting.

@Plorax
Copy link

Plorax commented Jul 17, 2022

I'm here because of an unrelated framework giving me the exact same error. I'm running Ubuntu 18 in WSL on Windows 10.

@Plorax
Copy link

Plorax commented Jul 17, 2022

Check this out, this "Missing X server on $DISPLAY" was added back in 2018
https://groups.google.com/a/chromium.org/g/ozone-reviews/c/K8bdtY-A8E8/m/zNZry3XxBQAJ

@Plorax
Copy link

Plorax commented Jul 17, 2022

The $DISPLAY is an environment variable that should be set if there is an X display ? That is what I got so far. Maybe figuring out what to set it to is the answer.

@vincechapman
Copy link

vincechapman commented Jul 26, 2022

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)

@vvolodin
Copy link

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)

@jnalbert
Copy link

I have the same problem as @vvolodin trying to run xfvb in docker and i set the DISPLAY but it still threw an error

@InanisV
Copy link

InanisV commented Jul 29, 2022

Similar to @Plorax , I have the same problem mentioned in this issue. And the same as @jnalbert , after installing xfvb on my Ubuntu 18.04 virtual machine, it pops the problem ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.

@rainb3rry
Copy link

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

@mkmark
Copy link

mkmark commented Aug 5, 2022

@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

@Joshfindit
Copy link

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)?

@peterramaldes
Copy link

Same here 😢
image

@rainb3rry
Copy link

export DISPLAY=$HOST_IP:10.0 &&

have you tried by export DISPLAY=$HOST_IP:10.0 && chromium

@YoannBuzenet
Copy link

YoannBuzenet commented Sep 5, 2022

Same here with this Dockerfile :

The error :

pptruser@0de9a4a15e20:/usr/app$ google-chrome-stable
[15:15:0905/115256.763542:ERROR:ozone_platform_x11.cc(240)] Missing X server or $DISPLAY
[15:15:0905/115256.763571:ERROR:env.cc(255)] The platform failed to initialize.  Exiting.

The dockerFile :

FROM node:16-slim

# Update package informations, install wget and gnupg
RUN  apt-get update \
  && yes | DEBIAN_FRONTEND=noninteractive apt-get install ca-certificates dbus-x11 fonts-liberation gconf-service gtk2-engines-pixbuf libappindicator1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 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 lsb-release xorg xdg-utils xvfb \
  && apt-get install -y wget gnupg\
  && rm -rf /var/lib/apt/lists/*

# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
RUN apt-get update \
  && apt-get install -y wget gnupg \
  && 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-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-khmeros fonts-kacst fonts-freefont-ttf libxss1 \
  --no-install-recommends \
  && rm -rf /var/lib/apt/lists/*

# If running Docker >= 1.13.0 use docker run's --init arg to reap zombie processes, otherwise
# uncomment the following lines to have `dumb-init` as PID 1
# ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init
# RUN chmod +x /usr/local/bin/dumb-init
# ENTRYPOINT ["dumb-init", "--"]

# Uncomment to skip the chromium download when installing puppeteer. If you do,
# you'll need to launch puppeteer with:
#     browser.launch({executablePath: 'google-chrome-unstable'})
# ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true

# From node 15 we need to define WORKDIR before running npm install
WORKDIR /usr/app
COPY ./ ./

ENV DISPLAY=:0

# Install puppeteer so it's available in the container.
RUN npm init -y &&  \
  npm i puppeteer \
  # Add user so we don't need --no-sandbox.
  # same docker layer as npm install to keep re-chowned files from using up several hundred MBs more space
  && groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
  && mkdir -p /home/pptruser/Downloads \
  && chown -R pptruser:pptruser /home/pptruser \
  && chown -R pptruser:pptruser ./node_modules \
  && (node -e "require('child_process').execSync(require('puppeteer').executablePath() + ' --credits', {stdio: 'inherit'})" > THIRD_PARTY_NOTICES)

# Run everything after as non-privileged user.
USER pptruser

ENTRYPOINT ["google-chrome-stable"]

If I try
xvfb-run google-chrome --disable-gpu --no-sandbox --disable-setuid-sandbox

I get

[34:70:0905/122317.454518:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[34:70:0905/122317.454599:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[34:69:0905/122317.456252:ERROR:bus.cc(399)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[34:69:0905/122317.456268:ERROR:bus.cc(399)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[34:69:0905/122317.464422:ERROR:bus.cc(399)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[34:69:0905/122317.464447:ERROR:bus.cc(399)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[34:121:0905/122317.492726:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[34:121:0905/122317.492757:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[34:121:0905/122317.492792:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[34:121:0905/122317.492843:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[34:121:0905/122317.492872:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[77:77:0905/122317.494724:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported

@jlanssie
Copy link

jlanssie commented Sep 10, 2022

I experienced an issue in Azure Pipelines, where I could not run a headless Puppeteer:

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

I eventually fixed the issue by running Xvfb and sending Puppeteer's output to Xvfb.

My azure pipeline YAML:

trigger: none
pr: none

pool:
  vmImage: ubuntu-latest

variables:
  workingDir: 'MyDir'

jobs:
- job: 'my_job'
  displayName: 'My Job'
  steps:
  - task: NodeTool@0
    inputs:
      versionSpec: '18.x'
      checkLatest: true
    displayName: 'Install Node.js'

  - script: npm i puppeteer
    workingDirectory: '$(Build.SourcesDirectory)/$(workingDir)'
    displayName: 'Install Puppeteer'

  - script: |
      Xvfb :10 -ac &
    displayName: 'Set display'

  - script: node main.js 
    workingDirectory: '$(Build.SourcesDirectory)/$(workingDir)'
    displayName: 'My Task running Puppeteer'

In the forementioned script, it is this part that covers the correct execution of Puppeteer

  - script: |
      Xvfb :10 -ac &
    displayName: 'Set display'

I also had to the display parameter to my browser env variables in my Puppeteer script

const browser = await puppeteer.launch({ headless: false, dumpio: false, env: { DISPLAY: ":10"} });

The combination of Xvfb running in the background and Puppeteer outputting to the former's listening port, works for me.

@csaid4152
Copy link

I was having the same issue in kali trying to install and run google-chrome. I was getting the following error

[13014:13014:0713/051548.616150:ERROR:ozone_platform_x11.cc(247)] Missing X server or $DISPLAY
[13014:13014:0713/051548.616386:ERROR:env.cc(226)] The platform failed to initialize. Exiting.

Solution for me was to search google in kali, right click, edit application, check the box that say Run in Terminal.
Now in terminal run "google-chrome --no-sandbox" and boom it works. But it will give you an error if you run it without "--no-sandbox"

@AndrewPahomovOtto
Copy link

I got that issue in CI/CD.
I have it because I add local .env file to tests by mistakes.
TEST_URL in .env was localhost.
.env overrides GH action variables.
Remove local .env helped me

@smit-code
Copy link

@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

@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

It worked for me as well, thanks Man

@axelfran
Copy link

Are you all running in headless mode on the VM?

I got this error when I forgot to set:
puppeteer.launch({ headless: true })

@niettcat
Copy link

export DISPLAY=:1 && /usr/bin/google-chrome works for me on Ubuntu 22.04.1 LTS

@martsim6
Copy link

martsim6 commented Jan 5, 2023

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.

this helped me on ubuntu 22, using snap chromium. Thanks a lot!

@MarlonPassos-git
Copy link

MarlonPassos-git commented Jan 8, 2023

;

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

thanks very much. i remove the chrome and install following the steps of the site and it worked

the one problem of this, is that i need to start the xlauch.exe whenever i start

@Raff-dev
Copy link

Raff-dev commented Jan 15, 2023

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

@ElGalileo12
Copy link

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

@alxvallejo
Copy link

@ElGalileo12 Do you need to install this before installing chrome/chromium? If I run this after, I'm still getting the following:

# launching puppeteer with config {"args":["--no-sandbox","--disable-setuid-sandbox","--disable-dev-shm-usage","--disable-accelerated-2d-canvas","--no-first-run","--no-zygote","--single-process","--disable-gpu","--headless"],"headless":true,"devtools":false,"timeout":90000,"executablePath":"/usr/bin/chromium","dumpio":true}
[0124/141649.205536:ERROR:browser_main_loop.cc(536)] Failed to open an X11 connection.
[0124/141649.206620:ERROR:bus.cc(393)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[0124/141649.208294:WARNING:audio_manager_linux.cc(69)] Falling back to ALSA for audio output. PulseAudio is not available or could not be initialized.

DevTools listening on ws://127.0.0.1:38011/devtools/browser/e9e3e6a5-065a-472d-b4af-16a6d5961097

@Sevellion
Copy link

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

@PragathiKS
Copy link

Hi,

run below cmd to install google chrome -

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

facing same error on ubuntu, Any suggestions to solve the error.

ERROR:ozone_platform_x11.cc(238)] Missing X server or $DISPLAY
ERROR:env.cc(255)] The platform failed to initialize. Exiting.

@kingakidi
Copy link

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

@SumitMistry
Copy link

export DISPLAY=$HOST_IP:10.0 && chromium

I have still the similar issue:

`root@ubuntu-22:~/USvisa/US-visa-appointment-notifier# printenv DISPLAY
:0

root@ubuntu-22:~/USvisa/US-visa-appointment-notifier# export DISPLAY=$HOST_IP:0 && /usr/bin/google-chrome
bash: /usr/bin/google-chrome: No such file or directory

root@ubuntu-22:~/USvisa/US-visa-appointment-notifier# export DISPLAY=$HOST_IP:0 && /usr/bin/chromium-browser
mkdir: cannot create directory '/run/user/0': Permission denied
[36431:36431:0329/043944.667627:ERROR:zygote_host_impl_linux.cc(100)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

root@ubuntu-22:~/USvisa/US-visa-appointment-notifier# export DISPLAY=$HOST_IP:0 && /usr/bin/chromium-browser --no-sandbox
mkdir: cannot create directory '/run/user/0': Permission denied
Authorization required, but no authorization protocol specified
[36596:36596:0329/043955.352621:ERROR:ozone_platform_x11.cc(239)] Missing X server or $DISPLAY
[36596:36596:0329/043955.352668:ERROR:env.cc(255)] The platform failed to initialize. Exiting.`

@kevgithub
Copy link

kevgithub commented Mar 29, 2023

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.

@StackedQueries Thank you so much mate, you literally save my day. mua~

@svobora
Copy link

svobora commented Apr 3, 2023

export XAUTHORITY=$HOME/.Xauthority && chromium-browser

@BayoKwendo
Copy link

Was experiencing the same below code helped in solving the issue

            const executablePath: string = await new Promise(resolve => locateChrome((arg: any) => resolve(arg))) || '';

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

            });

@nitsik
Copy link

nitsik commented May 31, 2023

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?

@Stroik
Copy link

Stroik commented Jul 17, 2023

In my particular case, I'm using Ubuntu Desktop 22 and I was having this issue. The way that I solved it was adding

const pupOpts = {
        headless: false,
        executablePath: `${process.env.CHROME_PATH}`,
        env: {
          DISPLAY: ':0',
        },
        args: [
          '--no-sandbox',
          '--disable-setuid-sandbox',
          '--disable-dev-shm-usage',
          '--disable-accelerated-2d-canvas',
          '--no-first-run',
          '--no-zygote',
        ],
      }

I hope this help someone else

@StoryDevOffical
Copy link

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

@DiZiNnEs
Copy link

DiZiNnEs commented Oct 30, 2023

The Puppeteer documentation has a guide to running a specific file where there is a browser launch using Puppeteer, the Dockerfile itself

In my Dockerfile, I inherited the developers' docker image and started my own project:

FROM ghcr.io/puppeteer/puppeteer:latest

WORKDIR /home/pptruser

USER root
RUN apt-get update
COPY package.json .
COPY package-lock.json .
COPY tsconfig.json .
COPY src ./src
COPY index.ts .
COPY .env .
COPY fonts fonts/
COPY jest.config.ts .
COPY .prettierrc.json .

RUN npm ci
COPY .env ./dist/
COPY fonts ./dist/fonts/
RUN npm run build
COPY dist /app/dist
EXPOSE 8000

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

My puppeteer launch options for docker:

const browser = await puppeteer.launch({
      headless: true,
      args: ['--no-sandbox'],
      executablePath: '/usr/bin/google-chrome'
    });

And the work is good. You can also use headless: 'new' instead of headless: true but that doesn't work for me. See also troubleshooting

@kyrlon
Copy link

kyrlon commented Nov 9, 2023

export XAUTHORITY=$HOME/.Xauthority && chromium-browser

THIS worked for me! I am running Ubuntu20 on an Azure server. I have just chromium installed via snap so this is what I ran:

export XAUTHORITY=$HOME/.Xauthority && chromium

@dlopez525
Copy link

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

@paulweimer
Copy link

I was getting the same error on Github Actions and for me the problem was that in my karma.conf.js I was using "Chrome" in the browsers array.
So I changed it to browsers: ['ChromeHeadless'] and now it's working fine.

@Ismola
Copy link

Ismola commented May 24, 2024

I have achieved it.

I have done it. After having tried all the suggestions I found on the internet, follow this guide and see many error threads, I have achieved it by doing this:

NOT PUTTING ANY DISPLAY CONFIGURATION in the .bashrc

The idea came from here:

@pstaender
Copy link

pstaender commented May 28, 2024

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.

@Mike-Jagger
Copy link

Mike-Jagger commented Jun 7, 2024

I came across this issue when I was trying to use puppeteer in a Docker container. I tried a mix of the solutions here and came up with a not so pretty solution, but solution that works, at least for me.

Here is the Docker file:

# Use Ubuntu V22.04 image
FROM ubuntu:22.04

# Install necessary packages including Node.js, npm, xvfb, and other dependencies
RUN apt-get update && apt-get install -y \
    curl \
    gnupg \
    ca-certificates \
    apt-transport-https \
    software-properties-common \
    wget \
    dbus-x11 \
    xvfb \
    ffmpeg \
    xauth \
    vim-common \
    libnss3 \
    libxss1 \
    libpulse0 \
    libasound2 \
    libasound2-plugins \
    libatk1.0-0 \
    libatk-bridge2.0-0 \
    libcups2 \
    libdrm2 \
    libdbus-glib-1-2 \
    libgbm1 \
    libxkbcommon-x11-0 \
    libgtk-3-0 \
    && curl -sL https://deb.nodesource.com/setup_18.x | bash - \
    && apt-get install -y nodejs \
    && curl --location --silent 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-stable --no-install-recommends \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Create and change to the app directory
WORKDIR /usr/src/app

# Copy application dependency manifests to the container image
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy local code to the container image
COPY . .

# Set environment variables
ENV DISPLAY=:99
ENV XAUTHORITY=/root/.Xauthority
# ... other environment variables

# Expose the port
EXPOSE 8080

# Copy the startup script to the container
COPY startup.sh /usr/src/app/startup.sh

# Make the startup script executable
RUN chmod +x /usr/src/app/startup.sh

# Run the web service on container startup
CMD ["/usr/src/app/startup.sh"]

Here is the startup shell script that is used to write the Xauthority file to authorize connection to the :99 display, and also setup the Xvfb server:

#!/bin/bash

# Start Xvfb
Xvfb :99 -screen 0 1920x1080x24 &

# Wait for Xvfb to start
sleep 2

# Set the DISPLAY environment variable (redundant but just to make sure)
export DISPLAY=:99

# Generate a .Xauthority file
touch /root/.Xauthority
xauth generate $DISPLAY . trusted
xauth add $DISPLAY . $(xxd -l 16 -p /dev/urandom)

# Set XAUTHORITY environment variable
export XAUTHORITY=/root/.Xauthority

# Run the web service
dbus-run-session node subService.js # Start the dbus-daemon instance for my subscription service

# For a quick test to see if Xvfb runs at all, you can replace with the command below instead
# dbus-run-session -- xvfb-run --server-args='-screen 0 1920x1080x24' node subService.js

# Since I run Xvfb already within my code, having it try to run twice on the same port might bring in
# errors (at least that is what I get on my end hehe, might work for you)

Resources you might find useful:

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