Created
November 22, 2021 10:23
-
-
Save heapwolf/e5a2a80a2adb802855c4bf051e6818f6 to your computer and use it in GitHub Desktop.
find misbehaving or unwanted timeouts and intervals
This file contains hidden or 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
window._setTimeout = window.setTimeout | |
window._clearTimeout = window.clearTimeout | |
window._setInterval = window.setInterval | |
window._clearInterval = window.clearInterval | |
window.activeTimers = {} | |
window.setTimeout = (func, delay) => { | |
const id = window._setTimeout(() => { | |
func() | |
window.clearTimeout(id) | |
}, delay) | |
window.activeTimers[id] = new Error().stack | |
return id | |
} | |
window.setInterval = (func, delay) => { | |
const id = window._setInterval(() => { | |
func() | |
window.clearInterval(id) | |
}, delay) | |
window.activeTimers[id] = new Error().stack | |
return id | |
} | |
window.clearTimeout = (timerId) => { | |
delete window.activeTimers[timerId] | |
window._clearTimeout(timerId) | |
} | |
window.clearInterval = (timerId) => { | |
delete window.activeTimers[timerId] | |
window._clearInterval(timerId) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment