Testing nightmare.js example code but no result shown

nodejs

#1

I am running the example code of nightmare.js on c9,io, a virtual machine for ubuntu. The example.js does not return anything. Could someone review what the problem here?I am a total beginner for node.js and c9 so the issue might lie in some very simple process.Attached is the screen cut just in case I made a mistake like placing it in a wrong location.

 var Nightmare = require('nightmare');
 var nightmare = Nightmare({ show: true });

nightmare
  .goto('http://yahoo.com')
  .type('form[action*="/search"] [name=p]', 'github nightmare')
  .click('form[action*="/search"] [type=submit]')
  .wait('#main')
  .evaluate(function () {
    return document.querySelector('#main .searchCenterMiddle li a').href
  })
  .end()
  .then(function (result) {
    console.log(result)
  })
  .catch(function (error) {
console.error('Search failed:', error);
  });

#2

this happens because nightmare.js doesn’t run well in headless mode and hides all error messages

DEBUG=nightmare* node example.js 

will suggest to install xvfb
And after installing it by running:

sudo apt-get update &&\
    sudo apt-get install -y libgtk2.0-0 libgconf-2-4 \
    libasound2 libxtst6 libxss1 libnss3 xvfb

nighmare works when launched with xvfb-run command

DEBUG=nightmare* xvfb-run node example.js 

#3

I cannot find any tutorial of installing xvfb on cloud9.
How should I do it?
If I got a new Mac, will I solve this problem?


#4

there is a tutorial in my previous answer, see the code snippet with sudo apt-get. I’ll edit the answer to make this more obvious.


#5

Please look here:

https://github.com/segmentio/nightmare/issues/224#issuecomment-141575361