Monday, March 14, 2022

[SOLVED] Puppeteer - Chromium | Unable to open X display | Ubuntu 20.04

Issue

  1. Puppeteer preinstalled chromium wasn't working at all so I installed ubuntu one by apt install chromium-browser and changed executable path to usr/bin/chromium-browser

  2. Now, puppeteer doesn't throw any errors but I'm getting this one:

    [935270:935270:1222/220755.094434:ERROR:browser_main_loop.cc(1434)] Unable to open X display.

I tried everything I red on forums but didn't work.


Solution

I am just assuming that you are executing this on a terminal only Ubuntu? In my case it was the Ubuntu Windows subsystem for Linux.

As usual when you have a solution the problem is mostly what the error says. There is no display.

Unable to open X display.

There is a solution for this called X virtual framebuffer or xvfb. https://en.wikipedia.org/wiki/Xvfb

The way I understand it it is aiming at acting as a display for all the intents of the client but is not visible to the user.

So one solution for the problem I had was to install xvfb and then run the command that requires a display with this tool. In my case it was protractor but the pupeteer command should look similar:

sudo apt-get install xvfb 
xvfb-run --auto-servernum npm run protractor

PS. I got inspired by this blog entry https://remarkablemark.org/blog/2020/12/12/headless-test-in-github-actions-workflow/



Answered By - Thilo Pfeiffer
Answer Checked By - Pedro (WPSolving Volunteer)