views:

2328

answers:

5

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

+18  A: 

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

ceejayoz
+51  A: 

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

if (window.console && window.console.firebug) {
  //Firebug is enabled
}
Andreas Grech
Remember, use your powers for good, or awesome, but don't penalize firebug users because it makes it so easy to circumnavigate any sort of 'copy' or 'save' actions they might be interested in taking. That'd be bad form.
matt lohkamp
IIRC, using console.log in Safari with developer mode on also works - so the statement 'created only with firebug' *may* be incorrect.
alex
Safari indeed has a console object, but Safari's console does not have a `firebug` property, and thus the above condition will fail in Safari, thus not detecting Firebug
Andreas Grech
@Dreas - you are correct
alex
+3  A: 

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.

Kent Fredric
+4  A: 

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);
}
David Brockman
A: 

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.

Stephan Kristyn