iktwug
Last Updated: February 25, 2016
·
7.208K
· dpashkevich

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

8 Responses
Add your response

5115
5117

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

over 1 year ago ·
9327

It is not support Chrome > 29

over 1 year ago ·
9330

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

over 1 year ago ·
9920

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

over 1 year ago ·
9921

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

over 1 year ago ·
15570
over 1 year ago ·
15571

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