0

I've installed PhantomJS in my Meteor app using the instructions in the answer here: Installing/Using Phantom.js with Meteor but the method involved:

(private/phantomDriver.js)

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

has a set URL... how can I pass parameters to the file to change the URL? e.g.

page.open(URL, etc...)

This:

var URL = newURL
spawn(phantomjs.path, ['assets/app/phantomDriver.js', URL]);

Logs

"stdout: ReferenceError: Can't find variable: URL" to the console.

Community
  • 1
  • 1
reoh
  • 282
  • 5
  • 12
  • possible duplicate of [Passing a variable to PhantomJS via exec](http://stackoverflow.com/questions/16752882/passing-a-variable-to-phantomjs-via-exec) While the question might not match, the answer does. – Artjom B. Apr 13 '15 at 17:10

1 Answers1

0

Artjom B.'s link didn't solve the problem (needed to use spawn(phantomjs.path) whereas exec expects a string I don't know of) - though it did lead me to the answer so, thanks!

Also made use of require('system').args; to access the arguments sent via spawn

Final code:

server.js:

spawn(phantomjs.path, ['assets/app/phantom_driver.js',URL]);

private/phantomDriver.js

var page = require('webpage').create();
var args = require('system').args;
var URL = args[1]

page.open(URL, function(status) {
  console.log('Page loaded. Status: ' + status);
  page.render('github.png');
  phantom.exit();
})
reoh
  • 282
  • 5
  • 12