Who called window.scrollTo(...)?

Chrome's Event Listener Breakpoints allow you to break and inspect scroll event listeners, but how do you find out what part of your application code invoked window.scrollTo?

Paste the following snippet in your browser's console while your application is active and it will print the stack trace each time your code invokes window.scrollTo to scroll the page. If you would like to examine the code in with a breakpoint, uncomment the line that reads debugger and the execution would stop when window.scrollTo is called.

var originalScroll = window.scrollTo;

window.__defineGetter__('scrollTo', function() {  
    return function(x, y) {
        console.log('scrollTo invoked: ' + new Error().stack);
        // Uncomment next line if you'd like to examine the stack
        // debugger;
        originalScroll(x, y);
    }
});
comments powered by Disqus