简体   繁体   English

检测萤火虫的打开和关闭

[英]Detect firebug opening and closing

Does anybody have a way to detect Firebug opening and closing. 是否有人有办法检测Firebug的打开和关闭。

I know you can do the following: 我知道您可以执行以下操作:

if (window.console && window.console.firebug) {
  //Firebug is enabled
}

but this only detects the firebug console on page load. 但这只会在页面加载时检测到Firebug控制台。 What I want to do is on a page where firebug is not open, detect the opening of the firebug console. 我要做的是在未打开Firebug的页面上,检测Firebug控制台的打开情况。

I've tried the following, but with no luck 我尝试了以下方法,但是没有运气

setInterval(function(){
  if(window.console && window.console.firebug){
    ...
  else
    ...
}, 1000);

Any help greatly appreciated. 任何帮助,不胜感激。

Matt 马特

Simply.. You cant. 简单..你不能。 The firebug window not just an another couple of div element on your page. Firebug窗口不仅是页面上的另一个div元素。

The Firebug window.console object is created just before the first Javascript in the page is executed but only if Firebug is active for the page before the first JS and if the user has the Firebug Console panel enabled. 仅在执行页面中的第一个Java脚本之前创建Firebug window.console对象,但前提是第一个JS之前的页面的Firebug是活动的,并且用户启用了Firebug控制台面板。

In other words, from within the page you can only detect if the Console is enabled. 换句话说,在页面内,您只能检测是否启用了控制台。 But for your purposes that should be enough. 但是对于您的目的,这应该足够了。

We should delete the console property if a user turns Firebug off for a page. 如果用户关闭页面的Firebug,我们应该删除console属性。 I don't know if we actually do that. 我不知道我们是否真的这样做。

console.table() returns "_firebugIgnore" if firebug is running. 如果Firebug正在运行,console.table()将返回“ _firebugIgnore”。

if( window.console && (console.firebug || 
   console.table && /firebug/i.test(console.table()) ))
{
    alert('Firebug is running');
}else{
    alert('Firebug is not found');
}

you can make it as 你可以做到

var t = setTimeout("CheckFireBug()",10000);
function CheckFireBug() {
    var t = setTimeout("CheckFireBug()",10000);
    if (window.console && window.console.firebug) {
        //Firebug is enabled
        console.debug('Firebug is enabled.');
    } else {
        //Firebug is not enabled
        console.debug('Firebug is not enabled.');
    }
}

Firebug overwrites the console property of window , so you may detect it like so: Firebug会覆盖windowconsole属性,因此您可以像这样检测到它:

var _console = window.console;
Object.defineProperty(window, 'console', {
    set: function (x) {
        if (x.exception) { // check if this is actually Firebug, and not the built-in console
            alert('Firebug on');
        }
        _console = x;
    },
    get: function () {
        return _console;
    }
});

The problem is that this object remains when Firebug is closed, so you can't detect that. 问题在于,当Firebug关闭时,该对象仍然存在,因此您无法检测到该对象。 Maybe there's some other way but I can't find it ATM. 也许还有其他方法,但我找不到ATM。

Details: It's not possible to access Firebug's execution context from document scripts, so we're limited to waiting for Firebug to access some of window 's properties, which does not seem to happen when you close Firebug. 详细信息:无法从文档脚本访问Firebug的执行上下文,因此我们仅限于等待Firebug访问window的某些属性,当您关闭Firebug时似乎不会发生。 Here's some of the events during shutdown, taken with FBTrace : 这是关机期间使用FBTrace进行的一些事件:

Firebug堆栈跟踪

I've searched the stacktrace for "leaks" to window , but couldn't find any. 我已经在stacktrace中搜索到“泄漏”到window ,但是找不到任何东西。

如果您只想检测Firebug的打开/关闭,则可以检查窗口大小调整/模糊事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM