netlog.js 657 B

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