Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GM_log and other GM functions don't work in Greasemonkey scripts

I have created a "Hello World" Greasemonkey script in Firefox which contains only one line of code:

GM_log("Hello World");

This did not seem to function, at least it did not produce any output in my firebug console.
The same with other GM_... functions like GM_wait

When I replaced:

GM_log("Hello World");

with:

alert("Hello World")

it worked (so the script headers are not the problem).

I have also set the following about:config options to true:

  • javascript.options.showInConsole
  • extensions.firebug.showChromeErrors
  • extensions.firebug.showChromeMessages

Is there some other setting to change for GM_... functions to work in Greasemonkey scripts?

Do I have to change other firebug settings for GM_log messages to show in the firebug console?

like image 310
Thomas Schmidt Avatar asked May 16 '12 14:05

Thomas Schmidt


1 Answers

The reason for this is a new special Metadata Block imperative: @grant, added in GM 1.0. If you need GM_log to work, you have to add this line into your script Metadata Block: "// @grant GM_log" , otherwise it will not work. You can read about this feature at http://wiki.greasespot.net/@grant.

like image 156
gml Avatar answered Nov 12 '22 03:11

gml