Skip to content

Commit

Permalink
Merge pull request #179 from macbre/native-phantomjs-options
Browse files Browse the repository at this point in the history
Passing through Phantomjs options
  • Loading branch information
macbre committed Dec 18, 2013
2 parents 1cbdeaa + 6404201 commit 7a01b05
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
26 changes: 22 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var debug = require('debug')('phantomas'),

function phantomas(url, options, callback) {
var args = [],
phantomJsArgs = [],
events = new emitter(),
path = '',
proc,
Expand Down Expand Up @@ -38,19 +39,36 @@ function phantomas(url, options, callback) {

// build args
Object.keys(options).forEach(function(key) {
var val = options[key];
var val = options[key],
nativeOptions = [
'cookies-file',
'ignore-ssl-errors',
'proxy',
'proxy-auth',
'proxy-type'
];

if (val === false) {
return;
}

args.push('--' + key);
// handle native PhantomJS options (#163)
// @see http://phantomjs.org/api/command-line.html
if (nativeOptions.indexOf(key) > -1) {
phantomJsArgs.push('--' + key + '=' + val);
}
else {
args.push('--' + key);

if (val !== true) {
args.push(val);
if (val !== true) {
args.push(val);
}
}
});

// add native PhantomJS options
args = phantomJsArgs.concat(args);

debug('Running %s %s', path, args.join(' '));

// spawn the process
Expand Down
5 changes: 5 additions & 0 deletions phantomas.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ program
.describe('config', 'uses JSON-formatted config file to set parameters')
.describe('cookie', 'document.cookie formatted string for setting a single cookie (e.g. "bar=foo;domain=url")')
.describe('cookie-jar', 'persistent cookie JAR across requests')
.describe('cookies-file', 'specifies the file name to store the persistent Cookies')
.describe('disable-js', 'disable JavaScript on the page that will be loaded').boolean('disable-js')
.describe('format', 'output format').default('format', 'plain')
.describe('ignore-ssl-errors', 'ignores SSL errors, such as expired or self-signed certificate errors')
.describe('log', 'log to a given file')
.describe('modules', 'run selected modules only [moduleOne],[moduleTwo],...')
.describe('no-externals', 'block requests to 3rd party domains').boolean('no-externals')
.describe('proxy', 'specifies the proxy server to use (e.g. --proxy=192.168.1.42:8080)')
.describe('proxy-auth', 'specifies the type of the proxy server (default is http)')
.describe('proxy-type', 'specifies the authentication information for the proxy (e.g. --proxy-auth=username:password)')
.describe('screenshot', 'render fully loaded page to a given file')
.describe('silent', 'don\'t write anything to the console').boolean('silent')
.describe('skip-modules', 'skip selected modules [moduleOne],[moduleTwo],...')
Expand Down

0 comments on commit 7a01b05

Please sign in to comment.