O'Reilly

How to Sniff & Disable Firebug

By on  

If you're a hardcore Web Developer like me, you're probably well aware of the excellent Firefox plugin known as Firebug. Firebug's built in tools for monitoring and debugging CSS, HTML, and JavaScript/AJAX can improve development time efficiency exponentially.

As great as Firebug is, using Firebug does have its disadvantages while browsing websites that perform numerous AJAX requests. Firebug chokes on trying to analyze and display all of the information that it can make Firefox hang up. This, of course, is followed by [CONTROL] + [ALT] + [DELETE] and a restart of Firefox. Two such websites that warn users about this problem are Gmail and NetVibes.

If you fear that a website you are developing could cause problems for visitors with Firebug enabled, you have a few options for preventing problems.

Sniffing Firebug and Displaying A Message

The following JavaScript sniffs for Firebug. You could use this to display a "Please disable Firebug..." type of message.

if (window.console && window.console.firebug) {
	/* firebug found! */
}

Disable Firebug Functionality

The following JavaScript code doesn't disable Firebug but renders some problem functionality useless. The following snippet of code was taken from Yahoo! Media Player.

if (! ('console' in window) || !('firebug' in console)) {
    var names = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml', 'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd'];
    window.console = {};
    for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {};
}
Track.js Error Reporting

Upcoming Events

Recent Features

  • Send Text Messages with PHP

    Kids these days, I tell ya.  All they care about is the technology.  The video games.  The bottled water.  Oh, and the texting, always the texting.  Back in my day, all we had was...OK, I had all of these things too.  But I still don't get...

  • Animated 3D Flipping Menu with CSS

    CSS animations aren't just for basic fades or sliding elements anymore -- CSS animations are capable of much more.  I've showed you how you can create an exploding logo (applied with JavaScript, but all animation is CSS), an animated Photo Stack, a sweet...

Incredible Demos

  • MooTools onLoad SmoothScrolling

    SmoothScroll is a fantastic MooTools plugin but smooth scrolling only occurs when the anchor is on the same page. Making SmoothScroll work across pages is as easy as a few extra line of MooTools and a querystring variable. The MooTools / PHP Of course, this is a...

  • Facebook-Style Modal Box Using MooTools

    In my oh-so-humble opinion, Facebook's Modal box is the best modal box around. It's lightweight, subtle, and very stylish. I've taken Facebook's imagery and CSS and combined it with MooTools' awesome functionality to duplicate the effect. The Imagery Facebook uses a funky sprite for their modal...

