

Chrome Inspector Detector - afschwartz
http://adamschwartz.co/chrome-inspector-detector
Detect whether the Chrome Inspector is open and docked, open and in a separate window, or closed.
======
skore
This ushers in a new era of annoying and pointless "This website prevents
right clicks" popups.

Just the other day I said to my coworker everybody, by now, knew how to use
firebug/inspector (he disagreed and, being in support, he does see more
suffering than I do) - we were looking at a client site that had a _javascript
obfuscation of the html source_.

It's like this grand battle stage of the worlds tiniest violins.

------
zackbloom
A developer could use this to kill all the DOM nodes on the page when the
console was opened. This might be the next generation of:

    
    
        img.onclick="javascript:function(){alert('Don\'t steal!');return false}"

~~~
chadscira
but then we could just ensure that this line gets called first

    
    
      console.profile = console.profileEnd = function () {};

~~~
jQueryIsAwesome
Not only that, you have to save a reference to the parts of the console that
you want to use just in case they attempt to destroy those.

    
    
        var c = console
        var l = console.log
        var log = function(){ l.apply(c, arguments) }
    

Now they can't break the console from working with stuff like:

    
    
        console.log = function(){}

~~~
chadscira
well in that case i guess you could always do

    
    
      var _console = console;
      console = undefined;

~~~
jQueryIsAwesome
You may break something by breaking it yourself, like naive code: if
(window.chrome) console.log("dev forgot to delete this"))

------
raldi
How do I press ⌘ on Linux?

~~~
cooldeal
It's becoming increasing clear that on HN you're a second class citizen if you
don't use Chrome on a Mac and develop on RoR.

~~~
yareally
I think you're confusing popularity with exclusion. Doesn't bother me or make
me feel like an outsider because I use Opera as my primary browser and mostly
Linux/Windows PCs. It's all a frame of mind and such statements are not really
needed on HN because it's really not true.

I actually read the Rails articles quite a bit just because I like to not
limit what I do or know to a small subset, even if I do not actively use it.
Software does not come to other platforms unless one ports it, after all :)

Disclaimer: not a RoR developer, but I do use Python.

~~~
bjxrn
One of the main reasons I switched away from Opera was because so many neat
little projects made with new HTML5 technologies would not work in Opera. This
goes both for small side projects as well as business ventures.

I do understand the lack of support for Opera, with it having just a tiny
market share in the US, but it still is a form of exclusion.

I'm glad Opera is switching to Webkit & V8 because besides the many websites
breaking I found Opera to be much nicer to use than Chrome or Firefox.

~~~
yareally
Yeah, I'm kind of used to Opera not always working with everything that it
does not phase me anymore after 10 years of use. If it's something I need to
see Opera won't render, I either hack around it in Opera or just open
Chromium. I also understand that Chrome is popular and many of the projects on
hn are hacks put together for the developer and to show us what they do for
fun and learning versus projects made for the masses, so I give leadway when
things don't always work. Sometimes it's just a simple mistake and the
developer is glad to fix it (like he did here [updated in the linked article]
for anyone that did not have an Apple keyboard). Although we all have our
favorites, most of us like to be accommodating if it does not require hours of
additional personal time.

I have all the large browsers installed though for web development, so I can
always open something else if needed. I just can't move away from Opera,
because of all the native power features I would have to give up or find
extensions that may or may not work exactly the same and have future support
by their developers. I can say though that unlike some sites I frequented in
the past (such as slashdot), I have never had anyone on HN make snarky remarks
about me being an Opera user, which is refreshing and quite the opposite of
being excluded.

I do think Webkit will help Opera in the long run as well, as long as they do
not use it as a reason to throw away their long term commitment they have
stuck with to keep backwards support for features and user interface elements.
If they ditch most of that on the notion they can just tell users to use
Chrome extensions, I would be truly sadden and have little reason to use Opera
anymore. I'd probably end up forking Chromium in attempt to make it function
like Opera once did and hope other former Opera users would help contribute
via code commits along the way. That's just worst case thinking and I'm going
to stay optimistic for now :)

Not to get too off track though from the discussion, but the OP (above my
original reply) is correct in that there is quite a bit of RoR and Apple
upvoted articles (if that was his point), but there are many others in a
variety of topics. Perhaps not everyone is as interested as I am about
broadening my knowledge of various technologies whether I use them or not, but
I think many of us on HN are. Since I don't follow RoR or Apple news that
much, I don't mind seeing it, because it at least keeps me exposed to
information I don't follow actively on my own.

------
jsonmez
Oh, the evil things I could do with this to coworkers who try to debug my
Javascript code. Oh, the evil things I could do...

~~~
afschwartz
It may not be clear, but the main use case for this app is not to harm
someone, but to aid in development. Perhaps you're making a game and want to
pause it or show wireframes when toggling the inspector. Or perhaps you're a
designer and you want to show a grid layout whenever you're inspecting
elements.

~~~
jsonmez
Or perhaps you want to make it so that when someone tries to inspect a DOM
element, the element turns into a youtube video of Rick Astley singing "Never
Gonna Give You Up." --Just sayin...

------
afschwartz
Thanks for reporting all of the issues.

I'll continue to improve and update [https://github.com/adamschwartz/chrome-
inspector-detector/is...](https://github.com/adamschwartz/chrome-inspector-
detector/issues) with the issues reported here. Thanks.

------
etjossem
Could be an intriguing way to detect other developers visiting the site and
communicate with them. Last time I checked, the front page of
<https://vimeo.com> was using the inspector console as a recruiting tool.

~~~
tomkin
Great idea!

------
DomreiRoam
It's a nice demo and congratulation to Adam but I wonder if I m the only one
that doesn't like that the browser allows this detection. I mean accessing the
log is one thing but shouldn't this be this unreachable fro; the sandbox?

