Several giant companies, Facebook and Netflix, have decided to prohibit users from executing JavaScript commands in the console (console).
Initially this was started by Facebook to prevent malicious users from executing specific command-mongering messages via the JavaScript console (sending a lot of spam to all Facebook users).
Of course it's a lot of blame, but before I get involved, the code they use looks like this:
Copy Code code as follows:
Netflix seems to be the only Facebook took direction [https://news.ycombinator.com/item?id=7222129].
(function () {
try {
var $_console$$ = console;
Object.defineproperty (window, console), {
Get:function () {
if ($_CONSOLE$$._COMMANDLINEAPI)
Throw "Sorry, for the sake of user security, this website has disabled the console script function";
Return $_console$$
},
Set:function ($val $$) {
$_console$$ = $val $$
}
})
catch ($ignore $$) {
}
})();
Although I am two-bit, in fact I think this practice is legal. From their point of view, if you temporarily disable the console to help prevent a problem, you have to do so.
But in the long run it's really not a good idea; The goal may be simply to shield the target users who depend on them.
Anyway, if you want to prevent the console from executing the script, the code looks good and it does.