My userscript prints some information using console.log()
.
This works fine in Chrome, but when I install this userscript in Firefox (Greasemonkey), the web console in Firefox is not displaying anything.
I searched for a solution and some suggested to use unsafeWindow
but it is also not showing any output. Moreover unsafeWindow
cannot be used for chrome. I even installed Firebug but it was no use. How can I resolve this?
For example, I tried this userscript in Firefox:
// ==UserScript==
// @name console
// ==UserScript==
console.log("hello");
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.