3 ms·
I'm still missing: - Freezing of all DOM events after X seconds. - Stopping all timers. - Showing all DOM/timer events in the console. - Recording a DOM tre
by amelius 9y ago
I'm still missing:
- Freezing of all DOM events after X seconds.
- Stopping all timers.
- Showing all DOM/timer events in the console.
- Recording a DOM tree, and diffing it with a later recording.
- Jakob 9y agoRe stopping timers: The timer id is afaik just a steadily increasing number starting at 1 which is returned by setTimeout() so you can iterate through them, e.g. to stop all: for (let i=1; i++; i<=setTimeout('')) { clearTimeout(i); } Though that’s an implementation detail which could change in the future since the spec seems to not enforce it.
- aiham 9y agoThat happens to be how common browsers have implemented it but the spec does not guarantee it: > Let handle be a user-agent-defined integer that is greater than zero that will identify the timeout to be set by this call in the list of active timers. https://dev.w3.org/html5/spec-preview/timers.html https://dev.w3.org/html5/spec-preview/timers.html Edit: Just noticed your edit.
- dspillett 9y agoIt might be safer to loop in reverse: for (let i=setTimeout(''); i--; i>=0) { clearTimeout(i); } That way if the optimiser decides not to optimise such that the termination condition doesn't call setTimeout() every iteration, you don't end up with an infinite loop because the result of setTimeout('') ends up incrementing in-step with the value of i. That advantage of browser support, assuming it was internal support and not tacked on in the dev-tools, would be that they could implement a toggle so the timers can be reactivated after you've finished checking what they were getting in the way of. [note: interval timers may need to be considered as well as timeout timers, unless they use the same ID counter with not type checking so either can be turned off by either clearTimeout() or clearInterval() - again that may be an implementation detail that varies between browsers]
- Jakob 9y agoGood catch on the reverse loop, you’re right.
- blauditore 9y ago> Freezing of all DOM events after X seconds Using the debugger for this has been helpful for me in some cases: Hit F8 (pause JS execution) when you want to freeze the state, and some browsers stop any kind of operation, inluding CSS hover states and so on. I'm usually working in either Firefox or Chrome, so one of them should work that way (not sure which). You should just make sure dev tools are open, and maybe be on the debugger tab.
- TeMPOraL 9y agoThanks for the tip! F8 doesn't seem to work on my Firefox, but I found the "Pause" feature on the Debugger tab. IMO this should be a top-level user feature. Almost every day I have situations in which wish I'd be able to quickly pause JS execution on a website.