Andrej Andrej - 1 year ago 142
Javascript Question

Find out whether Chrome console is open

I am using this little script to find out whether Firebug is open:

if (window.console && window.console.firebug) {
//is open

And it works well. Now I was searching for half an hour to find a way to detect whether Google Chrome's built-in web developer console is open, but I couldn't find any hint.


if (window.console && {
//is open

doesn't work.


So it seems that it is not possible to detect whether the Chrome console is open. But there is a "hack" that works, with some drawbacks:

  • will not work when console is undocked

  • will not work when console is open on page load

So, I am gonna choose Unsigned´s answer for now, but if some1 comes up with a brilliant idea, he is welcome to still answer and I change the selected answer! Thanks!

Answer Source

Thanks to Paul Irish for pointing out this solution from Discover DevTools, using the profiler:

function isInspectOpen()
    if (console.clear) console.clear();
    return console.profiles.length > 0;

Update: console.profiles has been removed from Chrome.

This other option can detect the docked inspector being opened, after the page loads, but will not be able to detect an undocked inspector, or if the inspector was already open on page load. There is also some potential for false positives.

window.onresize = function()
    if ((window.outerHeight - window.innerHeight) > 100)
        alert('Docked inspector was opened');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download