Logging to console from Firefox extension?

我们两清 提交于 2019-11-30 12:54:46

You need to do 2 things:

  1. enable logging for addons

    • in about:config, add a new option "extensions.sdk.console.logLevel" and give it the value "all"

    • restart Firefox

  2. in Firefox open the Browser Console:

    • Tools -> Web developer -> Browser console

    • NOTE: this is different from the usual Web Console used to debug web pages

You should see addons logs there now.

TLTR:

  1. Go to about:config url and create key extensions.sdk.console.logLevel with value all
  2. See log messages either in Browser console (Ctrl+Shift+J) or in terminal you started Firefox from.

cfx or its successor jpm creates this configuration key automatically in development firefox profile.

From logging documentation:

extensions.sdk.console.logLevel: if set, this determines the logging level for all installed SDK-based add-ons.

extensions.extensionID.sdk.console.logLevel, where extensionID is an add-on's Program ID. If set, this determines the logging level for the specified add-on. This overrides the global preference if both preferences are set.

Have you tried console.log() with Firebug? (I know you have tried Application.console.log() and Firebug.console.log() already)

I just tried it in the Web Console on FF16 running Firebug 1.10.4 and it seems to work:

Here are some more examples from the Firebug Wiki itself: FirebugWiki Console API

Additionally, you can write messages of different types in the console, such as: console.debug(), console.info(), console.warn(), console.error()

canuckistani

If you run console.log from Add-on code, it send up in the 'Messages' tab of the Error Console window:

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