How to know when Chrome console is open
tl;dr; Although it’s not supposed to be supported – it’s possible to know whether the Chrome console is opened or not. Check it out. Reddit discussion. … Ever…
tl;dr;
Although it's not supposed to be supported – it's possible to know whether the Chrome console is opened or not.
Check it out.
…
Ever wondered if it's possible to tell whether the browser's Development-Tools are opened or not. Apparently it's not possible in Chrome. And that's a good thing, it's no website business to know when I inspect their code.
The thing is… it is possible to tell.
When you run console commands it runs slower when the console is opened. That's it. You simply run console.log and console.clear a few times and if it's slower – than the console is open.
With this hack you can find out pretty reliably when the console is open and when it is closed.
Frankly, I don't see how this can be mitigated without harming the performance of the browser. When the console is opened it has to be slower. Hence this hack will most likely continue to work. And I assume it'll work similarly on other browsers and with other consoles.
Although others will claim otherwise, the only way I see this hack being used legitimately is by geeks to impress their peers.
Other than that the only valid reasons that I can think of are malicious, but I'm not gonna tell you how 😉
**
Making it perfectly accurate**
In the demo I've used a benchmark ratio of 1.6 to determine if the console is open or not. In a perfect implementation the ratio will be dynamic and will change between environments.
Currently if a user will open the page with the console already opened it'll be detected only after the user will close it at least once.
It'll be possible to create another independent benchmark to tell whether the console was opened when the page first loaded.
Related Posts
Comments (6)
Imported from the original blog
When a tab is in the background, it runs slower, which cause your script to give false positive when switching tabs. Also, (videos, games, etc) in other tabs can drastically change the performance of the browser. Other processes (anti-virus, and just about everything else) will also change the performance of the browser.
At the end, how my browser behave is up to me, I can re-define console.log() and console.clear() with Userscript so they behave differently than what you expect. I can also define testDevTools as constant before the page loads so your script will crash.
This is not going to work in production situation, but it is a fun hack, good job ;)
Thanx :)
There is a new and accurate way to know https://stackoverflow.com/a...
Can be patched via extension, override "console.log" ("warn", "error", "debug", etc) so they ignore HTML Elements. Also patch "Function.prototype.toString" to prevent detection of patched "console". Match and patch "about:blank" too to prevent grabbing real "console" from "iframe".
2017 here.
Chrome still writes things to console even when the dev tool is not open.
So, no more performance hack for you.
Actually it still works.
But there's a better way to do it now https://stackoverflow.com/a...
hey that's work !
thanks bro :D