How to detect if browser console / inspector is *open*?

firebug, google-chrome, javascript, web-inspector, webkit

Solution

If you are willing to accept an interference for the user, you could use the debugger statement, as it is available in all major browsers.

Side note: If the users of your app are interested in console usage, they're probably familiar with dev tools, and will not be surprised by it showing up.

In short, the statement is acting as a breakpoint, and will affect the UI only if the browser's development tools is on.

Here's an example test:

<body>
<p>Devtools is <span id='test'>off</span></p>
<script>
  var minimalUserResponseInMiliseconds = 100;
  var before = new Date().getTime();
  debugger;
  var after = new Date().getTime();
  if (after - before > minimalUserResponseInMiliseconds) { // user had to resume the script manually via opened dev tools 
    document.getElementById('test').innerHTML = 'on';
  }
</script>

</body>

DISCLAIMER: I initially published this exact answer for this possibly duplicate question

Problem

What's the best way to determine if the user has the browser console (i.e. firebug, webkit inspector, Opera dragonfly) open? (I.e. I'm not interested in merely detecting the presence of the `console` object in script. I want to know when the user has actually opened the debugger panel. Ideally across the major browsers (IE/Safari/Chrome/Firefox... and even mobile browsers if possible)

Original source

Related problems