Detect if Chrome DevTools are open
Here's an interesting snippet taken from the validation code in the new Discover DevTools course prepared by Google and CodeSchool (check it out, btw, it's awesome!):
function () {
console.profile();
console.profileEnd();
if(console.clear) { console.clear() };
return console.profiles.length > 0;
}
It exploits the fact that CPU profiles aren't actually run if DevTools are closed. Looks hacky but it works!
P.S. The same trick is also reported to work with Firefox+Firebug.
UPD This no longer works starting from Chrome 29 due to removal of console.profiles
from window.console API. Related Chromium issue: https://codereview.chromium.org/15816002
Written by Dmitry Pashkevich
Related protips
9 Responses
Hah, someone brought it even this far! :) Thanks)
It is not support Chrome > 29
Yup, it no longer works as console.profiles
was removed. See https://codereview.chromium.org/15816002
devtools-detect* works with the latest Chrome/Safari/Firefox devtools and Firebug.
@sindresorhus Hehe, back to the window height method :) Thanks for sharing!
Don't use window height, there is a better way.
Article:
http://blog.guya.net/2014/06/20/how-to-know-when-chrome-console-is-open/
Demo:
http://guya.net/chrome/dev_tools/
@guya it's amazing how this topic is still alive! Interesting approach :) My results are unstable though - the text keeps changing between 'Opened' and 'Closed', all I do is move the mouse around.
all these above met