Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing through Phantomjs options #179

Merged
merged 1 commit into from
Dec 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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