Ollie Jennings
Ollie Jennings

Reputation: 92

Running PhantomJS & node.js together on Ubuntu

  1. So l have recently been using phantomjs-node using the 1.7 fix on my Mac with no problems.

    However when I try to run it on my Ubuntu 12.04 machine it gives me the following problems:

    phantom stdout: ReferenceError: Can't find variable: socket phantomjs://webpage.evaluate():1 phantomjs://webpage.evaluate():1 phantomjs://webpage.evaluate():1

    Edit:
    The line causing this problem is at shim.js line 1684:

    evil = "function(){socket.emit('message', " + (JSON.stringify(JSON.stringify(req))) + " + '\\n');}";
    

    which seems to be related to this PhantomJS issue.

    Any idea on how to fix this issue above would be helped.

  2. So l tried using phantom-proxy instead as it is meant to a kept-up-to-date version of phantomjs-node.

    However l am getting a different sort of problem when running on my ubuntu 12.04 machine:

    SyntaxError: Parse error
    TypeError: 'undefined' is not a function (evaluating 'require('./webpage').create(this)')
    ~/node_modules/phantom-proxy/lib/server/webserver.js:11
    ~/node_modules/phantom-proxy/lib/server/webserver.js:164
    ~/node_modules/phantom-proxy/lib/server/webserver.js:165
    

    I do realise there is a parse error, but this is from copying one of the examples in the readme.md provided.

    Any help with this solution either would be appreciated.

Upvotes: 1

Views: 1570

Answers (1)

Ollie Jennings
Ollie Jennings

Reputation: 92

Okay so l fixed this using option 1.

It required me doing a fresh node project using the

    express myapp
    npm install

etc.. then in my package.json file l attached the dependency:

   "phantom":"git://github.com/amir20/phantomjs-node.git#phantom-1.7-fix"
   npm install

l then tested one of the examples provided:

   var phantom = require('phantom');

   phantom.create(function (ph) {
      console.log('instance created');
      ph.createPage(function (page) {
         console.log('spooled up');
         page.open('http://www.google.com', function (status) {
            console.log(status);
            page.release();
         });
      });
   });

And this all worked properly.


NOTE: l do not use a proxy on my ubuntu machine, this is why it worked, on a machine that l did have a proxy on, the example failed to execute, this makes me thing that it won't work on heroku boxes, however l will have a test today and edit this answer with the result.


EDIT

I checked this solution by deploying my app on heroku. When running my app, it failed at the point l expected:

    phantom stdout: ReferenceError: Can't find variable: socket
       phantomjs://webpage.evaluate():1
       phantomjs://webpage.evaluate():1
       phantomjs://webpage.evaluate():1

This is due to the fact that phantomjs-node cannot work behind a proxy unless you specify the proxy settings, and since l was running on heroku, l could not specify these settings.

Upvotes: 1

Related Questions