gadicohen:phantomjs

v0.0.2Published 10 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

phantomjs

All this package does is install phantomjs for you and make sure it's in your nodejs PATH. It is not a wrapper for using phantomjs directly, and the most common use is to ensure phantomjs is installed and useable by the spiderable package.

This is a tiny wrapper for the node phantomjs module. You could also just add that node module directly, but the advantages of the smart package are:

  1. Uses a modified version of the node module with support for

Sun (e.g. SmartOS) binary

  1. Updates your apps PATH to include the phantomjs dir, so

that scripts like spiderable will work.

What if I want to use phantomjs directly?

I'd recommend using an NPM wrapper like [https://www.npmjs.org/package/phantomjs-wrapper phantomjs-wrapper] or [https://www.npmjs.org/package/webshot webshot].

Alternatively, Ben Green has graciously provided the following example of how to use the phantomjs binary directly:

server/server.js:

1var phantomjs = Npm.require('phantomjs');
2var spawn = Npm.require('child_process').spawn;
3Meteor.methods({
4  runTest: function(options){
5    command = spawn(phantomjs.path, ['assets/app/phantomDriver.js']);
6    command.stdout.on('data',  function (data) {
7      console.log('stdout: ' + data);
8    });
9    command.stderr.on('data', function (data) {
10      console.log('stderr: ' + data);
11    });
12    command.on('exit', function (code) {
13      console.log('child process exited with code ' + code);
14    });
15  }
16});

private/phantomDriver.js:

1var page = require('webpage').create();
2page.open('http://github.com/', function() {
3    console.log('Page Loaded');
4    page.render('github.png');
5    phantom.exit();
6});

Credits

This smart package basically just assists in making the changes suggested in this Modulus blog post. Thanks, guys, for another great contribution to Meteor!