Nightmare.js does not work as expected on a Ubuntu Linux cloud server

I cannot get nightmare.js to work on a Ubuntu Linux 14.04 server [via DigitalOcean].

I installed PhantomJS (1.9.8) and Node (4.2.4), and they work well, as far as I can tell.

For example, when I run this:

phantomjs loadspeed.js http://www.yahoo.com

with loadpeed.js containing this:

"use strict";
var page = require('webpage').create(),
    system = require('system'),
    t, address;

if (system.args.length === 1) {
    console.log('Usage: loadspeed.js <some URL>');
    phantom.exit(1);
} else {
    t = Date.now();
    address = system.args[1];
    page.open(address, function (status) {
        if (status !== 'success') {
            console.log('FAIL to load the address');
        } else {
            t = Date.now() - t;
            console.log('Page title is ' + page.evaluate(function () {
                return document.title;
            }));
            console.log('Loading time ' + t + ' msec');
        }
        phantom.exit();
    });
}

I get the following output:

Page title is Yahoo
Loading time 700 msec

However, when I try to run a simple nightmare:

node --harmony hello_nightmare.js

with hello_nightmare.js containing this:

var Nightmare = require('nightmare');

var google = new Nightmare()
  .goto('http://google.com')
  .wait()
  .run(function(err, nightmare) {
    if (err) return console.log(err);
    console.log('Done!');
  });

I get no output; it seems to me that I just hit 'Enter' on the command line.

I also tried an example on the github nightmare site:

npm install nightmare vo
node --harmony hello_nightmare_main.js

with hello_nightmare_main.js containing this:

var Nightmare = require('nightmare');
var vo = require('vo');

vo(function* () {
  var nightmare = Nightmare({ show: true });
  var link = yield nightmare
    .goto('http://yahoo.com')
    .type('input[title="Search"]', 'github nightmare')
    .click('.searchsubmit')
    .wait('.ac-21th')
    .evaluate(function () {
      return document.getElementsByClassName('ac-21th')[0].href;
    });
  yield nightmare.end();
  return link;
})(function (err, result) {
  if (err) return console.log(err);
  console.log(result);
});

And it still doesn't work.

How to fix this nightmare?

+4
3

, , https://github.com/segmentio/nightmare/issues/224

Nightmare Electron, X-; , Xvfb . xvfb

xvfb-run node --harmony hello_nightmare.js

+7

.

bash script nightmarejs node (4.2.4) Ubuntu Linux. DigitalOcean, 14.04.

apt-get -y update
apt-get -y upgrade
apt-get -y --force-yes install make unzip g++ libssl-dev git 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
mkdir src
cd src
wget https://nodejs.org/dist/v4.2.4/node-v4.2.4.tar.gz
tar xzf node-v4.2.4.tar.gz
cd node-v4.2.4
./configure
make -j2
make install
cd ..
mkdir nightmarejs
cd nightmarejs
npm -f init
npm install --save nightmare vo

.js(, hello_nightmare.js) ( , nightmarejs), , ( @yoz):

xvfb-run node --harmony hello_nightmare.js

, .

+7

X,

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

Tested on ubuntu's server aws ec2and it worked

then run the script:

xvfb-run node --harmony script.js

+3
source

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


All Articles