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

隐身守侯 提交于 2019-12-05 07:23:25
Brock Adams

Where did you get GM_wait? That is not a GM function; some people just name their ad-hoc functions that. Note that GM version 0.9.19 broke a lot of timing functionality, but this was fixed in version 0.9.20.

As for GM_log(), that works but it doesn't always put its message in a sensible location. On later versions of Greasemonkey, GM_log() writes to Firefox's Error Console -- which you can open by pressing CtrlShiftJ.
But, as Comentarist said, there is no good reason to use GM_log anymore. It's of limited functionality and does not port well.

All the good browsers now support console.log() natively (No Firebug required), but on Firefox, this also tends to output to Firefox's Error Console.

To use Firebug's excellent logging functions (well worth a look), you currently must use unsafeWindow like so:

unsafeWindow.console.clear ();
unsafeWindow.console.log ("Hello World!");

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.

I'd recommend you forget about GM_log() and use:

console.log('hello world');

http://wiki.greasespot.net/GM_log

Like it says "since GM_log will only display a single string at a time, users with Firebug installed may prefer to use console.log instead."

But about your question, I couldn't say why.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!