toString function (2019)
Thanks to Overcl9ck for commenting on this answer. Replacing the regular expression / /./ an empty function object still works.
var devtools = function(){}; devtools.toString = function() { this.opened = true; } console.log('%c', devtools);
regex toString (2017-2018)
Since the original asker no longer exists, and this is still an accepted answer, we add this solution for clarity. Acknowledgment author Antonin Hildebrand comments on zswang answer . This solution takes advantage of the fact that toString() not called for registered objects if the console is not open.
var devtools = /./; devtools.toString = function() { this.opened = true; } console.log('%c', devtools);
console.profiles (2013)
Update: console.profiles been removed from Chrome. This solution no longer works.
Thanks to Paul Irrish for pointing out this solution from Discover DevTools using the profiler:
function isInspectOpen() { console.profile(); console.profileEnd(); if (console.clear) console.clear(); return console.profiles.length > 0; }
window.innerHeight (2011)
This other parameter may detect the open pinned inspector after loading the page, but will not be able to detect an unsecured inspector or if the inspector was already open when the page loaded. There is also some potential for false positives.
window.onresize = function() { if ((window.outerHeight - window.innerHeight) > 100) alert('Docked inspector was opened'); }
Unsigned Oct 18 '11 at 15:02 2011-10-18 15:02
source share