Disabling JavaScript console debugging methods _javascript tips

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.