Last active
March 11, 2022 14:13
-
-
Save andrewjjenkins/84fa01006eacba116796 to your computer and use it in GitHub Desktop.
Ways to hack setTimeout and setInterval to help debug lingering timers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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