Reputation: 20354
The Mozilla documentation (https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/console.html) says that I should use console.log
to generate messages from an extension. Those messages are said to appear in the Firefox Error Console. But this is not the case for me. I'm using the Addon builder for the first time today, and I'd like to create an extension that switches tabs on certain events. The tabs are indeed switched, and to a tab which I expected, so my code definitely runs. But the console.log output is nowhere to see.
I have set the filter to "All". All I see are CSS warnings from the addon builder itself.
I have also installed Firebug. It doesn't show anything, too. (This works fine when using console.log from the context of a web page though.) The problem with Firebug would be that it's only enabled for one/some tab anyway, so when switching tabs, it's useless. I need a log window that's always there.
So where will the output from console.log end up?
Upvotes: 4
Views: 6243
Reputation: 37228
Instead of doing var aConsoleService = Cc...
just stick in the following and you can use everything:
Cu.import('resource://gre/modules/devtools/Console.jsm');
can now do whatever, console.log('blah')
, console.time('rawr')
, console.endTime('rawr')
, etc etc etc
Upvotes: 5
Reputation: 71
I guess they changed something, now console.log isn't displayed. I use console.error for debugging, it still shows up in ctrl-shift-j.
This page say something about deprecation of Error Console and using Web Console instead. It's probably related. https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIConsoleService
This doesn't require the sdk.
Upvotes: 2
Reputation: 6229
Just for completeness: in a bootstrapped, non-SDK-based addon, I had to add these two lines in bootstrap.js to have a faked console.log():
var aConsoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
var console = {log:function(str){aConsoleService.logStringMessage(str);}}
Might come in handy for somebody else, I guess..
Upvotes: 2
Reputation: 3090
Go ahead and put a test console.log("something")
in your addon main()
;
If nothing shows up in the Error Console ('Messages' tab), then maybe Firefox isn't configured to show console.log
(happened recently with jetpack sdk 1.14). See: Changes to console.log behaviour in SDK 1.14 for details.
Quick and dirty summary: In about:config
set extensions.sdk.console.logLevel
to "all"
Although from your question:
I have set the filter to "All".
... it sounded like your were already aware of this. So it's not entirely clear what you meant by that.
Upvotes: 10