Solvedphantomjs QXcbConnection: Could not connect to display

  1. Which version of PhantomJS are you using? Tip: run phantomjs --version.
  2. What steps will reproduce the problem?
    1. Take a working javascript file (e.g. rasterize.js)
    2. Call the file from a script file (e.g. executable file, #!/bin/sh at the start)
    3. Now execute the script file as a cron job
  3. Which operating system are you using?
    Ubuntu 16.04 LTS
  4. Did you use binary PhantomJS or did you compile it from source?
    Binary - installed it as part of Ubuntu (using apt).
  5. Please provide any additional information below.
    This is very similar to #14240, but I am using the stock version of PhantomJS (with Ubuntu). Below is the output from running the cron job (which calls the script file, to generate a pdf file once a day) ...

QXcbConnection: Could not connect to display
PhantomJS has crashed. Please read the bug reporting guide at and file a bug report.
Aborted (core dumped)


25 Answers

✔️Accepted Answer


can confirm export QT_QPA_PLATFORM=offscreen before selenium scripts work's well.

Other Answers:

The offscreen platform is a usable workaround for me with the stock Ubuntu package. This works for me:

QT_QPA_PLATFORM=offscreen phantomjs rasterize.js 2i8zaNg04d9B41Zir2kT3J/output.html 2i8zaNg04d9B41Zir2kT3J.png

@3zzy the steps I used are as follows:
bzip2 -d phantomjs-2.1.1-linux-x86_64.tar.bz2
tar -xvf phantomjs-2.1.1-linux-x86_64.tar
cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs

Does this help your case?

We finally got things working by downloading the binary at and extracting the phantomjs to /usr/bin

Please check your environment variable QT_QPA_PLATFORM. It must be empty.

Related Issues:

phantomjs QXcbConnection: Could not connect to display
can confirm export QT_QPA_PLATFORM=offscreen before selenium scripts work's well. ...
phantomjs Problems with web-animations-js
To get this working: Modify your karma.conf.js in local project setup and add './node_modules/web-an...
puppeteer Failed to download Chromium r536395! Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" env variable to skip download.
Solves the issue to me. Steps to reproduce Tell us about your environment: Puppeteer version: Not in...
puppeteer How to get text from a element ?
You can try this: or this: This might be a Obvious question but ...
puppeteer Chrome Headless doesn't launch on Debian
for the dockerisers amongst us - i've launched successfully with this setup: Running this example co...
vagrant vagrant box update - Fails with 404 Not Found error
A workarround to add in your Vagrantfile: Vagrant version Host operating system Ubuntu 16.04.3 LTS G...
puppeteer Ubuntu 18.04 Headless Chrome Node API - Puppeteer - Installation Guide
Based on You only have to run the following command in Ubu...
vagrant vagrant --help displays a rubygems error
To fix this error: Vagrant version Host operating system Expected behavior vagrant and vagrant --hel...
puppeteer how to check if selector exists or is present ?
As a variant: how to check if selector exists or is present waiting for (x) time or when the page is...
puppeteer Installation fails on Apple Silicon / M1
The solution for me using Chromium from Homebrew was: You will get a security warning ...
puppeteer npm install -g puppeteer fails
This command ended up working for me in case anyone lands here by googling the error: sudo npm insta...
puppeteer can't run puppeteer in centos7
@zhuyingda 's notes above will allow you to run puppeteer with --no-sandbox Server Info: CUP: Intel(...
puppeteer Headless mode is not working
I had the same issue I then added await page.screenshot(...) to see what's going on in headless mode...
vagrant Vagrant up forces shutdown of VM
Update: Please upgrade vagrant to 1.9.5 as it's released The version contains fix for this issue ...
puppeteer Run from Electron
For me the solution was a combination of the approach of @qathom and @tpkn: But in my case the array...
fastlane Connection reset by peer
Thanks for the fix! got me back in business New Issue Checklist Updated fastlane to the latest versi...
puppeteer How to scrape an element
The following should work: Hi I think this is an obvious question but still I cannot figure out how ...
puppeteer] Running as root without --no-sandbox is not supported
@ststeiger so which are the launch options? Like Or do I need to add args: ['--no-sandbox' '--disabl...
puppeteer Page.setContent should wait for resources to be loaded
Meanwhile a good workaround for page.setContent that waits for all the resources to load: ...
vagrant 1.8.7 fails to download or update boxes
I just sudo rm -rf /opt/vagrant/embedded/bin/curl and it works now It's looked like vagrant can fall...
puppeteer Request: browser.currentPage() or similar way to access Pages
To get the first page of the current browser I was playing around with Puppeteer today and I found o...
puppeteer Error: Failed to launch chrome! spawn /app/node_modules/puppeteer/.local-chromium/linux-609904/chrome-linux/chrome ENOENT
@arapocket Thanks for commenting—I forgot to follow up after I found a solution It's been a couple o...
vagrant VBoxManage.exe: error: Invalid NIC number
Confirm the problem It is reproduced with Windows10/Vagrant 1.8.3/VirtualBox 5.0.20 and hashicorp/pr...
puppeteer Error: Failed to launch the browser process! spawn chrome.exe ENOENT
For me on Linux the only way to resolve is by installing some dependencies: Source ...
puppeteer EventEmitter memory leak detected. 11 exit listeners added
@selfrefactor ah indeed you launch chrome processes in parallel Every chrome instance adds a listene...
vagrant Openssl error on Vagrant 1.8.7 / MacOs Sierra
The workaround to link the existing openssl as proposed in GH-7747 seems to work as well sudo ln -sf...
puppeteer Collect element attributes from selector
i think this would do it And once #625 is implemented this will be.. Beginner user here Started play...
fastlane firebase_app_distribution plugin doesn't work in macOS Catalina
Looks like files in firebase_app_distribution plugin have incorrect permissions 640 by default ...
puppeteer Puppeteer Won't Click on Element
In my case I'm able to use this reliably: page.$eval(selectorStr elem =>; ...
puppeteer Execution context was destroyed, most likely because of a navigation
@THE-GAME-YOU-LOST I see The right thing to do would be to await navigation caused by ...
puppeteer does not work with an input selector
I'm running into the same issue Strangely if I use page.evaluate it does work For example: I'd be cu...
puppeteer Different behavior between { headless: false } and { headless: true }
As mentioned in the article @Garbee posted the headless version does not have languages set on the n...
fastlane fastlane gym produces error: method `to_plist' not defined in Array
Alright New Issue Checklist Updated fastlane to the latest version I read the Contribution Guideline...
vagrant Error while executing "VBoxManage" on vagrant up
For me vboxreload is actually sudo /sbin/vboxconfig Vagrant version Vagrant 1.8.1 Host operating sys...
puppeteer Puppeteer with headless:true is extremely slow
Hey guys so I've found a workaround for this Though this issues has been raised in #1550 but it was ...
fastlane [match] failing on post_profiles / post_certificate with: undefined method `first' for "errors":String (NoMethodError)
Logging into allowed me to review the updated Apple Developer Pr...
vagrant mount.nfs: requested NFS version or transport protocol is not supported
It was still a problem for me in 2.1.2 in Manjaro Linux with a static IP Lately me and my coworkers ...
puppeteer Issue with deploying puppeteer on heroku (with resolution)
Did you try puppeteer.launch({args: ['--no-sandbox' '--disable-setuid-sandbox']});? ...
fastlane '<module:Faraday>': superclass mismatch for class ConnectionFailed (TypeError)
Same for me As a temporary workaround after installing fastlane via gem install: ...
fastlane App packaging is returning an error
@WedgeSparda The error message is not logic since automatic signing is already enabled But I managed...
vagrant Vagrant 1.8.5 embedded open ssl error
Yes I have openssl installed via brew The work around suggested by @garadox seemed to work though: ...
vagrant "vagrant plugin install vagrant-libvirt" on Ubuntu 14.04 must display a user-friendly message if libvirt is not installed
Hi I tried to use the CONFIGURE_ARGS trick but it failed with this message: So I had to add a second...
vagrant An error occurred in the underlying SSH library that Vagrant uses.
what worked for me was: #Vagrant 1.8.6 Mac OSX 10.11.6 VB - 5.1.8 Guest box - ubuntu/trusty64 (up to...
fastlane fastlane cert got Unauthorized Access error
@janpio I was able to authenticate successfully by entering sms when prompted for the 2FA code and s...
puppeteer Query nodes within shadow roots
TL;DR: try Copy JS Path in Chrome Canary to get a js selector for nodes inside Shadow DOM ...
InstaPy Login A/B test detected! Trying another string...
To anybody still having this issue on 6.1 Its caused by a typo in the file Line 159...
vagrant Cannot access
I was able to fix the issue by switching from = 'precise64' to = 'hashic...
fastlane xcode 9 beta export options not working
@Reedyuk Instead of xcargs use export_xcargs I tried the following with success export_xcargs: -allo...
fastlane macOS Catalina bad interpreter: No such file or directory
For example I have my GEM_HOME setup to be in my user folder (~/.gem) so I can install gems without ...