* Fix bug in spying function * New rule Synchronous XHR * Add the synchronousXHR rule to the dashboard
30 lines
1.0 KiB
JavaScript
30 lines
1.0 KiB
JavaScript
/**
|
|
* Analyzes AJAX requests
|
|
*/
|
|
/* global window: true */
|
|
|
|
exports.version = '0.2.a';
|
|
|
|
exports.module = function(phantomas) {
|
|
'use strict';
|
|
|
|
phantomas.setMetric('ajaxRequests'); // @desc number of AJAX requests
|
|
phantomas.setMetric('synchronousXHR'); // @desc number of synchronous
|
|
|
|
phantomas.on('init', function() {
|
|
phantomas.evaluate(function() {
|
|
(function(phantomas) {
|
|
phantomas.spy(window.XMLHttpRequest.prototype, 'open', null, function(result, method, url, async) {
|
|
phantomas.incrMetric('ajaxRequests');
|
|
phantomas.addOffender('ajaxRequests', '<%s> [%s]', url, method);
|
|
|
|
if (async === false) {
|
|
phantomas.incrMetric('synchronousXHR');
|
|
phantomas.addOffender('synchronousXHR', url);
|
|
phantomas.log('ajaxRequests: synchronous XMLHttpRequest call to <%s>', url);
|
|
}
|
|
}, true);
|
|
})(window.__phantomas);
|
|
});
|
|
});
|
|
}; |