Console logging from a Firefox add-on

北城以北 提交于 2019-12-04 12:38:13

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.

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

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..

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!