Javascript that detects Firebug?

JavascriptFirebug

Javascript Problem Overview


What's a surefire way of detecting whether a user has Firebug enabled?

Javascript Solutions


Solution 1 - Javascript

Original answer:

Check for the console object (created only with Firebug), like such:

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

Update (January 2012):

The Firebug developers have decided to remove window.console.firebug. You can still detect the presence of Firebug by duck typing like

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

or various other approaches like

if (document.getUserData('firebug-Token')) ...
if (console.log.toString().indexOf('apply') != -1) ...
if (typeof console.assert(1) == 'string') ...

but in general, there should be no need to actually do so.

Solution 2 - Javascript

If firebug is enabled, window.console will not be undefined. console.firebug will return the version number.

Solution 3 - Javascript

As of Firebug version 1.9.0, console.firebug is no longer defined because of privacy concerns; see release notes, bug report. This breaks the above mentioned methods. Indeed, it changes the answer to Allan's question to "there is no way"; if there is another way, it's considered a bug.

The solution instead is to check for the availability of console.log or whatever it is you want to use or replace.

Here is a suggestion for a replacement for the kind of code that David Brockman is presenting above, but one that doesn't remove any existing functions.

(function () {
    var names = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml', 
                'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd'];

    if (window.console) {
        for (var i = 0; i < names.length; i++) {
            if (!window.console[names[i]]) {
                window.console[names[i]] = function() {};
            }
        }
    } else {
        window.console = {};
        for (var i = 0; i < names.length; i++) {
            window.console[names[i]] = function() {};
        }
    }
})();

Solution 4 - Javascript

It may be impossible to detect.

Firebug has multiple tabs, which may be disabled separately, and, are now not enabled by default.

GMail as it is can only tell whether or not I have the "console" tab enabled. Probing further than this would likely require security circumvention, and you don't want to go there.

Solution 5 - Javascript

You can use something like this to prevent firebug calls in your code from causing errors if it's not installed.

if (!window.console || !console.firebug) {
    (function (m, i) {
        window.console = {};
        while (i--) {
            window.console[m[i]] = function () {};
        }
    })('log debug info warn error assert dir dirxml trace group groupEnd time timeEnd profile profileEnd count'.split(' '), 16);
}

Solution 6 - Javascript

Keep in mind in Chrome window.console also returns true or [Object console].

Furthermore, I would check whether Firebug is installed with

if (window.console.firebug !== undefined) // firebug is installed

Below is what I get in Safari and Chrome, no firebug installed.

if (window.console.firebug) // true
if (window.console.firebug == null) // true
if (window.console.firebug === null) // false

The Is-True and Is-Not Operators obviously do type coercion, which should be avoided in JavaScript.

Solution 7 - Javascript

Currently, the window.console.firebug has been removed by latest firebug version. because firebug is an extension based JavaScript debugger, Which defined some new function or object in window.console. So most times, you can only use this new defined functions to detection the running status of firebug.

such as

if(console.assert(1) === '_firebugIgnore') alert("firebug is running!"); 
if((console.log+'''').indexOf('return Function.apply.call(x.log, x, arguments);') !== -1)  alert("firebug is running!");

You may test these approach in each firebug.

Best wishes!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAllanView Question on Stackoverflow
Solution 1 - JavascriptAndreas GrechView Answer on Stackoverflow
Solution 2 - JavascriptceejayozView Answer on Stackoverflow
Solution 3 - JavascriptskagedalView Answer on Stackoverflow
Solution 4 - JavascriptKent FredricView Answer on Stackoverflow
Solution 5 - JavascriptDavid BrockmanView Answer on Stackoverflow
Solution 6 - Javascriptstevek-proView Answer on Stackoverflow
Solution 7 - JavascriptHao DongView Answer on Stackoverflow