0418c23f7ca16079ffc5de8c6abc5147587be97c
[yaffs-website] / node_modules / phantomjs-prebuilt / lib / phantom / examples / netlog.js
1 "use strict";
2 var page = require('webpage').create(),
3     system = require('system'),
4     address;
5
6 if (system.args.length === 1) {
7     console.log('Usage: netlog.js <some URL>');
8     phantom.exit(1);
9 } else {
10     address = system.args[1];
11
12     page.onResourceRequested = function (req) {
13         console.log('requested: ' + JSON.stringify(req, undefined, 4));
14     };
15
16     page.onResourceReceived = function (res) {
17         console.log('received: ' + JSON.stringify(res, undefined, 4));
18     };
19
20     page.open(address, function (status) {
21         if (status !== 'success') {
22             console.log('FAIL to load the address');
23         }
24         phantom.exit();
25     });
26 }