显然,由于最近的骗局,开发者工具被人们用来发布垃圾邮件,甚至被用来“黑客”账户。Facebook已经屏蔽了开发者工具,我甚至无法使用控制台。

他们是怎么做到的??一篇Stack Overflow的帖子声称这是不可能的,但Facebook已经证明他们错了。

只需转到Facebook并打开开发工具,在控制台中键入一个字符,就会弹出此警告。无论你投入什么,它都不会被执行。

这怎么可能?

他们甚至在控制台中阻止了自动完成:


当前回答

我无法在任何页面上触发它。更强大的版本可以做到这一点:

window.console.log = function(){
    console.error('The developer console is temp...');
    window.console.log = function() {
        return false;
    }
}

console.log('test');

设置输出样式:JavaScript控制台中的颜色

Edit Thinking@joeldixon66有正确的想法:从控制台禁用JavaScript执行«:::KSpace:::

其他回答

我的方法很简单,但它有助于这个主题的进一步变化。列出所有方法并将其更改为无用。

  Object.getOwnPropertyNames(console).filter(function(property) {
     return typeof console[property] == 'function';
  }).forEach(function (verb) {
     console[verb] =function(){return 'Sorry, for security reasons...';};
  });

然而,更好的方法是禁止以任何有意义的方式打开开发人员工具

(function() {
    'use strict';
    Object.getOwnPropertyNames(console).filter(function(property) {
        return typeof console[property] == 'function';
    }).forEach(function (verb) {
        console[verb] =function(){return 'Sorry, for security reasons...';};
    });
    window.addEventListener('devtools-opened', ()=>{
        // do some extra code if needed or ...
        // maybe even delete the page, I still like to add redirect just in case
        window.location.href+="#";
        window.document.head.innerHTML="";
        window.document.body.innerHTML="devtools, page is now cleared";
    });
    window.addEventListener('devtools-closed', ()=>{
        // do some extra code if needed
    });
    let verifyConsole = () => {
        var before = new Date().getTime();
        debugger;
        var after = new Date().getTime();
        if (after - before > 100) { // user had to resume the script manually via opened dev tools 
            window.dispatchEvent(new Event('devtools-opened'));
        }else{
            window.dispatchEvent(new Event('devtools-closed'));
        }
        setTimeout(verifyConsole, 100);
    }
    verifyConsole();        
})();

我会这样做:

Object.defineProperty(window, 'console', {
  get: function() {

  },
  set: function() {

  }
});

我无法在任何页面上触发它。更强大的版本可以做到这一点:

window.console.log = function(){
    console.error('The developer console is temp...');
    window.console.log = function() {
        return false;
    }
}

console.log('test');

设置输出样式:JavaScript控制台中的颜色

Edit Thinking@joeldixon66有正确的想法:从控制台禁用JavaScript执行«:::KSpace:::

自从facebook禁用控制台以来,Chrome发生了很大变化。。。

截至2017年3月,这不再有效。

您所能做的最好是禁用一些控制台功能,例如:

if(!window.console) window.console = {};
var methods = ["log", "debug", "warn", "info", "dir", "dirxml", "trace", "profile"];
for(var i=0;i<methods.length;i++){
    console[methods[i]] = function(){};
}

在Firefox中,它没有做到这一点,因为Firefox是一个开发人员浏览器,我认为由于命令WEBGL_debug_render_info在Firefox中被弃用,将被删除。请使用RENDERER和错误Referrer Policy:对于跨站点请求,将很快忽略限制较少的策略,包括“降级时没有Referrer”、“跨源时源”和“不安全url”:https://static.xx.fbcdn.net/rsrc.php/v3/yS/r/XDDAHSZfaR6.js?_nc_x=Ij3Wp8lg5Kz.