headphono.us

Avatar

Pras Sarkar blogs about web technology, music, social networks, digital identities and other random things.

Firebug console bug/erratic behavior

This bug happens quite often and is very hard to pin down. It usually manifests itself as some piece of functionality in your app not working until you open the Firebug console window. If you’re using console.log anywhere in your code-base, this error occurs since the Firebug console window isn’t defined unless it is open and usable.

Luckily, the fix is quite easy. Just surround your console.log() with a check to see if its available:

   if ( window.console ) {
      console.log( whatever );
   }

Tags

One Comment, Comment or Ping

  1. The same issue happens in IE 8, without the IE Developer Tools enabled, the ‘console.log’ statements throw errors.

    Rather than wrapping each ‘console.log’ statement in a condition, the problem can be solved by using the following code snippet,

    if(!window.console || !console.log) {
    var console = { log: function () {} };
    }

    This even prevents the errors in browser’s that do not have the ‘console’ object, or have a custom ‘console’ object but no ‘log’ method defined.

Reply to “Firebug console bug/erratic behavior”

My Lifestream

My shenanigans around the web