Welcome to Code Couch

ReferenceError: console is not defined

Posted by at 8:50pm on October 13, 2008.

If you have recently changed your Firefox configurations (and upgraded to Firebug 1.2) then you may have experienced some difficulties with console.log throwing the following error:

ReferenceError: console is not defined

It turns out that this is by design. If you want to make use of the console object that Firebug offers, you need to do so with a call to window.loadFirebugConsole() first.

A little bit of testing, and the following code can be safely put in your javascript source to enable use of the Firebug console object safely (without breaking other browsers).

if (window['loadFirebugConsole']) {
} else {
	if (!window['console']) {
		window.console = {};
		window.console.info = alert;
		window.console.log = alert;
		window.console.warn = alert;
		window.console.error = alert;

Whilst you are at it, why not check out some of the other nifty commands available on the Firebug console object at the Get Firebug website.

Post to Twitter



There is one response to this post.

  1. hii.. first: very nice blog. second: i registered to say thanks for this tip i was looking for some kind of a way to figured out whether the console of firebug is set and its seems like (window['console']) working... i have another way of doing this in my office where i work but im home now and i just couldn't remember exactly what was it :)

Leave a reply

Comments are closed for this post.