|
|
(6 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
| {{DISPLAYTITLE:GM_log}}
| | As of Greasemonkey 4.0, this method has been removed. |
| | | You should use the [https://developer.mozilla.org/en-US/docs/Web/API/console.log console] instead. |
| == Description ==
| |
| | |
| This [[API_reference|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 [[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]]
| |
| | |
| == Syntax ==
| |
| | |
| '''GM_log(''' ''message'' ''')'''
| |
| | |
| :Value: Function
| |
| :Returns: undefined
| |
| :Compatibility: [[Version_history#0.3_beta|Greasemonkey 0.3b+]]
| |
| | |
| :{| cellpadding="5" style="border-style:solid; background:#FFFFE0;"
| |
| |+ Parameters
| |
| !style="background:#CC9900;"|'''Properties'''
| |
| |-
| |
| | <code><span style="background:#FFFFE0;">[[#message |message]]</span></code>
| |
| |}
| |
| :* All properties are optional except [[#message|message]].
| |
| | |
| === Properties ===
| |
| ----
| |
| ==== <code>message</code> ====
| |
| :Value: String, Integer<sup>[1]</sup> or Boolean<sup>[1]</sup>
| |
| :Usage: <code>'''message''' = "ARGHHH!";</code>
| |
| | |
| :* Message to send to the JavaScript error console.
| |
| :* <sup>[1]</sup> 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.
| |
| | |
| == Examples ==
| |
| {{Samp |1=<pre style="border: none; margin: inherit;">
| |
| GM_log("Hello, World!");
| |
| </pre>}}
| |
| | |
| {{Samp |1=<pre style="border: none; margin: inherit;">
| |
| GM_log("Warning, " + someInputField.value + "!");
| |
| </pre>}}
| |
| | |
| == GM_log and Firebug ==
| |
| Since [https://addons.mozilla.org/firefox/addon/1843 Firebug] 1.0, <code>extensions.firebug.showChromeMessages</code> must be set to <code>true</code> for GM_log messages to show up in the Firebug console.
| |
| | |
| It is also recommended to enable <code>extensions.firebug.showChromeErrors</code>, as doing so will reveal syntax errors and script breaks.
| |
| | |
| This can be done from <code>about:config</code>, 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 <code>GM_log</code> converts any passed parameter to a string, and works from the Chrome, it would be more advisable to simply use <code>console.log</code>, which will allow you to take advantage of Firebug's DOM Inspector on the logged objects.
| |
| | |
| [[Category:API_Reference|L]]
| |
As of Greasemonkey 4.0, this method has been removed.
You should use the console instead.