Skip to content

Instantly share code, notes, and snippets.

@sysnajar
Created November 26, 2017 05:50
Show Gist options
  • Save sysnajar/1bbbe526cb22ce5a020aaf349d27b8fd to your computer and use it in GitHub Desktop.
Save sysnajar/1bbbe526cb22ce5a020aaf349d27b8fd to your computer and use it in GitHub Desktop.
Install nightmare on debian server without X installed
1. Try running this simple Nightmare scripts , it returns nothing:
1 Nightmare = require ('nightmare');
2 var show = process.argv.length>2 && process.argv[2]=='true'
3 console.log('show = '+show)
4
5 const nightmare = Nightmare({ show: show });
6
7 nightmare
8 .goto('http://google.com')
9 .cookies.get({
10 path: '/query',
11 secure: true
12 })
13 .then((cookies) => {
14 // do something with the cookies
15 console.log('done')
16 process.exit()
17 })
18
2. Turns out Nightmare uses Electron which requires X-window installed
https://stackoverflow.com/questions/34795037/nightmare-js-not-working-as-expected-on-ubuntu-linux-cloud-server
3. we fix it by using xvfb
3.1 installl xvfb :
sudo apt-get install -y xvfb x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps clang libdbus-1-dev libgtk2.0-dev libnotify-dev libgnome-keyring-dev libgconf2-dev libasound2-dev libcap-dev libcups2-dev libxtst-dev libxss1 libnss3-dev gcc-multilib g++-multilib
3.2 run it (instead of just node example.js)
xvfb-run node example.js
4. it works!!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment