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

后端 未结 12 1157
予麋鹿
予麋鹿 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:57

    Internally devtools injects an IIFE named getCompletions into the page, called when a key is pressed inside the Devtools console.

    Looking at the source of that function, it uses a few global functions which can be overwritten.

    By using the Error constructor it's possible to get the call stack, which will include getCompletions when called by Devtools.


    Example:

    const disableDevtools = callback => {
      const original = Object.getPrototypeOf;
    
      Object.getPrototypeOf = (...args) => {
        if (Error().stack.includes("getCompletions")) callback();
        return original(...args);
      };
    };
    
    disableDevtools(() => {
      console.error("devtools has been disabled");
    
      while (1);
    });

提交回复
热议问题