Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging to console from Firefox extension?

I understand that I can log to the console when using a Firefox extension with the cfx run command.

Is there a way to log to a console after the extension has been packaged with cfx xpi? Logging to Firebug is fine if possible.

I have found two blog posts about this (here and here). Both are rather old and don't work any more.

I'm using version 1.10 of the add-on SDK and FF15.

like image 671
David Tuite Avatar asked Oct 15 '12 10:10

David Tuite


People also ask

How do I open the console log in Firefox?

You can open the Browser Console in one of two ways: from the menu: select “Browser Console” from the Web Developer submenu in the Firefox Menu (or Tools menu if you display the menu bar or are on macOS). from the keyboard: press Ctrl + Shift + J (or Cmd + Shift + J on a Mac).

How do I debug Firefox extensions?

in the Firefox menu (or Tools menu if you display the menu bar or are on macOS), click Web Developer then Debugger. press Ctrl + Shift + i ( Command + Option + i on macOS) and click Debugger.


2 Answers

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

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

like image 163
mindrones Avatar answered Jan 01 '23 01:01

mindrones


TLDR:

  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.

like image 34
czerny Avatar answered Jan 01 '23 02:01

czerny