Javascript + Browser - 如何检测dev工具/ firebug何时打开?

时间:2017-04-01 10:02:09

标签: javascript google-chrome web

在你们中的任何人开始说不可能之前,请导航到facebook.com打开devtools,即使在非附加模式下,它会告诉你dev工具是打开的,对吗?

那么facebook如何能够实现这一目标呢?

我可以为附加窗口

window.outerHeight - window.innerHeight > 200 || window.outerWidth - window.innerWidth > 200

但是当弹出窗口时,这不起作用。

Facebook如何解决此问题?

2 个答案:

答案 0 :(得分:1)

我认为facebook所做的只是在控制台中记录警告。 以下是Chrome中适合我的代码。 我禁用了3种我知道的方法来启动Chrome中的Developer Tool:

  1. 右键单击并选择检查选项:为此,我禁用了右键单击
  2. F12按键:阻止此事件的默认行为
  3. Ctrl + Shift + I:阻止所有Ctrl默认行为
  4. 看,如果你能负担得起的话。

    document.onkeydown = function(event) {      
        if(event.code == "F12" || event.ctrlKey) {
            event.preventDefault();
        }
    }
    document.addEventListener('contextmenu', event => event.preventDefault());
    

答案 1 :(得分:1)

在评论中推测@ elpddev时,他们只是在页面加载时使用console.log进行记录,他们没有检测到您已打开控制台。

如果您检查页面上的JS代码,您应该找到:

var j = i.stop || h._("Stop!")
  , k = i.text || h._("This is a browser feature intended for developers. If someone told you to copy-paste something here to enable a Facebook feature or \"hack\" someone's account, it is a scam and will give them access to your Facebook account.")
  , l = i.more || h._("See {url} for more information.", [h.param('url', 'https://www.facebook.com/selfxss')]);
if ((window.chrome || window.safari) && !i.textonly) {
    var m = 'font-family:helvetica; font-size:20px; ';
    [[j, i.c1 || m + 'font-size:50px; font-weight:bold; ' + 'color:red; -webkit-text-stroke:1px black;'], [k, i.c2 || m], [l, i.c3 || m], ['', '']].map(function(s) {
        setTimeout(console.log.bind(console, '\n%c' + s[0], s[1]));
    });
} else {
    var n = ['', ' .d8888b.  888                       888', 'd88P  Y88b 888                       888', 'Y88b.      888                       888', ' "Y888b.   888888  .d88b.  88888b.   888', '    "Y88b. 888    d88""88b 888 "88b  888', '      "888 888    888  888 888  888  Y8P', 'Y88b  d88P Y88b.  Y88..88P 888 d88P', ' "Y8888P"   "Y888  "Y88P"  88888P"   888', '                           888', '                           888', '                           888']
      , o = ('' + k).match(/.{35}.+?\s+|.+$/g)
      , p = Math.floor(Math.max(0, (n.length - o.length) / 2));
    for (var q = 0; q < n.length || q < o.length; q++) {
        var r = n[q];
        n[q] = r + new Array(45 - r.length).join(' ') + (o[q - p] || '');
    }
    console.log('\n\n\n' + n.join('\n') + '\n\n' + l + '\n');
    return;
}

它有点难以阅读,因为即使使用漂亮的打印,它也会缩小。 j = i.stop || h._("Stop!")类型的内容似乎是尝试加载本地化文本,然后再回归英语。然后测试他们是否已将浏览器检测为Chrome或Safari并且未设置i.textonly,如果是这样,它似乎显示的是您在Chrome / Safari中查看时使用的花哨样式。 else子句更难以遵循,但它似乎创建了您在文本模式或非Chrome / Safari浏览器中获得的ASCII艺术横幅:

 .d8888b.  888                       888    
d88P  Y88b 888                       888    
Y88b.      888                       888    This is a browser feature intended for 
 "Y888b.   888888  .d88b.  88888b.   888    developers. If someone told you to copy-paste 
    "Y88b. 888    d88""88b 888 "88b  888    something here to enable a Facebook feature 
      "888 888    888  888 888  888  Y8P    or "hack" someone's account, it is a 
Y88b  d88P Y88b.  Y88..88P 888 d88P         scam and will give them access to your 
 "Y8888P"   "Y888  "Y88P"  88888P"   888    Facebook account.
                           888              
                           888              
                           888              

See https://www.facebook.com/selfxss for more information.