From c21306fa19cd17c02146c15b61a8229d2888f264 Mon Sep 17 00:00:00 2001 From: nathanvda Date: Sun, 31 Jan 2016 23:08:19 +0100 Subject: [PATCH] Use system.args if phantom.args is undefined In phantomjs versions > 2.0 phantom.args is no longer supported, and we should use system.args instead. --- lib/screencap/raster.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/screencap/raster.js b/lib/screencap/raster.js index 884abe3..ab7c319 100644 --- a/lib/screencap/raster.js +++ b/lib/screencap/raster.js @@ -34,12 +34,23 @@ var page = new WebPage(), // Functions // function pickupNamedArguments() { - var i, pair; - for(i = 0; i < phantom.args.length; i++) { - pair = phantom.args[i].split(/=(.*)/); - args[pair[0]] = pair[1]; + var pair, scriptArgs; + if (typeof phantom.args != 'undefined') { + // phantomjs < 2.0 + scriptArgs = phantom.args; + } else { + // phantomjs 2.0 + var system = require('system'); + scriptArgs = system.args; + // remove first arg as always script name + scriptArgs.shift(); } + scriptArgs.forEach(function(arg, i) { + pair = arg.split(/=(.*)/); + args[pair[0]] = pair[1]; + }); + if(!args.width) { args.width = 1024; } if(!args.dpi) { args.dpi = 1; } if(args.url) { args.url = decodeURIComponent(args.url); }