ajaxReqYLT.js 1.0 KB

123456789101112131415161718192021222324252627282930
  1. /**
  2. * Analyzes AJAX requests
  3. */
  4. /* global window: true */
  5. exports.version = '0.2.a';
  6. exports.module = function(phantomas) {
  7. 'use strict';
  8. phantomas.setMetric('ajaxRequests'); // @desc number of AJAX requests
  9. phantomas.setMetric('synchronousXHR'); // @desc number of synchronous
  10. phantomas.on('init', function() {
  11. phantomas.evaluate(function() {
  12. (function(phantomas) {
  13. phantomas.spy(window.XMLHttpRequest.prototype, 'open', null, function(result, method, url, async) {
  14. phantomas.incrMetric('ajaxRequests');
  15. phantomas.addOffender('ajaxRequests', '<%s> [%s]', url, method);
  16. if (async === false) {
  17. phantomas.incrMetric('synchronousXHR');
  18. phantomas.addOffender('synchronousXHR', url);
  19. phantomas.log('ajaxRequests: synchronous XMLHttpRequest call to <%s>', url);
  20. }
  21. }, true);
  22. })(window.__phantomas);
  23. });
  24. });
  25. };