Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

Puppeteer's Chrome exits with Missing X server or $DISPLAY

Your error

ERROR:ozone_platform_x11.cc(...)] Missing X server or $DISPLAY1 more line it can show

Fix it fast

Most common cause, 1 of 4

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

Fix
const browser = await puppeteer.launch({
  headless: process.env.HEADFUL ? false : true,
});
Did this fix it?
Full steps for this cause: check, fix, verify

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.

  • Applies to Puppeteer 25.18.1, Chrome for Testing on Linux, xvfb-run on Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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.

Run this first
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:

  1. 1The launch asks for a visible browser on a serverlaunch() has headless: false or devtools: true, and DISPLAY prints empty
  2. 2ignoreDefaultArgs removed the headless flagheadless is true or unset, yet launch() passes ignoreDefaultArgs: true or a list that names --headless=new
  3. 3You need a windowed browser, but the server has no X serverheadless: false is intended (an extension or a visual check needs it) and the machine has no desktop session
  4. 4An env launch option dropped DISPLAYXvfb 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 $DISPLAY
  • Error: 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.

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

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

Verify
node scrape.js

Confirmed by chromium.googlesource.com

Did this fix it?

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.

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

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

Verify
node scrape.js

Confirmed by raw.githubusercontent.com

Did this fix it?

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.

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

Fix
sudo apt-get install -y xvfb
xvfb-run -a node scrape.js

Verify

The headful run finishes under xvfb-run and the script's output looks the same as on a desktop.

Verify
xvfb-run -a node scrape.js

Confirmed by pptr.dev

Did this fix it?

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.

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

Fix
const browser = await puppeteer.launch({
  headless: false,
  env: { ...process.env, TZ: 'UTC' },
});

Verify

Chrome opens on the existing display and the launch succeeds.

Verify
node scrape.js

Confirmed by pptr.dev

Did this fix it?

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.

Which stack is behind this page?

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.