A List of Chrome DevTools Tips and Tricks
flaviocopes.com
flaviocopes.com
javascript:(function(){var t=['div','header','nav','main','section','footer','table','th','td','tr','form','fieldset','label','img','address','blockquote','h1','h2','h3','h4','h5','h6','p','pre','dd','dl','dt','ol','ul','li'];var c=['blue','blue','blue','blue','blue','blue','teal','teal','teal','teal','orange','orange','orange','red','red','red','red','red','red','red','red','red','red','green','green','green','green','green','green','yellow'];for (var i in t){var l=document.getElementsByTagName(t[i]);var j=0,e;while(e=l.item(j++)){e.style.outline='solid '+c[i]+' 1px';}}})();
Add console.log statements anywhere in your code by adding "conditional breakpoints" and writing a console.log in the breakpoint expression.
Very useful if you’ve a hot reloading pipeline.
If only that worked. Sure, it sets the state from a CSS perspective, so you can test things like styles. But many popular JavaScript libraries simply ignore it (looking at you JQuery UI) because of how they hook those events.
For example I've seen many that set several attributes when you mouse over (e.g. data-x, additional class, etc), so if you want to test it the only way right now is to mouse over for real and then do this keyboard voodoo to cut the hovered element into the clipboard, and then after you move your mouse away paste it back onto the page.
You might say "Just call .trigger() from the console!" but the reality is there are several different ways to hook (particularly when a library supports both touch and mouse). Plus some intermingle the CSS hover selector AND Javascript events.
- 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.
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.> 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
Edit: Just noticed your edit.
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]
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.
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.
And for example the CSS grid tools are something I haven't seen in chrome yet and they work very well in FF. On the other hand, the Serviceworker tool set is much better in chrome than in FF.