puppeteer icon indicating copy to clipboard operation
puppeteer copied to clipboard

[Bug]: Missing X server or $DISPLAY

Open pankhiprasher opened this issue 2 years ago • 30 comments

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

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 avatar Mar 18 '22 20:03 pankhiprasher

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

kzenman avatar Mar 19 '22 10:03 kzenman

@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

pankhiprasher avatar Mar 21 '22 14:03 pankhiprasher

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 avatar Mar 28 '22 16:03 StackedQueries

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[bot] avatar Jun 23 '22 11:06 stale[bot]

image

Still happening

AlexRudyak avatar Jun 27 '22 16:06 AlexRudyak

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$

abhiatmsit avatar Jul 13 '22 05:07 abhiatmsit

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.

rpicard92 avatar Jul 15 '22 16:07 rpicard92

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 avatar Jul 17 '22 06:07 Plorax

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 avatar Jul 17 '22 07:07 Plorax

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.

Plorax avatar Jul 17 '22 07:07 Plorax

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)

vincechapman avatar Jul 26 '22 11:07 vincechapman

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)

vvolodin avatar Jul 27 '22 10:07 vvolodin

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

jnalbert avatar Jul 27 '22 19:07 jnalbert

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.

InanisV avatar Jul 29 '22 02:07 InanisV

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

rainb3rry avatar Aug 04 '22 08:08 rainb3rry

@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

mkmark avatar Aug 05 '22 04:08 mkmark

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

Joshfindit avatar Aug 17 '22 19:08 Joshfindit

Same here 😢 image

peterramaldes avatar Aug 27 '22 14:08 peterramaldes

export DISPLAY=$HOST_IP:10.0 &&

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

rainb3rry avatar Aug 28 '22 02:08 rainb3rry

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

YoannBuzenet avatar Sep 05 '22 11:09 YoannBuzenet

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.

jlanssie avatar Sep 10 '22 21:09 jlanssie

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"

csaid4152 avatar Sep 15 '22 14:09 csaid4152

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

AndrewPahomovOtto avatar Sep 16 '22 07:09 AndrewPahomovOtto

@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

smit-code avatar Sep 25 '22 20:09 smit-code

I came up with that for PlayWright but it should be the same for Puppeteer. This worked for me:

  1. Create a bash script:

nano launcher.sh

Add some content to launch your script:

#!/bin/bash
export DISPLAY=$HOST_IP:10.0 && /usr/local/bin/node /path/to/playwright/script.js
  1. Make it executable:

chmod +x launcher.sh

  1. Add the appropriate line to your crontab:

*/30 * * * * /usr/bin/bash /path/to/launcher.sh

Done.

zeglin avatar Oct 22 '22 23:10 zeglin

I had the same problem in Ubuntu using WSL in win10, the issue come from missing packages in Linux and using headless: true, and not using --no-sandbox in launchOptions.

I solve it by installing the missing packages, as mentionned here : https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix

sudo apt-get install ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 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 wget xdg-utils

and removing headless: true from LaunchOptions and using args

args: ['--no-sandbox', '--disable-setuid-sandbox'],

laminesadiki avatar Oct 28 '22 22:10 laminesadiki

I had the same problem in Ubuntu using WSL in win10, the issue come from missing packages in Linux and using headless: true, and not using --no-sandbox in launchOptions.

I solve it by installing the missing packages, as mentionned here : https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix

sudo apt-get install ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 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 wget xdg-utils

and removing headless: true from LaunchOptions and using args

args: ['--no-sandbox', '--disable-setuid-sandbox'],

That is hardly a solution. You installed a bunch of dependencies to run a headless Chrome and then remove the headless flag from the script and end up not running it headless???

Also, the sandbox arguments should not impact errors about the presence or absence of a display.

jlanssie avatar Oct 28 '22 22:10 jlanssie

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.

dmuthuraaj avatar Oct 31 '22 07:10 dmuthuraaj

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

HaithamOumerzoug avatar Nov 03 '22 10:11 HaithamOumerzoug

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

XAEAXII avatar Nov 03 '22 13:11 XAEAXII