iktwug
Last Updated: February 25, 2016
·
4.986K
· dpashkevich
D42a7264714dee5006b9c99d2567a320

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

Say Thanks
Respond

8 Responses
Add your response

5115
F46c21deea19955ae03c8f28aa6b9f99
over 1 year ago ·
5117
D42a7264714dee5006b9c99d2567a320

Hah, someone brought it even this far! :) Thanks)

over 1 year ago ·
9327
C58020fd121385a6ee0ba7ef6985d3bf

It is not support Chrome > 29

over 1 year ago ·
9330
D42a7264714dee5006b9c99d2567a320

Yup, it no longer works as console.profiles was removed. See https://codereview.chromium.org/15816002

over 1 year ago ·
9920
D36a92237c75c5337c17b60d90686bf9

devtools-detect* works with the latest Chrome/Safari/Firefox devtools and Firebug.

over 1 year ago ·
9921
D42a7264714dee5006b9c99d2567a320

@sindresorhus Hehe, back to the window height method :) Thanks for sharing!

over 1 year ago ·
15570
Icon 03 normal
over 1 year ago ·
15571
D42a7264714dee5006b9c99d2567a320

@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.

over 1 year ago ·