monitor utility
tl;dr: monitor(fetch)
can be used in the context of DevTools to print all fetch requests. More so, monitor(setInterval)
and monitor(setTimeout)
can be used to detect symptoms of bad coding.
monitor(fetch) // prints the URLs (i.e. constructor arguments) of all outgoing requests to the console
monitor(setInterval) // tracks new intervals
monitor(setTimeout) // tracks new timeouts
An infinite stream of new setTimeout
is a symptom of bad coding, which should either be replaced with one setInterval
or removed altogether if design permits.
To quickly assess the impact of setInterval
and setTimeout
on the CPU, you can use the following hacky code which clears all intervals and timeouts on the page under the assumption that the last function call returns the highest interval and timeout identifiers–a correct assumption.
for (let i = 0; i <= setInterval(function(){}, 1e3); ++i) {
clearInterval(i);
}
for (let i = 0; i <= setTimeout(function(){}, 1e3); ++i) {
clearTimeout(i);
}