Discussion

  1. Excellent snippets, saves a lot of source code viewing and google searching. You can see that firebug does have quite an impact on the web.

    One thing that *I* think happened to my firefox, was that it can’t be opened right now. I’ve restarted my machine multiple times and I get the message “Firefox is already running.” I got the message a lot on linux machines and that usually just involved me deleting my profile folder in .mozilla , but I am not too sure where this folder exists in my windows box. The issue in the linux, was that I did not close the firefox window in another linux box when I logged off (all of the linuxes box where networked together using nfs so my data will be the same regardless of which box I logged into) I am willing to bet this is firebug related, since the last time I used it, firefox abruptly closed after opening like the 30th tab. /endrant

  2. I’m not sure if that’s a Firebug issue but it happens to me quite a bit with fire fox. The fix for that is going into windows task manager, hit the processes tab and look for the file named “firefox.exe”, once found, highlight it and then click the end process button. Now start up firefox…should work again.

  3. johnG

    interesting!

  4. Melindrea

    Is there any way to disable Firebug if the user has javascripts disabled?

    Thank you,
    Melindrea

  5. @Melindrea: I don’t believe so.

  6. Melindrea

    Thanks anyways. =)

  7. mastr3s

    This really great script i’ve ever see can execute Firebug. I use firebug but i hate it when they see all activity on my web. Now i’m good

  8. Krepa

    I tried that solution to disabling firebug but doesnt excatly work right, would you have any idea how to disable the acutally console fully..

  9. It doesn’t work,
    I can detect whether firebug is installed or not, but i cant stop it.
    I need to hide the url’s i call with ajax, but in the firebug’s panel it is all open

  10. @Jesus DeLaTorre try this command line:

    sudo killall -9 firefox

    and then restart your Firefox

  11. JR

    The sniffing code correctly detects Firebug, but the code that supposedly disables Firebug functionality runs only in the absence of Firebug. As I read it, that code is intended to prevent Firebug function calls from within the Yahoo! media player from throwing errors in browsers that don’t have Firebug installed.

    If you’re terribly concerned with people using Firebug’s console on your site, you could try the following to hinder them:

    if (window.console && window.console.firebug) {
        for (var x in console) {
            delete console[x];
        }
    }
    

    Keep in mind that this affects only the console of Firebug; all other features will likely work normally. Also, while Firebug is immensely popular, it is far from the only tool to execute user Javascript.

    Cheers =)

  12. Sashi

    Hi, i would like to know, how i can disable firebug on a bebo application page. I have developed a bebo application, using php and bebo api. But the casual javascript code to disable firebug does not work there.
    Please, can any body tell me, how i can disable the javascript there, as the firebug is driving me mad, when users crack the game and cheat with the points.

  13. Jason

    Worked great if console was enabled, but we found that a user doesn’t have to have Console enabled to run Net enabled and that having the Net panel enabled causes js conflicts. Has anyone else found a way to detect if the other panels, such Net are enabled when Console is not?

  14. Simone gianni

    There is NO WAY of stopping firebug, not stopping each and every other possible plugin that can sniff or execute code inside your page. The problem is that, being javascript delivered as source code and executing on client machines, it is possible for everyone to read, reverse engineer, modify and do whatever they want with your javascript code.

    You should write applications that have server side checks to prevent cheating/sniffing/whatelse on the client, cause client computer IS NOT a safe environment, firebug or not firebug.

    Scripts given in this post are useful to display a warning to the user like “Hey, fellow developer, so you are using firebug … it can make this site really slow”, not to prevent him from looking at your code or “playing” with your javascript, cause there is no way of doing it anyway.

  15. RAJ

    thanks for providing this code but there is a small change

    if (window.console && window.console.firebug) {
           console.clear();
    }
  16. Maxime

    Hi, I’m trying to close Firefox when I detect Firebug but with no success…

    if (window.console && window.console.firebug) {
    window.opener='X';
    window.open('','_parent','');
    window.close();
    }
    

    Firefox doesn’t allow window.close

    if (window.console && window.console.firebug) {
    window.location = "chrome://mozapps/content/profile/profileSelection.xul";
    }
    

    Try the chrome URL in your Firefox, it will close it…

    Then I have found the close function directly into the firebugOverlay.xul and firebug.js files but I don’t know how I can call it with javascript

    in the xul file : oncommand=”Firebug.closeFirebug(true)”
    in the js file :

    closeFirebug: function(userCommand)  // this is really deactivate
        {
            var browser = FirebugChrome.getCurrentBrowser();
    
            TabWatcher.unwatchBrowser(browser, userCommand);
            Firebug.resetTooltip();
        }
    

    If someone know how to do let us know.

    • marion

      firebug.js is included in the Firebug Extension. It contains some code that can not have the permission to execute in the web page.

  17. MR

    There is any way to hide Firebug to prevent some site to try block it?

  18. Anil

    I read you post and that is helpful and good for hint but i am unable to disable or clear firebug events. can you please provide me the code script with example for more help.

  19. Foobar

    Also very funny:

    if(window.console.firebug)  { 
         document.body.innerHTML = "PLEASE DO NOT USE FIREBUG" 
    };
  20. @kvetchus

    I know this is a REALLY old post (from 2008), but it came up as I was googling around for alternative ways of detecting firebug (which was injecting an error into a jQuery script when enabled). window.console.firebug was removed due to privacy concerns, so it no longer works. detecting the console object isn’t useful because all major modern browsers have that object now (yup, even IE!). I haven’t found a reliable way, and apparently if I were to it would actually be considered a security issue in the firebug plugin… Since comments don’t appear to display dates: (04/11/2012)

  21. MRX

    That’s why developers of tools and software, need to think sometimes about security not only of one side – client side, but about other side too.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!

Recently on David Walsh Blog

  • OâReilly Velocity Conference â New York

    My favorite front-end conference has always been O'Reilly's Velocity Conference because the conference series has focused on one of the most undervalued parts of client side coding:  speed.  So often we're so excited that our JavaScript works that we forget that speed, efficiency, and performance are just as important. The next Velocity...

  • Free Download: Font Bundle Featuring 17 Incredible Typefaces

    The only thing we love more than a good font, is a good free font. So we’ve combed the Web for some of our favorite free fonts, and gathered them here in a single download. You’ll find a variety of useful typefaces, from highly geometric designs...

  • OâReilly Velocity Conference â Amsterdam

    My favorite front-end conference has always been O'Reilly's Velocity Conference because the conference series has focused on one of the most undervalued parts of client side coding:  speed.  So often we're so excited that our JavaScript works that we forget that speed, efficiency, and performance are just as important. The next Velocity...

  • CanIUse Command Line

    Every front-end developer should be well acquainted with CanIUse, the website that lets you view browser support for browser features.  When people criticize my blog posts for not detailing browser support for features within the post, I tell them to check CanIUse:  always up to date, unlike...

  • Generating Alternative Stylesheets for Browsers Without @media

    If your CSS code is built with a mobile-first approach, it probably contains all the rules that make up the "desktop" view inside @media statements. That's great, but browsers that don't support media queries (IE 8 and below) will simply ignore them, ending up getting the...