Title: How do you log to Firebug from an extension?
Tags: debugging;firefox;logging;console;firebug
Question: I'm writing an extension for Firefox, and I need to log some data to Firebug's console. Within the scope of my addon, "console" is undefined, and "window.content.console" is also undefined. So how do I log to the console?


Here is the accepted answer: Since you're not writing Javascript that executes within a window, ```console``` is not defined.

So you need to reference the Firebug extension first:

```Firebug.Console.log(str);
```

Comment for this answer: Oopch, `Firebug` is undefined!
Comment for this answer: try this 

Application.console.log("Hello from my Firefox Extension!");
Comment for this answer: @TahaJahangir, just turn your Firebug on for current page and press f5 ;)
Comment for this answer: I have Firebug installed but it seems you can no longer do this. `Firebug` is `undefined`.

Here is another answer: There are contexts in which even the Firebug object is unknown, like if you're trying to call it from a sidebar... in which case you have to go all the way back to the original window to get the firebug object:

``` var Firebug = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
 .getInterface(Components.interfaces.nsIWebNavigation)
 .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
 .rootTreeItem
 .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
 .getInterface(Components.interfaces.nsIDOMWindow).Firebug;
```

You can then from within your sidebar call Firebug like so:

```Firebug.Console.log("foo");
```

This is documented here: https://developer.mozilla.org/en/Code_snippets/Sidebar


Here is another answer: To log to the console from inside a firefox extension’s javascript:

Application.console.log("Hello from my Firefox Extension!");


Here is another answer: If in your extension you have access to the content Window object, you can unwrap it, and call the console methods directly:

```window.wrappedJSObject.console.log('something important');
```

Comment for this answer: window.wrappedJSObject is undefined

Here is another answer: As far as I know you can only do that if you are creating a JetPack Add-on. Normal debugging is done with Venkman from Mozilla at http://www.mozilla.org/projects/venkman/


Here is another answer: Firebug console is associated with a particular page, so it wouldn't be very convenient even if you managed to log messages there. Did you try Chromebug? I didn't use it, but I would expect to find a similar console for extensions to use there.

You could also use the regular Error Console, although you won't get all the niceties Firebug's console provides. You could install Console^2 https://addons.mozilla.org/en-US/firefox/addon/1815 to make using the Error Console a little less painful.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 6, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 2.5', 'CreationDate': '2009:00:07/25/09', 'FavoriteCount': 4.0, 'PostTypeId': 1, 'Tags': '<debugging><firefox><logging><console><firebug>', 'Title': 'How do you log to Firebug from an extension?', 'ViewCount': 3394, 'id': 1182816, 'user_AboutMe': '', 'user_AccountId': 18060.0, 'user_DisplayName': 'Robin Rodricks', 'user_Reputation': 106853.0, 'user_Views': 5431.0, 'user_id': 41021.0}}