Skip to content

Instantly share code, notes, and snippets.

@andrewjjenkins
Last active March 11, 2022 14:13
Show Gist options
  • Save andrewjjenkins/84fa01006eacba116796 to your computer and use it in GitHub Desktop.
Save andrewjjenkins/84fa01006eacba116796 to your computer and use it in GitHub Desktop.
Ways to hack setTimeout and setInterval to help debug lingering timers.
(function () {
var oldSetTimeout = GLOBAL.setTimeout;
GLOBAL.setTimeout = function () {
var e = new Error('Just for stack trace');
console.log('New timeout registered from %s', e.stack);
return oldSetTimeout.apply(this, arguments);
};
var oldSetInterval = GLOBAL.setInterval;
GLOBAL.setInterval = function () {
var e = new Error('Just for stack trace');
console.log('New interval registered from %s', e.stack);
return oldSetInterval.apply(this, arguments);
}
})();
setTimeout(function () {
console.log('Timeout fired');
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment