Khachatur
Khachatur

Reputation: 989

How to detect if browser inspector window is open?

Is it possible to detect if browser's inspector window is open?

We tried to detect it by comparing the window.outerHeight and window.innerHeight, but this does not work when inspector window is not attached to browser (is floating).

window.outerHeight - window.innerHeight > 100

Thanks, Khachatur

Upvotes: 1

Views: 1646

Answers (1)

Yasin Uslu
Yasin Uslu

Reputation: 546

I'm looking for a more clear way to do it but here is one hacky way i'm using currently:

Normally the time spent between two new Date() calls is less than 100ms. So if you put debugger between them, user will at least spend more than 100ms there and we'll know that they opened the console.

Here is a simple implementation:

function isConsoleOpen() {
  var startTime = new Date();
  debugger;
  var endTime = new Date();

  return endTime - startTime > 100;
}

$(function() {
  $(window).resize(function() {
    if(isConsoleOpen()) {
        // do something
    }
  });
});

Upvotes: 3

Related Questions