8 ms·
Chrome Inspector Detector
Detect whether the Chrome Inspector is open and docked, open and in a separate window, or closed.
- jQueryIsAwesome 14y agoconsole.profile = console.clear = function(){} That's all you need write in the console to stop this annoyance.
- afschwartz 14y agoDoes that make profiling unusable?
- jQueryIsAwesome 14y agoIt 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 14y agoIt 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.
- jQueryIsAwesome 14y agoIt doesn't matter what your intentions are; eventually it will be used to annoy some developers, lets just hope that it doesn't become something common.
- arcatek 14y agoIt 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 https://code.google.com/p/chromium/issues/detail?id=223418
- afschwartz 14y agoStarred. Thanks for the submission. Would definitely be better to have this integrated into the browser.
- thirtyseven 14y agoIt kind of gets in the way of development though when the profiler window gets clogged up with the probes... maybe the detector could clean up after itself?
- afschwartz 14y agoWe agree. We're actively looking into other ways to do the detection. For example, when the inspector is docked, we might not need to run the profiler check. We'll continue to update as we find better solutions.
- patejam 14y agoDoesn't work exclusively with the Chrome Inspector. Having the downloads bar at the bottom sets this off as well, for example.
- Scene_Cast2 14y agoHaving a non-standard window zoom also sets this off.
- lukeschlather 14y agoChromium / Ubuntu I only get it with greater than 100% zoom, zooming out doesn't trigger.
- afschwartz 14y agoI'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 14y agoFrom 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 14y ago@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... https://github.com/adamschwartz/chrome-inspector-detector/is...)
- deleted 14y ago[deleted]
- vladikoff 14y agoDoesn't work even without the downloads bar. ( Win 7 , Chrome Beta )
- afschwartz 14y agoI'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.
- brettcvz 14y agoAlso doesn't work on ubuntu (at least not with scrotwm)
- patejam 14y agoUbuntu 12.10 with Cinnamon works.
- afschwartz 14y agoCan you provide any other information?
- drivebyacct2 14y agoFalse. http://i.imgur.com/7keR7aL.png 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 14y agoI'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 14y agoLooks okay now!
- afschwartz 14y agoThanks for reporting all of the issues. I'll continue to improve and update https://github.com/adamschwartz/chrome-inspector-detector/issues https://github.com/adamschwartz/chrome-inspector-detector/is... with the issues reported here. Thanks.
- ryiytrye 14y agoWorks fine to detect the inspection window, but a false positive (as "open and docked") if I change Chrome window state from maximised to normal.
- afschwartz 14y agoI'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.
- jsonmez 14y agoOh, 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 14y agoIt 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 14y agoOr 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...
- jaredmcateer 14y agoThat may have been your aim and while there is a great potential good, there's also a great potential for evil. You've opened pandora's box and now we'll see how it plays out. My guess is that we're going to see a lot of misguided website abuse this until the Chrome team has to patch it so websites can't know its state.
- just2n 14y agoDefeated: javascript:clearTimeout(setTimeout(function(){}, 1) - 1);
- jQueryIsAwesome 14y agoBut 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 14y agochrome.inspector.detector=function(){return{}};
- jQueryIsAwesome 14y agoand what if he stops putting a public reference to the "detector" method?, read previous answer again.
- brokenparser 14y agoUse Firefox.
- raldi 14y agoHow do I press ⌘ on Linux?
- afschwartz 14y agoJust updated with OS-specific instructions: https://github.com/adamschwartz/chrome-inspector-detector/commit/f126305c683 https://github.com/adamschwartz/chrome-inspector-detector/co...
- raldi 14y agoWorks great, thanks!
- dlss 14y agoEasy -- just plug in an apple keyboard and hit ⌘
- manojlds 14y agoBut it is Ctrl + shift + I on windows and I thin Linux too.
- cooldeal 14y agoIt'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.
- schrodinger 14y agoThat's not contributing anything of value. Offer advice if you've got it, otherwise I don't think theres a valid need to be snarky.
- frozenport 14y agoSays 'Add Comment" not 'Add Advice'. Also the advice is clear, don't use OS specific keys for the web.
- md224 14y agoApologies 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 14y agoYup! :)
- Siecje 14y agoI don't get it?
- afschwartz 14y agoPerhaps you're making a javascript game and want to pause it or show wireframes when toggling the inspector. Things like that...
- tantalor 14y agoGood 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.
- zackbloom 14y agoA 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}"
- maratd 14y agoWell ... people who know how to use the inspector also know how to get the content without using the inspector. Although it would be significantly more annoying.
- chadscira 14y agobut then we could just ensure that this line gets called first console.profile = console.profileEnd = function () {};
- jQueryIsAwesome 14y agoNot 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 14y agowell in that case i guess you could always do var _console = console; console = undefined;
- jQueryIsAwesome 14y agoYou may break something by breaking it yourself, like naive code: if (window.chrome) console.log("dev forgot to delete this"))
- aeon10 14y agoview-source would still work right. so
- twinn 14y agoThis is cool, I used the same technique in the discover-devtools.codeschool.com course for the first challenge.
- afschwartz 14y agoYup! We credited http://stackoverflow.com/a/15567735/131898 http://stackoverflow.com/a/15567735/131898 in the README (https://github.com/adamschwartz/chrome-inspector-detector/blob/master/README.md https://github.com/adamschwartz/chrome-inspector-detector/bl...) which in turn credits you. :)
- hyshai 14y agoWorst case scenario, to defeat this: Save page to local drive, edit JS (and remove this) in your IDE/text editor. Open locally.
- hfcorriez 14y agoI think so.
- tantalor 14y agodelete window.chrome.inspector Did I win?
- tantalor 14y ago$5 to the first Chrome extension that detects this and kills it.
- jpettersson 14y agoGreat for easter eggs!
- theoutlander 14y agoOn Windows, use F12 instead of Ctrl + Shift + I
- devniel 14y agoInteresting, I thought that you played with the document and window height
- skore 14y agoThis 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.
- DomreiRoam 14y agoIt'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?
- meerita 14y agoCases uses for this?
- executive 14y agoInstructions are incompatible with Chrome OS.
- deleted 14y ago[deleted]
- FiloSottile 14y agoOn 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
- homakov 14y agoI was hoping it is doing kind of this detection http://homakov.blogspot.com/2013/03/pwning-your-privacy-in-all-browsers.html http://homakov.blogspot.com/2013/03/pwning-your-privacy-in-a... you simply used chrome api :)
- etjossem 14y agoCould 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 https://vimeo.com was using the inspector console as a recruiting tool.
- tomkin 14y agoGreat idea!