Skip to content

Instantly share code, notes, and snippets.

@ariya
Created June 7, 2011 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ariya/1011801 to your computer and use it in GitHub Desktop.
Save ariya/1011801 to your computer and use it in GitHub Desktop.
onResourceRequested example
var page = new WebPage(), address, resources = [];
if (phantom.args.length === 0) {
console.log('Usage: netsniff.js <some URL>');
phantom.exit();
} else {
address = phantom.args[0];
page.onLoadStarted = function () {
page.startTime = Date.now();
};
page.onResourceRequested = function (req) {
req.time = Date.now() - page.startTime;
resources.push(req);
};
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
} else {
console.log('All resources:');
console.log(JSON.stringify(resources, undefined, 4));
}
phantom.exit();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment