Skip to content

Instantly share code, notes, and snippets.

@NullDev
Last active November 26, 2020 16:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NullDev/42f7806ba667b27bb5256fca8bf7ea2f to your computer and use it in GitHub Desktop.
Save NullDev/42f7806ba667b27bb5256fca8bf7ea2f to your computer and use it in GitHub Desktop.
Hack to detected whether the developer tools of the browser are open

UPDATE:

This does not work on recent versions of Chrome and FireFox!


This is a hack to detected whether the developer tools of the browser are open or closed. It also works if the development tools are not docked.

HTML Code:

status: <div id="c"></div>

JavaScript Code:

var isOn;

var t1 = new Image();
var t2 = new Image();

Object.defineProperty(t1, "id", {
    get:function() {
        isOn = true;
        throw	new Error("");
    }
});

t2.__defineGetter__("id", function(){ isOn = true; });

setInterval(function() {
    isOn = false;
    console.dir(t1);
    console.log(t2);
    console.clear();
    document.getElementById("c").innerHTML = isOn ? "on" : "off";
}, 1000);

JSFiddle Demo: https://jsfiddle.net/1dojo5er/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment