Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript that detects Firebug?

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

like image 626
Allan Avatar asked Dec 29 '08 17:12

Allan


People also ask

What replaced Firebug for Firefox?

The Firebug web development tool, an open source add-on to the Firefox browser, is being discontinued after 12 years, replaced by Firefox Developer Tools.

How do I enable Firebug?

Installing Firebug You can download and install Firebug from https://addons.mozilla.org/en-US/firefox/addon/1843/. After visiting the page referenced above, click on the Download button, it shows a window to and click on the Install button there. It takes a while and asks you to restart the Firefox browser.

What is Firebug tool?

Firebug is a discontinued free and open-source web browser extension for Mozilla Firefox that facilitated the live debugging, editing, and monitoring of any website's CSS, HTML, DOM, XHR, and JavaScript. Firebug.


3 Answers

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.

like image 136
5 revs, 3 users 59% Avatar answered Oct 13 '22 19:10

5 revs, 3 users 59%


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

like image 23
ceejayoz Avatar answered Oct 13 '22 21:10

ceejayoz


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() {};
        }
    }
})();
like image 43
skagedal Avatar answered Oct 13 '22 19:10

skagedal