3

I found in the tutorial on codeschool.com (discover-devtools: http://discover-devtools.codeschool.com/chapters/1/challenges/3) that there is possibility to check if Chrome Developer tools are open? How to check it's state/get event of (cmd+alt+i) pressed?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
static
  • 8,126
  • 15
  • 63
  • 89

2 Answers2

4

google is your friend here

function isInspectOpen()
{
    console.profile(); 
    console.profileEnd(); 
    if (console.clear) console.clear();
    return console.profiles.length > 0;
}

from This Question

this function will return true is the user has the developer tools open

edit

in response to your comment

$('#header').click(alert(isInspectOpen()))

is not properly formatted jQUery , try:

$('#header').click(function(){
   alert(isInspectOpen());
});
Community
  • 1
  • 1
Scott Selby
  • 9,420
  • 12
  • 57
  • 96
  • hm, calling the `isInspectOpen()` works fine :) (i.e. it reterns `true`). But if I set `setTimeout('alert(isInspectOpen())', 10000)` and close the DevTools still after 10 seconds it alerts `true`. Any idea why so? How could I test the function another way? – static May 27 '13 at 02:00
  • don't use a timeout to test this , try just testing with the tools open , then with it closed – Scott Selby May 27 '13 at 02:02
  • any Idea, how to call the `alert(isInspectOpen())` (or another way of notification, e.g. change text of some `div`) with closed DevTools? `$('#header').click(alert(isInspectOpen()))` doesn't work for me neither – static May 27 '13 at 02:08
  • 2
    Please note that we removed dangerous console.profiles from Blink: https://src.chromium.org/viewvc/blink?revision=151136&view=revision so the trick won't work for Chromium anymore. – Yury Semikhatsky Jun 03 '13 at 08:47
-2

You could try a logging framework like log4js or similar. http://log4js.berlios.de/links.html#other

Your code would have less dependency on a specific browser.

  • to log smth. I need to find out how this smth. work (shows its work in browser e.g. which event does it fire/which state does it change), and how to do it that was a question ;) of course log4js is a good thing to show the event is happened – static May 27 '13 at 01:54