Nightmare JS not working

I know that the title of the question looks very vague! But it is there.

I installed nodejs on my production server that had the correct phantomjs, then I installed the nightmare via npm install nightmare , I see it in node_modules, I tried the example given 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 didn’t output anything, I simplified the script to a simple single goto, for the page on my server this page was never called when I ran the script through node file.js

I have CentOS 6.7, phantomjs 1.1 I also tested it on a new CentOS 7 installation with the latest phantomjs. Same.

Am I missing some precondition or something else? How to debug a problem since node script.js gives no output

UPDATE: Apparently, the problem is that the electron used by the nightmare “instead of phantoms” requires a graphical environment, so it does not start in my environment.

+3
source share
3 answers

The new version of Nightmare requires electron , not PhantomsJs. Make sure the electron command is in the $ PATH variable.

Install electron

npm i -g electron-prebuilt

Debug:

DEBUG=nightmare* node script.js

+4
source

Have a look at this Docker file: https://github.com/aheuermann/docker-electron/blob/master/7/Dockerfile

These are the minimum libraries you need. And to start with you script:

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

The electronic application should no longer crash

+1
source

You can also set electron in the background without actually displaying a graphical interface. You check if this works:

 var nightmare = Nightmare({ show: false}); 
0
source

Source: https://habr.com/ru/post/1274328/


All Articles