2011-06-08 12:01:30 +04:00
|
|
|
var page = new WebPage(), address, requests = [], responses = [];
|
2011-06-07 10:56:23 +04:00
|
|
|
|
|
|
|
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) {
|
2011-06-08 12:01:30 +04:00
|
|
|
requests.push(req);
|
|
|
|
};
|
|
|
|
|
|
|
|
page.onResourceReceived = function (res) {
|
|
|
|
responses.push(res);
|
2011-06-07 10:56:23 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
page.open(address, function (status) {
|
|
|
|
if (status !== 'success') {
|
|
|
|
console.log('FAIL to load the address');
|
|
|
|
} else {
|
2011-06-08 12:01:30 +04:00
|
|
|
console.log('All requests:');
|
|
|
|
console.log(JSON.stringify(requests, undefined, 4));
|
|
|
|
console.log();
|
|
|
|
console.log('All responses:');
|
|
|
|
console.log(JSON.stringify(responses, undefined, 4));
|
2011-06-07 10:56:23 +04:00
|
|
|
}
|
|
|
|
phantom.exit();
|
|
|
|
});
|
|
|
|
}
|