24

Is there any way to detect whether the Chrome Inspect Element window is running?

For example if the user clicks "Inspect Element" in Chrome, the window shows a Hello World alert.

Is that possible?

3
  • hmmm, you can deinfately monitor a "Right Click", although I doubt you can see what option they pick. So you could change the behavior of the right click action and maybe show your box then? Sep 23, 2011 at 10:17
  • yes Abe I know that I can change the right click. but really i want to monitor if inspect element is running and doing anything. for example running a javascript function. Sep 23, 2011 at 10:30
  • See Find out whether Chrome console is open for a working solution. Oct 8, 2013 at 19:53

2 Answers 2

33

UPDATE This no longer works. The property console.profiles has been removed in Chrome 29.

The only solution that's left is checking the difference between window.outerHeight and window.innerHeight as suggested by @Gerben. There is a library devtools-detect based on this method which adds devtoolschange to the window object.

Alternatively, there is an effort in progress to create a Chrome extension using a more robust detection method, see this Google Group.


Here's how they check if DevTools are open in the first challenge of Discover DevTools interactive course:

function () {
    console.profile(); 
    console.profileEnd(); 
    if(console.clear) { console.clear() };
    return console.profiles.length > 0;
}
9
14
window.onresize = function(){
 if((window.outerHeight-window.innerHeight)>100)
   alert('hello');
}

In action: http://jsbin.com/ediquk/

Note that it seems like the resize event gets fired twice, so you should check whether you alerted the use already.

9
  • Works in firefox too, but you need to put the alert inside in timeout, because otherwise the layout freezes. See jsbin.com/ediquk/3
    – Gerben
    Sep 23, 2011 at 14:08
  • 1
    Is it correct that this only works when the window is docked?
    – pimvdb
    Sep 23, 2011 at 16:15
  • 5
    Yes. Only when docked. I don't see how you can detect a undocked inspector.
    – Gerben
    Sep 23, 2011 at 16:23
  • 3
    But this also fires whenever the window is resized... which happens a lot more often than opening the inspector.
    – sachleen
    Mar 24, 2013 at 3:23
  • 2
    I suspect this would also be triggered by someone with multiple toolbars, or other extensions which modify the browser's UI. The Chrome bookmark toolbar, for instance, counts against this calculation. Jun 28, 2013 at 22:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.