GM log: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
Aavindraa (talk | contribs)
→‎GM_log and Firebug: a note about strings, alternate method of logging
Aavindraa (talk | contribs)
→‎Description: output example
Line 8: Line 8:


If you aren't seeing your messages, make sure you navigate to [[mozillazine:About:config|about:config]], and change the values of <code>javascript.options.showInConsole</code> and <code>javascript.options.strict</code> to true. This can be helpful for debugging.  
If you aren't seeing your messages, make sure you navigate to [[mozillazine:About:config|about:config]], and change the values of <code>javascript.options.showInConsole</code> and <code>javascript.options.strict</code> to true. This can be helpful for debugging.  
The output produces the namespace, the name of the script, and the string.
For example:
<pre>
#namespace/myScript: Hello World!
</pre>


[[#Examples|Examples]] | [[#GM_log_and_Firebug|GM_log and Firebug]] | [[#Notes|Notes]]
[[#Examples|Examples]] | [[#GM_log_and_Firebug|GM_log and Firebug]] | [[#Notes|Notes]]

Revision as of 18:03, 12 September 2009

Template:Underscore


Greasemonkey Manual
Using Greasemonkey
Installing Scripts
Monkey Menu
Getting Help
User Script Authoring
Editing
Environment
API

Description

This API method allows script authors simple access to logging informational messages in the Error Console.

If you aren't seeing your messages, make sure you navigate to about:config, and change the values of javascript.options.showInConsole and javascript.options.strict to true. This can be helpful for debugging.

The output produces the namespace, the name of the script, and the string.

For example:

#namespace/myScript: Hello World!

Examples | GM_log and Firebug | Notes

Syntax

GM_log( message )

Value: Function
Returns: undefined
Compatibility: Greasemonkey 0.3b+
Parameters
Properties
message
  • All properties are optional except message.

top

Properties


message

Value: String, Integer[1] or Boolean[1]
Usage: message = "ARGHHH!";
  • Message to send to the JavaScript error console.
  • [1] While the value may be a non-string, it will convert the argument to a string. There may also be some instances of visual clipping on large numerical values during conversion. This is a feature present in Mozilla based JavaScript console logging.

top | back

Examples

Template:Core samp

Template:Core samp

top

GM_log and Firebug

Since Firebug 1.0, extensions.firebug.showChromeMessages must be set to true for GM_log messages to show up in the Firebug console.

It is also recommended to enable extensions.firebug.showChromeErrors, as doing so will reveal syntax errors and script breaks.

This can be done from about:config, or from the Firebug GUI. Go to the "Console" tab, then click the arrow next to the tab's name, and ensure that "Show Chrome Errors" and "Show Chrome Messages" are checked.

However, one should note that since GM_log converts any passed parameter to a string, and works from the Chrome, it would be more advisable to simply use console.log, which will allow you to take advantage of Firebug's DOM Inspector on the logged objects.

top

Notes

top