Nightmare JS not working
Asked Answered
T

3

5

I know the title of the question looks very vague! But that's there's to it.

I installed nodejs on my production server, which had phantomjs working properly, then I installed nightmare via npm install nightmare, I can see it in node_modules, I tried the example listed by the developers on github:

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

nightmare
  .goto('http://yahoo.com')
  .type('input[title="Search"]', 'github nightmare')
  .click('#uh-search-button')
  .wait('#main')
  .evaluate(function () {
    return document.querySelector('#main .searchCenterMiddle li a').href
  })
  .end()
  .then(function (result) {
    console.log(result)
  })

Nothing happened, the script did not output anything, I simplified the script to a simple single goto, for a page on my server, the page was never called when I ran the script via node file.js

I have CentOS 6.7, phantomjs 1.1 I also tested it on a fresh CentOS 7 installation with latest version of phantomjs, same thing.

Am I missing some kind of prerequisite or something? How do I debug the issue since node script.js is not giving any output

UPDATE: Apparently the problem is, electron, which is used by nightmare 'instead of phantomjs' requires a graphical enviroment, which is why it fails to run in my enviroment.

Tumbrel answered 19/4, 2016 at 13:1 Comment(0)
R
8

New version of Nightmare requires electron, Not PhantomsJs. Make sure electron command is in your $PATH variable.

Install Electron

npm i -g electron-prebuilt

To debug:

DEBUG=nightmare* node script.js

Riocard answered 19/4, 2016 at 13:9 Comment(4)
Thank you, I thought that was it at first after your answer, cos obviously that should have been the reason, I installed electron-prebuilt globally, I ran into some dependency errors when I was trying to run electron, I installed the needed libraries, but nightmare still does not work, I tried NODE_DEBUG=nightmare node script.js still no output Also running electron is not giving me any output as well, I tried electron --help, not sure if it accepts this argument, but either way no outputTumbrel
Try ` DEBUG=nightmare* node script.js` , looks like the library uses debug module, Not the built-in debuglogRiocard
Thank you, that showed the error, maybe I've got something wrong, do I need to have a GUI environment for this to run? Does it require X11 to be running? Because one of the libraries it required belonged to X11 I think 'libgtk-x11', I'm getting the error: electron child process exited with code 1: general error - you may need xvfb.Tumbrel
I guess so. I'm on Windows, so can't help you much. You can browse through their GitHub issues for any information.Riocard
S
2

Look at this Dockerfile: https://github.com/aheuermann/docker-electron/blob/master/7/Dockerfile

It s the minimal libs you need. And to start you script:

Xvfb -ac -screen scrn 1280x2000x24 :9.0 &
export DISPLAY=:9.0
DEBUG=* node src/index.js

Electron based app should no more crash

Sirocco answered 16/1, 2017 at 16:40 Comment(0)
W
1

You can also try to set electron in the background without actually showing any GUI. You check if this works:

var nightmare = Nightmare({ show: false});
Williams answered 18/1, 2017 at 12:38 Comment(1)
did you try it?Consul

© 2022 - 2024 — McMap. All rights reserved.