Error ConsoleFrom MozillaZine Knowledge Base(Difference between revisions)
Revision as of 00:15, 6 March 2005This page is part of the extension development documentation project. Ask your questions in MozillaZine Forums. Also try browsing example code. Note: development documentation is in process of being moved to Mozilla Development Center (MDC).
What is JavaScript ConsoleJavaScript Console is a tool available in most Mozilla-based applications that is used for reporting errors in the application chrome and in web pages user opens. Despite its name it reports not only Javascript-related errors and warnings, but also CSS errors and arbitrary messages from chrome code. Manipulating data displayed in JavaScript ConsoleInformation displayed in JavaScript Console can be accessed and manipulated through var consoleService = Components.classes['@mozilla.org/consoleservice;1'] .getService(Components.interfaces.nsIConsoleService); Logging custom messages in JavaScript ConsoleThere are two functions in The easy wayTo print simple string messages to JavaScript Console, use the following code: consoleService.logStringMessage("Hello world!"); You may want to create a helper function like this: function myDump(aMessage) { var consoleService = Components.classes["@mozilla.org/consoleservice;1"] .getService(Components.interfaces.nsIConsoleService); consoleService.logStringMessage("My extension: " + aMessage); } You can also use the The advanced wayThe more tricky way is to pass an function myLogToConsole(aMessage, aSourceName, aSourceLine, aLineNumber, aColumnNumber, aFlags, aCategory) { var consoleService = Components.classes["@mozilla.org/consoleservice;1"] .getService(Components.interfaces.nsIConsoleService); var scriptError = Components.classes["@mozilla.org/scripterror;1"] .createInstance(Components.interfaces.nsIScriptError); scriptError.init(aMessage, aSourceName, aSourceLine, aLineNumber, aColumnNumber, aFlags, aCategory); consoleService.logMessage(scriptError); } The above function logs a message like this to JavaScript Console: Warning: function goQuitApplication does not always return a value Source File: chrome://global/content/globalOverlay.js Line: 68 return true; --------------^ Now to the meaning of function's parameters:
An example call, that generates the above warning: myLogToConsole("function goQuitApplication does not always return a value", "chrome://global/content/globalOverlay.js", " return true;", 68, 13, Components.interfaces.nsIScriptError.warningFlag, "XUL javascript"); Using console listeners
Accessing available messages
MiscellaneoustoJavaScriptConsole()If your code is executed in a browser or mail overlay, the Resources
|