netlog.js 671 B

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