How does Facebook disable the browser's integrated Developer Tools?

后端 未结 12 1092
予麋鹿
予麋鹿 2020-11-22 06:12

So apparently because of the recent scams, the developer tools is exploited by people to post spam and even used to \"hack\" accounts. Facebook has blocked the developer too

12条回答
  •  执笔经年
    2020-11-22 06:48

    I located the Facebook's console buster script using Chrome developer tools. Here is the script with minor changes for readability. I have removed the bits that I could not understand:

    Object.defineProperty(window, "console", {
        value: console,
        writable: false,
        configurable: false
    });
    
    var i = 0;
    function showWarningAndThrow() {
        if (!i) {
            setTimeout(function () {
                console.log("%cWarning message", "font: 2em sans-serif; color: yellow; background-color: red;");
            }, 1);
            i = 1;
        }
        throw "Console is disabled";
    }
    
    var l, n = {
            set: function (o) {
                l = o;
            },
            get: function () {
                showWarningAndThrow();
                return l;
            }
        };
    Object.defineProperty(console, "_commandLineAPI", n);
    Object.defineProperty(console, "__commandLineAPI", n);
    

    With this, the console auto-complete fails silently while statements typed in console will fail to execute (the exception will be logged).

    References:

    • Object.defineProperty
    • Object.getOwnPropertyDescriptor
    • Chrome's console.log function (for tips on formatting output)

提交回复
热议问题