Skip to content

Instantly share code, notes, and snippets.

@jbuchbinder
Created April 1, 2016 14:03
Show Gist options
  • Save jbuchbinder/f77e20dbe85c537ae68bae8faf0b3e44 to your computer and use it in GitHub Desktop.
Save jbuchbinder/f77e20dbe85c537ae68bae8faf0b3e44 to your computer and use it in GitHub Desktop.
PhantomJS page load timer
// @jbuchbinder
//
// Execute with:
// phantomjs --ssl-protocol=TLSv1 phantom-load.js URL
"use strict";
var page = require('webpage').create(),
system = require('system'),
address;
if (system.args.length === 1) {
console.log('Usage: phantomjs-load.js <some URL>');
phantom.exit(1);
} else {
address = system.args[1];
page.onResourceRequested = function (req) {
//console.log('requested: ' + JSON.stringify(req, undefined, 4));
};
page.onResourceReceived = function (res) {
//console.log('received: ' + JSON.stringify(res, undefined, 4));
};
page.onError = function(msg, trace) {
// Hide errors
};
var perf_start = new Date().getTime();
page.open(address, function (status) {
if (status !== 'success') {
//console.log('FAIL to load the address, status == ' + status);
phantom.exit(1);
}
var perf_time = new Date().getTime() - perf_start;
console.log(perf_time);
phantom.exit(0);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment