Skip to content

Instantly share code, notes, and snippets.

@dawsontoth
Created March 15, 2018 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dawsontoth/7285ae367a32206db93e238b49e172d9 to your computer and use it in GitHub Desktop.
Save dawsontoth/7285ae367a32206db93e238b49e172d9 to your computer and use it in GitHub Desktop.
function getStackTrace() {
let obj = {};
Error.captureStackTrace(obj, getStackTrace);
return obj.stack;
}
window.activeFuncs = {};
window.originalSetTimeout = window.setTimeout;
window.originalClearTimeout = window.clearTimeout;
window.originalSetInterval = window.setInterval;
window.originalClearInterval = window.clearInterval;
window.setTimeout = function(func, delay) {
let id,
wrapper = () => {
delete window.activeFuncs['timeout' + id];
func.apply(window);
};
id = window.originalSetTimeout(wrapper, delay);
if (func) {
window.activeFuncs['timeout' + id] = getStackTrace();
}
return id;
};
window.clearTimeout = function(timerID) {
window.originalClearTimeout(timerID);
delete window.activeFuncs['timeout' + timerID];
};
window.setInterval = function(func, delay) {
let id = window.originalSetInterval(func, delay);
if (func) {
window.activeFuncs['interval' + id] = getStackTrace();
}
return id;
};
window.clearInterval = function(intervalID) {
delete window.activeFuncs['interval' + intervalID];
return window.originalClearInterval(intervalID);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment