Search code examples
firefox-addon-sdk

Is there a way to use Firebug's console.log from Firefox's cfx?


Using the Add-on SDK's cfx run command, is it possible to get it to log to Firebug's console instead of the command line one from the main add-on code or content scripts?


Solution

  • You can use the undocumented property unsafeWindow. As its name implies, this is a BAD IDEA. But, as you are only using it for debugging everything should be fine. Please remove these statements when releasing your addon.

    unsafeWindow.console.log("Hello, firebug!");
    

    If you want to make all console calls go to firebug you can put the following in your content script.

    console = unsafeWindow.console;
    

    If you just want log

    console.log = unsafeWindow.console.log
    

    Note: When I was running this on a contentScriptWhen: "start" page-mod I noticed that Firebug hadn't loaded into the console object yet. So if you are using contentScriptWhen: "start" you may need a slight delay before accessing the console.