------
just2n
Defeated:

    
    
        javascript:clearTimeout(setTimeout(function(){}, 1) - 1);

~~~
jQueryIsAwesome
But what if he starts using setInterval? A more global solution is to: Open
the "sources" panel, click on "Event Listener Breakpoints", then click "set
Timer" and just delete the lines where it is calling the detector function.

~~~
arcatek

        chrome.inspector.detector=function(){return{}};

~~~
jQueryIsAwesome
and what if he stops putting a public reference to the "detector" method?,
read previous answer again.

~~~
brokenparser
Use Firefox.

------
patejam
Doesn't work exclusively with the Chrome Inspector. Having the downloads bar
at the bottom sets this off as well, for example.

~~~
Scene_Cast2
Having a non-standard window zoom also sets this off.

~~~
afschwartz
I've made the docked/undocked an experimental feature since it was causing the
issues you were seeing. Please let me know if you're still seeing any issues
with false positives for open.

~~~
goldfeld
From quickly checking the code before the reports, you seemed to be first
checking for the height thing, and prematurely returning, before running any
profiling. Wouldn't you avoid these problems if you first checked for the
surer stuff, and then checked the height?

~~~
afschwartz
@goldfeld absolutely. However, the profiler check mucks up the console output
so I was hoping to use it as a fallback. For now I've made it experimental and
will keep it that way until we can resolve the issues you pointed out.
(<https://github.com/adamschwartz/chrome-inspector-detector/is...>)

------
twinn
This is cool, I used the same technique in the discover-
devtools.codeschool.com course for the first challenge.

~~~
afschwartz
Yup! We credited <http://stackoverflow.com/a/15567735/131898> in the README
([https://github.com/adamschwartz/chrome-inspector-
detector/bl...](https://github.com/adamschwartz/chrome-inspector-
detector/blob/master/README.md)) which in turn credits you. :)

------
ryiytrye
Works fine to detect the inspection window, but a false positive (as "open and
docked") if I change Chrome window state from maximised to normal.

------
theoutlander
On Windows, use F12 instead of Ctrl + Shift + I

------
homakov
I was hoping it is doing kind of this detection
[http://homakov.blogspot.com/2013/03/pwning-your-privacy-
in-a...](http://homakov.blogspot.com/2013/03/pwning-your-privacy-in-all-
browsers.html)

you simply used chrome api :)

------
FiloSottile
On Canary it continually spams this on the console:

    
    
      Profile 'Profile 13' started. chrome.inspector-detector.js:16
      Profile 'Profile 13' finished. chrome.inspector-detector.js:17
      Console was cleared

------
md224
Apologies if this is a silly question, but why is console.clear() needed for
this to work?

EDIT: Oh, I get it, it must be housekeeping to clear the log messages
generated by the profiler.

~~~
afschwartz
Yup! :)

------
hyshai
Worst case scenario, to defeat this: Save page to local drive, edit JS (and
remove this) in your IDE/text editor. Open locally.

~~~
zackbloom
You'd have to open it with --disable-web-security to bypass potential CORS
problems on some sites.

~~~
hyshai
good point

------
devniel
Interesting, I thought that you played with the document and window height

------
tantalor

        delete window.chrome.inspector
    

Did I win?

------
vladikoff
Doesn't work even without the downloads bar. ( Win 7 , Chrome Beta )

------
brettcvz
Also doesn't work on ubuntu (at least not with scrotwm)

~~~
afschwartz
Can you provide any other information?

------
executive
Instructions are incompatible with Chrome OS.

------
jpettersson
Great for easter eggs!

------
meerita
Cases uses for this?

------
tantalor
$5 to the first Chrome extension that detects this and kills it.

------
Siecje
I don't get it?

~~~
afschwartz
Perhaps you're making a javascript game and want to pause it or show
wireframes when toggling the inspector. Things like that...

~~~
tantalor
Good idea. You should package this as a Chrome extension then. No reason why I
should run your code in my app, even in debug mode, when it can run outside
and sandboxed.

------
drivebyacct2
False. <http://i.imgur.com/7keR7aL.png> (Ubuntu 13.04, Plasma/KDE, KWin,
Chrome 27.0.1448.0 dev. It says that no matter what I do...)

~~~
afschwartz
I've made the docked/undocked an experimental feature since it was causing the
issues you were seeing. Please let me know if you're still seeing any issues
with false positives for open.

~~~
drivebyacct2
Looks okay now!

------
jQueryIsAwesome

        console.profile = console.clear = function(){}
    

That's all you need write in the console to stop this annoyance.

~~~
afschwartz
Does that make profiling unusable?

~~~
jQueryIsAwesome
It does, but you usually don't want to profile other dev's pages; here is
another solution that doesn't make profiling unusable:

    
    
        chrome.inspector.detector = function(){ return {open:false}}
    

But a more aggresive solution is this one:

    
    
        console = undefined;
        var iframe =     document.body.appendChild(document.createElement("iframe"));
        iframe.style.display = "none";
        window._console = iframe.contentWindow.console
    

And you can use `_console` instead of `console`

~~~
afschwartz
It may not be clear, but the main use case for this app is not to harm
someone, but to aid in development.

Perhaps you're making a game and want to pause it or show wireframes when
toggling the inspector.

Or perhaps you're a designer and you want to show a grid layout whenever
you're inspecting elements.

~~~
arcatek
It would be nice to have DOM events (just like onResize), which would only be
activated when activating the related option in the console (just like the
"Show XHR requests" option).

[edit] <https://code.google.com/p/chromium/issues/detail?id=223418>

~~~
afschwartz
Starred. Thanks for the submission. Would definitely be better to have this
integrated into the browser.

