Error Console

From MozillaZine Knowledge Base
Revision as of 10:54, 31 October 2004 by Asqueella (talk | contribs) (tweak the code; add a link to JS coding guidelines)
Jump to navigationJump to search

You can output information to console using the following method:

  1. Declare a global variable (but be sure to use an unique identifier!):
    var gConsoleService = Components.classes['@mozilla.org/consoleservice;1']
                        .getService(Components.interfaces.nsIConsoleService);

    (note, you can also use toJavaScriptConsole() function to open JavaScript console on startup)

  2. Define a function:
    function myExt_logMessage(aMessage) {
      gConsoleService.logStringMessage('My extension: ' + aMessage);
    }
  3. Use it like here:
    myExt_logMessage("Initialized.");

See also: Using dump(), Using Console Service.