ユーザーコンソールjs,Displale the User's JavaScript Cosolieを無効にします.

1468 ワード

The re are a few giant companies out there,namely Facebook and Netflix,who have decided to effectively disable a user's ability to execute JavaScript consome command. The decision was initially made byフェイスブック to prevent users from executing a specific set of command which would expose user information via the Java Script consolie Of course this has been subject to loads of criticism、but before I weigh in、 here's the code to it:
// It appears Netflix is following (Facebook's lead)[https://news.ycombinator.com/item?id=7222129].(function() {
    try {
        var $_console$$ = console;
        Object.defineProperty(window, "console", {
            get: function() {
                if ($_console$$._commandLineAPI)
                    throw "Sorry, for security reasons, the script console is deactivated on netflix.com";
                return $_console$$            },
            set: function($val$$) {
                $_console$$ = $val$$            }
        })
    } catch ($ignore$$) {
    }})();
Not that my opinion maters much,but I actually think this practice somewhat legit. From their perspective,if disabling the consolis helps to temporarly prevent an issue,you have to it. In the long term,it's really not a good idea;they may become a target simply based on their effort to block people out. Regardless、this code seems to work so if you want to prevent consolieve executions、this will do it.