API Reference System - fpdetective/phantomjs GitHub Wiki

This is a living document. As the codebase is updated, we hope to keep this document updated as well. Unless otherwise stated, this document currently applies to the latest PhantomJS release: PhantomJS 1.8.0

Note: This page serves as a reference. To learn step-by-step on how to use PhantomJS, please refer to the Quick Start guide.

To start using, you must require a reference to the system module:

var system = require('system');

The following example demonstrates the same functionality as the Unix printenv utility or the Windows set command:

var env = require('system').env;
Object.keys(env).forEach(function(key) {
    console.log(key + '=' + env[key]);
});

The following example prints all of the command-line arguments:

var args = require('system').args;
if (args.length === 1) {
    console.log('Try to pass some arguments when invoking this script!');
}
else {
    args.forEach(function(arg, i) {
        console.log(i + ': ' + arg);
    });
}