var system = require('system') , page = require('webpage').create() , fs = require('fs') , optUtils = require('./options'); // Read in arguments var options = JSON.parse(system.args[1]); var site = system.args[2]; var path = system.args[3]; var streaming = options.streaming; page.viewportSize = { width: options.windowSize.width , height: options.windowSize.height }; // Capture JS errors and write them to stderr page.onError = function(msg, trace) { var msgStack = ['ERROR: ' + msg]; if (trace && trace.length) { msgStack.push('TRACE:'); trace.forEach(function(t) { msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : '')); }); } system.stderr.write(msgStack.join('\n')); }; if (options.errorIfStatusIsNot200) { page.onResourceReceived = function(response) { // If request to the page is not 200 status, fail. if (response.url === site && response.status !== 200) { system.stderr.write('Status must be 200; is ' + response.status); page.close(); phantom.exit(0); } }; } // Handle cookies if (Array.isArray(options.cookies)) { for (var i=0; i