Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lucasbrigida/f9d606a6888cbd1c7874a84607486c3e to your computer and use it in GitHub Desktop.
Save lucasbrigida/f9d606a6888cbd1c7874a84607486c3e to your computer and use it in GitHub Desktop.
Running Nightmare headlessly on Linux

Installation

Installing dependencies

sudo apt-get install build-essential clang libdbus-1-dev libgtk2.0-dev \
                       libnotify-dev libgnome-keyring-dev libgconf2-dev \
                       libasound2-dev libcap-dev libcups2-dev libxtst-dev \
                       gcc-multilib g++-multilib \
                       libgtk2.0-0 libgconf-2-4 \
                       libasound2 libxtst6 libxss1 libnss3 xvfb \

Install NodeJS

Download nvm

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash

After install nvm, install a node version. For example:

nvm install v5.5.0

Close your terminal and open again.

Install Electron Pre-Built

In project folder run command

npm install [email protected] --save

Specify Electron Path

Add electronPath parameter

var nightmare = Nightmare({
  electronPath: require('electron-prebuilt')
});

Run Nightmare Script

xvfb-run -a node --harmony <your-script>

Your script didn't run?

DEBUG=nightmare:*,electron:* xvfb-run -a node --harmony <your-script>

OR

DEBUG=nightmare:*,electron:* node --harmony <your-script>

Check if there is not installed library. If you can not find the problem please visit this link

@gentleShark
Copy link

fyi, this Gist is out of date and doesn't work. this, however, does: https://medium.com/@cubxi/running-nightmare-js-on-a-headless-server-95f97d271488

@mh4ck
Copy link

mh4ck commented Apr 25, 2021

Thank you very much for this script!

Just to let everyone know libgnome-keyring-dev making problems in debian 10 but you can just ignore it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment