简体   繁体   中英

Firefox Addon console.log() Not working

So I need to check some results in a Firefox add-on I'm working on, however the console.log() does not work. I've tried simply putting, console.log("Hello World"); in the main.js file and loading it, but it doesn't log anything.

By default the minimum log level is error . Everything else is not printed, and that includes console.log() . Please see the Log Levels for more information on how to use and configure logging and associated levels.

If you are working on an extension/addon (not SDK), simply import the Console.jsm and then the console.log() will work normally. That is what I do.

Components.utils.import('resource://gre/modules/devtools/Console.jsm');

Update: As of Firefox 44+

Components.utils.import('resource://gre/modules/Console.jsm');

You can use Firebug for your firefox extension development. If you install this add-on, you can use its console with "Firebug.Console.log();" command. Please be careful, in this command you should not type "Console" with a small letter!

In addition, you can use Firefox "Browser Console" (not Web Console) by the following command: Application.console.log();

Using the Addon SDK? You must set the Log level for your extension:

var self = require("sdk/self"); 
var prefService = require("sdk/preferences/service");  
prefService.set('extensions.'+ self.id +'.sdk.console.logLevel','all');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM