Advertisement
Guest User

Untitled

a guest
Jul 28th, 2011
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 2011-06-21: Version 1.2.0
  2. run phantomjs ./whateverscript http://fbi.gov
  3.  
  4.  
  5.  
  6.  
  7. gettimeofday({1311848791, 76708}, {4294967236, 0}) = 0
  8. gettimeofday({1311848791, 76734}, {4294967236, 0}) = 0
  9. gettimeofday({1311848791, 76765}, {4294967236, 0}) = 0
  10. gettimeofday({1311848791, 76787}, {4294967236, 0}) = 0
  11. clock_gettime(CLOCK_MONOTONIC, {8641, 606891018}) = 0
  12. close(36)                               = 0
  13. close(34)                               = 0
  14. close(35)                               = 0
  15. close(28)                               = 0
  16. close(29)                               = 0
  17. close(30)                               = 0
  18. close(31)                               = 0
  19. close(32)                               = 0
  20. close(33)                               = 0
  21. close(27)                               = 0
  22. gettimeofday({1311848791, 78629}, {4294967236, 0}) = 0
  23. gettimeofday({1311848791, 78669}, {4294967236, 0}) = 0
  24. gettimeofday({1311848791, 78697}, {4294967236, 0}) = 0
  25. gettimeofday({1311848791, 78745}, {4294967236, 0}) = 0
  26. gettimeofday({1311848791, 79013}, {4294967236, 0}) = 0
  27. gettimeofday({1311848791, 79258}, {4294967236, 0}) = 0
  28. gettimeofday({1311848791, 79389}, {4294967236, 0}) = 0
  29. gettimeofday({1311848791, 79509}, {4294967236, 0}) = 0
  30. --- SIGSEGV (Segmentation fault) @ 0 (0) ---
  31. +++ killed by SIGSEGV +++
  32. Segmentation fault
  33.  
  34.  
  35. ============script start ==============
  36.  
  37.  
  38. //rip off of netsniff.js in phantomjs examples
  39. var report =
  40. {
  41.     consoleLog:'',
  42.     redirectTotal:0,
  43.     requestTotal:0,
  44.     resourceIssues:'1',
  45.     har:null,
  46.     showHarOnError:true,
  47.    
  48.     console : function(msg)
  49.     {
  50.         this.consoleLog += msg + "\n";
  51.     },
  52.    
  53.    
  54.  
  55.     startLoad : function()
  56.     {
  57.         var d = new Date();
  58.         this.startTime = d.getTime();
  59.     },
  60.    
  61.  
  62.     endLoad : function()
  63.     {
  64.         var d = new Date();
  65.         this.endTime = d.getTime();
  66.     },
  67.    
  68.  
  69.     build : function(page)
  70.     {
  71.         this.page = page;sc
  72.         this._buildData();
  73.         if (this.resourceIssues)
  74.         {
  75.             if (this.showHarOnError)
  76.             {
  77.                 this.har = createHAR(page.address, page.title, page.startTime, page.resources);
  78.             }
  79.         }
  80.     },
  81.    
  82.  
  83.     _buildData : function()
  84.     {
  85.         var redirs = 0;
  86.         var requestCount = 0;
  87.         var problems = '';
  88.  
  89.         this.page.resources.forEach(function (res)
  90.         {
  91.             httpStatus = res.endReply.status;
  92.             requestCount++;
  93.             if (httpStatus == 301 || httpStatus == 302)
  94.             {
  95.                 redirs++;
  96.             }
  97.             else if (httpStatus<200 || httpStatus > 299)
  98.             {
  99.                 if (httpStatus == null) httpStatus = 'Unknown';
  100.                 problems += httpStatus+': '+res.request.url+"\n";
  101.             }
  102.         });
  103.  
  104.         this.redirectTotal = redirs;
  105.         this.requestTotal = requestCount;
  106.         this.resourceIssues = problems;
  107.     },
  108.    
  109.  
  110.     print : function()
  111.     {
  112.         console.log('Page: ' + this.page.address);
  113.         console.log('Load time: ' + (this.endTime - this.startTime) + 'ms');
  114.         console.log('Total requests: ' + this.requestTotal);
  115.         console.log('Total redirects: ' + this.redirectTotal);
  116.         if (this.resourceIssues)
  117.         {
  118.             console.log('Resource Problems');
  119.             console.log(this.resourceIssues);
  120.         }
  121.         if (this.consoleLog)
  122.         {
  123.             console.log('Console');
  124.             console.log(this.consoleLog);
  125.         }
  126.         if (this.har)
  127.         {
  128.             console.log('HAR');
  129.             console.log(JSON.stringify(this.har, undefined, 4));
  130.         }
  131.     }
  132. }
  133.  
  134.  
  135. printR = function(obj, depth)
  136. {
  137.     var breakString = '\n';
  138.     var result = '';
  139.     depth = depth ? depth : 0;
  140.  
  141.     if (obj.constructor)
  142.     {
  143.         for(var k in obj)
  144.         {
  145.             for(var l = 0; l < depth; l++)
  146.             {
  147.                 result+=' ';
  148.             }
  149.            
  150.             if((obj[k]!=null) && (obj[k].constructor == Array|| obj[k].constructor == Object))
  151.             {
  152.                 result += k+"=>"+typeof(obj)+"("+breakString+"" + this.printR(obj[k], depth+1)+")"+breakString;
  153.             }
  154.             else
  155.             {
  156.                 result += k+"=>"+obj[k]+breakString;
  157.             }
  158.         }
  159.     }
  160.     else
  161.     {
  162.         result = obj + breakString;
  163.     }
  164.     return result;
  165. }
  166.  
  167.  
  168. if (!Date.prototype.toISOString)
  169. {
  170.     Date.prototype.toISOString = function ()
  171.     {
  172.         function pad ()
  173.         {
  174.             return n < 10 ? '0' + n : n;
  175.         }
  176.        
  177.         function ms ()
  178.         {
  179.             return n < 10 ? '00'+ n : n < 100 ? '0' + n : n
  180.         }
  181.        
  182.         return this.getFullYear() + '-' +
  183.             pad(this.getMonth() + 1) + '-' +
  184.             pad(this.getDate()) + 'T' +
  185.             pad(this.getHours()) + ':' +
  186.             pad(this.getMinutes()) + ':' +
  187.             pad(this.getSeconds()) + '.' +
  188.             ms(this.getMilliseconds()) + 'Z';
  189.     }
  190. }
  191.  
  192.  
  193. function createHAR(address, title, startTime, resources)
  194. {
  195.     var entries = [];
  196.  
  197.     resources.forEach(function (resource)
  198.     {
  199.         var request = resource.request,
  200.             startReply = resource.startReply,
  201.             endReply = resource.endReply;
  202.  
  203.         if (!request || !startReply || !endReply)
  204.         {
  205.             return;
  206.         }
  207.  
  208.         entries.push(
  209.         {
  210.             startedDateTime: request.time.toISOString(),
  211.             time: endReply.time - request.time,
  212.             request:
  213.             {
  214.                 method: request.method,
  215.                 url: request.url,
  216.                 httpVersion: "HTTP/1.1",
  217.                 cookies: [],
  218.                 headers: request.headers,
  219.                 queryString: [],
  220.                 headersSize: -1,
  221.                 bodySize: -1
  222.             },
  223.             response:
  224.             {
  225.                 status: endReply.status,
  226.                 statusText: endReply.statusText,
  227.                 httpVersion: "HTTP/1.1",
  228.                 cookies: [],
  229.                 headers: endReply.headers,
  230.                 redirectURL: "",
  231.                 headersSize: -1,
  232.                 bodySize: startReply.bodySize,
  233.                 content:
  234.                 {
  235.                     size: startReply.bodySize,
  236.                     mimeType: endReply.contentType
  237.                 }
  238.             },
  239.             cache: {},
  240.             timings:
  241.             {
  242.                 blocked: 0,
  243.                 dns: -1,
  244.                 connect: -1,
  245.                 send: 0,
  246.                 wait: startReply.time - request.time,
  247.                 receive: endReply.time - startReply.time,
  248.                 ssl: -1
  249.             }
  250.         });
  251.     });
  252.  
  253.     return {
  254.         log:
  255.         {
  256.             version: '1.2',
  257.             creator:
  258.             {
  259.                 name: "PhantomJS",
  260.                 version: phantom.version.major + '.' + phantom.version.minor +
  261.                     '.' + phantom.version.patch
  262.             },
  263.             pages: [
  264.             {
  265.                 startedDateTime: startTime.toISOString(),
  266.                 id: address,
  267.                 title: title,
  268.                 pageTimings: {}
  269.             }],
  270.             entries: entries
  271.         }
  272.     };
  273. }
  274.  
  275.  
  276. if (phantom.args.length === 0)
  277. {
  278.     console.log('Usage: script.js <some URL>');
  279.     phantom.exit();
  280. }
  281.  
  282. var page = new WebPage();
  283.  
  284. page.onConsoleMessage = function (msg, ln, x)
  285. {
  286.     report.console('"'+msg + '" line: ' +ln + ' file: ' + x);
  287. };
  288.  
  289. page.address = phantom.args[0];
  290. page.resources = [];
  291.  
  292.  
  293. page.onLoadStarted = function ()
  294. {
  295.     report.startLoad();
  296.     page.startTime = new Date();
  297. };
  298.  
  299. page.onResourceRequested = function (req)
  300. {
  301.     page.resources[req.id] =
  302.     {
  303.         request: req
  304.     };
  305. };
  306.  
  307. page.onResourceReceived = function (res)
  308. {
  309.     if (res.stage === 'start')
  310.     {
  311.         page.resources[res.id].startReply = res;
  312.     }
  313.    
  314.     if (res.stage === 'end')
  315.     {
  316.         page.resources[res.id].endReply = res;
  317.     }
  318. };
  319.  
  320.  
  321.  
  322. page.open(page.address, function (status)
  323. {
  324.     var har;
  325.    
  326.     if (status !== 'success')
  327.     {
  328.         console.log('FAIL to load the address '+status);
  329.     }
  330.     else
  331.     {
  332.         report.endLoad();
  333.         page.title = page.evaluate(function ()
  334.         {
  335.             return document.title;
  336.         });
  337.         report.build(page);
  338.         report.print();
  339.     }
  340.    
  341.     phantom.exit();
  342. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement