Tuesday 16 May 2017

(NodeJs) Command line arguments to PhantomJs child process along with script args

I have the following code that works:

var Path = require('path')
var Phantomjs = require('phantomjs2')
var phantomjsPath = Phantomjs.path
var childArgs = [
      Path.join(__dirname, 'phantomjs-worker.js'),
      'http://...some login url...',
      3000, //login timeout
      'http://...some address to render as image...',
      5000, //address timeout
      '...output image file path...',
      1000, //page width
      1000, //page height
      1234 //some id
    ]            
var child = Proc.spawn(phantomjsPath, childArgs, { cwd: process.cwd() })

Inside phantom-worker.js:

var argsOffset = 0;
var login = system.args[argsOffset + 1];
var logintimeout = system.args[argsOffset + 2];
var address = system.args[argsOffset + 3];
var addresstimeout = system.args[argsOffset + 4];
var output = system.args[argsOffset + 5];
var pageWidth = parseInt(system.args[argsOffset + 6]);
var pageHeight = parseInt(system.args[argsOffset + 7]);
var pageId = system.args[argsOffset + 8];
...

I need to be able to pass in

--ignore-ssl-errors=true --ssl-protocol=tlsv1

as well.

I tried adding these as the first 2 arguments but it doesn't work. It starts looking for the output image file path for some reason and obviously fails.

Is there any way to pass in these command line arguments along with the script and its child arguments?



via Raza Ali

No comments:

Post a Comment