Puppeteer's Chrome exits with Missing X server or $DISPLAY
Fix it fast
Most common cause, 1 of 4The launch asks for a visible browser on a server
Go back to headless mode, which is the Puppeteer default, and keep the windowed mode for your own desktop runs only, for example behind an environment variable.
const browser = await puppeteer.launch({
headless: process.env.HEADFUL ? false : true,
});Short answer
Missing X server or $DISPLAY means Chrome started without its --headless switch and found no X display to draw on. In Puppeteer that comes from headless: false, devtools: true or ignoreDefaultArgs dropping the flag. Launch with headless: true (the default), or keep a visible browser by running the script under xvfb-run. Puppeteer 25.18.
Which cause do you have?
Print the display variable of the shell that starts the script, then list the launch options that decide headless mode. An empty DISPLAY plus headless: false points to cause 1; ignoreDefaultArgs or an env option points to causes 2 and 4.
echo "DISPLAY=[$DISPLAY]"
grep -rnE "headless|devtools|ignoreDefaultArgs|env:" --include=*.js --include=*.ts --include=*.mjs .Then find the line you see in this list and open its fix:
- 1The launch asks for a visible browser on a server
launch() has headless: false or devtools: true, and DISPLAY prints empty - 2ignoreDefaultArgs removed the headless flag
headless is true or unset, yet launch() passes ignoreDefaultArgs: true or a list that names --headless=new - 3You need a windowed browser, but the server has no X server
headless: false is intended (an extension or a visual check needs it) and the machine has no desktop session - 4An env launch option dropped DISPLAY
Xvfb or a desktop is running and echo shows DISPLAY, but launch() passes its own env object
What does the error look like?
ERROR:ozone_platform_x11.cc(...)] Missing X server or $DISPLAYError: Failed to launch the browser process!
Cause 1 of 4
The launch asks for a visible browser on a server
You seelaunch() has headless: false or devtools: true, and DISPLAY prints empty
Check
Chromium writes Missing X server or $DISPLAY only when the --headless switch is absent and no X connection opens. Puppeteer's devtools option forces headless to false, so either setting starts a windowed Chrome that a server with no desktop cannot show.
grep -rnE "headless: *false|devtools: *true" --include=*.js --include=*.ts .Fix
Go back to headless mode, which is the Puppeteer default, and keep the windowed mode for your own desktop runs only, for example behind an environment variable.
const browser = await puppeteer.launch({
headless: process.env.HEADFUL ? false : true,
});Verify
The script runs on the server and the log no longer shows the X server line.
node scrape.jsConfirmed by chromium.googlesource.com
Cause 2 of 4
ignoreDefaultArgs removed the headless flag
You seeheadless is true or unset, yet launch() passes ignoreDefaultArgs: true or a list that names --headless=new
Check
Puppeteer adds --headless=new (or --headless for headless: 'shell') through its default arguments. With ignoreDefaultArgs: true none of them are sent, so Chrome starts windowed even though the headless option looks right.
grep -rn "ignoreDefaultArgs" --include=*.js --include=*.ts .Fix
Pass ignoreDefaultArgs as an array naming only the flags you really want gone. That keeps the headless switch in place.
const browser = await puppeteer.launch({
ignoreDefaultArgs: ['--disable-extensions'],
});Verify
Run the script again on the server. Chrome starts headless and the X server line is gone.
node scrape.jsConfirmed by raw.githubusercontent.com
Cause 3 of 4
You need a windowed browser, but the server has no X server
You seeheadless: false is intended (an extension or a visual check needs it) and the machine has no desktop session
Check
Puppeteer's troubleshooting notes say an xvfb service must be running to use Chrome for Testing in non-headless mode. Xvfb is a virtual X server, so Chrome gets a display without a monitor.
command -v xvfb-run || echo "xvfb-run not installed"Fix
Install Xvfb and start the script through xvfb-run. With -a, xvfb-run picks an unused display number by itself, and your command runs on that virtual screen.
sudo apt-get install -y xvfb
xvfb-run -a node scrape.jsVerify
The headful run finishes under xvfb-run and the script's output looks the same as on a desktop.
xvfb-run -a node scrape.jsConfirmed by pptr.dev
Cause 4 of 4
An env launch option dropped DISPLAY
You seeXvfb or a desktop is running and echo shows DISPLAY, but launch() passes its own env object
Check
The env launch option sets the variables Chrome sees, and its default is the whole of process.env. An object that lists only a few variables replaces that default, so DISPLAY never reaches the browser.
grep -rn -A3 "env:" --include=*.js --include=*.ts .Fix
Spread process.env into the object and add your own values on top, so DISPLAY and the rest of the environment pass through.
const browser = await puppeteer.launch({
headless: false,
env: { ...process.env, TZ: 'UTC' },
});Verify
Chrome opens on the existing display and the launch succeeds.
node scrape.jsConfirmed by pptr.dev
How do I stop it coming back?
- Leave headless at its default in shared code and switch to a window only through an environment variable on your own machine.
- Give CI jobs that need a visible browser an Xvfb service or an xvfb-run wrapper, as Puppeteer's CI notes describe.
- Build any custom env for launch() from process.env rather than from an empty object.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.