Firebug: avoid errors in other browsers

Small snippets or full-featured libraries – if you develop in Javascript and don’t have Firefox and Firebug

installed – you’d better get them now.

Firebug is a Firefox extension which brings several top-notch inspection/debugging features. You can inspect DOM, change CSS run-time and so on.

Aside DOM, CSS and Net capabilities Firebug features a very good debugger and some very useful logging capabilities. For example in your scripts you could write:

console.log ( "result is:", var );

and get the javascript variable “var” dumped into Firebug console.

Browsers Issue

Sadly, firebug as an extension is only available to Firefox. This means that any of your script will fail while running inside other browsers.

I wrote a little script to fix the problem:

if ( typeof( console) == "undefined" ) var console = {};
console.turnOff = function ()
{
	var api = [ 'log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml', 'trace', 'group', 'groupEnd', 'time', 'timeEnd', 'profile', 'profileEnd', 'count' ];
	for ( var i = 0; i < api.length; i++ ) console[ api[i] ] = function (){};
	console.firebug = "0.00";
}
if ( typeof( console.firebug) == "undefined"  ) console.turnOff();

Needless to say, I became aware afterwards a quite identical solution was available from the Firebug official site’s as well. Here’s is the official solution:

if (!window.console || !console.firebug)
{
    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() {}
}

The only difference is mine provides a console.turnOff() function which disables firebug logging even in firefox (when called explicitly form your script).

console.turnOff();
console.debug( 'Hello world' ); //won't output anything

This seems like a great time to subscribe my RSS !

Leave a Reply

Bills

Don’t forget to Subscribe

Latest Activity

Posts

  • Google this is ridiculous
    Google you’re doing it wrong. Very wrong. This is utterly ridiculous. It’s a screenshot with a standard Firefox browser, in the standard screen resolution (1280×800), on Read More
  • A step back from the open source
    One month ago, I created my first Android app. While the app was a paid one, the reception has been outstanding. I’ve gotten a fair amount Read More
  • Facebook shuts down EventPress development.
    When you’re a big company, especially one that makes its money on free web services and advertising, it’s very easy to say you love open Read More
  • Why Android is laggy
    Great post from Andrew Munn explaining some key differences between Android and iPhone/iOs, especially when it comes to rendering and smoothness of animations and why Read More
  • Google Plus keeps your data as much as Facebook does
    When you delete an account from Google+, Google promises you to delete all the data associated with your G+ profile. Well, I deleted mine some time Read More