Improve scroll bottlenecks rules

This commit is contained in:
Gaël Métais
2015-05-07 17:10:01 +02:00
parent 8c79f39389
commit f8f792645b
5 changed files with 40 additions and 12 deletions
@@ -41,7 +41,7 @@ exports.module = function(phantomas) {
// count window.addEventListener('scroll', ...) - issue #508
if (eventType === 'scroll' && (path === 'window' || path === '#document')) {
phantomas.incrMetric('eventsScrollBound');
phantomas.addOffender('eventsScrollBound', 'bound by %s', phantomas.getBacktrace());
phantomas.addOffender('eventsScrollBound', 'bound by %s on %s', phantomas.getBacktrace(), path);
}
}
@@ -67,4 +67,16 @@ exports.module = function(phantomas) {
})(window.__phantomas);
});
});
phantomas.on('report', function() {
phantomas.evaluate(function() {
(function(phantomas) {
// Check if a window.onscroll function is defined
if (typeof(window.onscroll) === "function") {
phantomas.incrMetric('eventsScrollBound');
phantomas.addOffender('eventsScrollBound', 'bound by %s on %s', '', 'window.onscroll');
}
}(window.__phantomas));
});
});
};
@@ -32,13 +32,7 @@ exports.module = function(phantomas) {
});
window.dispatchEvent(evt);
// 3. onscroll()
if (window.onscroll) {
phantomas.pushContext({
type: 'window.onscroll'
});
window.onscroll();
}
// No need to call window.onscroll(), it's called by the scroll event on window
} catch(e) {
phantomas.log('ScrollListener error: %s', e);