console.log is not working when used in a Firefox, Greasemonkey script

Wait a minute: if the question is about logging in the console with Greasemonkey (I could swear I saw the tag greasemonkey), why not use the GM_log method?

// ==UserScript==
// @name          GM_log Example
// @namespace     http://www.example.com/
// ==/UserScript==

GM_log("This is an example of GM_log");

Or am I missing something?

PS: you can also check for javascript.options.showInConsole in about:config. it should be true.


I found that (testing with Chrome/Tampermonkey) you need:

window.log("<message goes here>");, not unsafeWindow.console.log("<msg>");, as unsafeWindow and console come up as undefined.

Try that, as I'm pretty sure that's the way you're supposed to do it in later versions of browsers, etc.


You mean it doesn't work when installed via Greasemonkey, right?
Not long ago, Greasemonkey broke console.log (New! Bug report). Now, to see the results of a plain console.log() call from a Greasemonkey, you need to look in Firefox's Error console, not Firebug's.

You can see FF's Error console by pressing: CtrlShiftJ.

However, you can use unsafeWindow.console.log() in both Chrome and Greasemonkey scripts. Chrome now has limited support for unsafeWindow.

If you use unsafeWindow, you have access to the full range of Firebug's logging functions from Greasemonkey. (Firebug must be installed and they still might not work in Chrome userscripts; I haven't tested that way in a while.)


In Firefox, if Firebug is not installed, or it is not active for the page, then unsafeWindow.console.log() calls will display to the New "Web Console" (CtrlShiftK).
You need to use the unsafeWindow when inside a Greasemonkey script.

Note that Firefox currently supports console.log(), console.info(), console.warn(), and console.error() natively -- no Firebug required.