最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Does Greasemonkey allow loading local javascript via @require? - Stack Overflow

programmeradmin8浏览0评论

I have tried to include some local Javascript (in the same folder as the GM script) and in both cases, the script fails to load and the scripts seems to stop working until I restart the browser even if the line with the @require is removed.

I tried both

// @require file://script.js

then

// @require file:///full/path/to/script.js

and both options don't work.

Is loading local Javascript banned in Greasemonkey or does it require some extra settings to enable it?

I have tried to include some local Javascript (in the same folder as the GM script) and in both cases, the script fails to load and the scripts seems to stop working until I restart the browser even if the line with the @require is removed.

I tried both

// @require file://script.js

then

// @require file:///full/path/to/script.js

and both options don't work.

Is loading local Javascript banned in Greasemonkey or does it require some extra settings to enable it?

Share Improve this question asked Dec 14, 2012 at 17:35 vfclistsvfclists 20.2k22 gold badges77 silver badges98 bronze badges 1
  • Firefox does block access to local files, you can enable it but i dont know if that will let greasemonkey do it too. kb.mozillazine.org/… – NickSlash Commented Dec 14, 2012 at 17:55
Add a comment  | 

1 Answer 1

Reset to default 17

Yes, you can @require and @resource local files, but the syntax has to be correct. Also, if the script is installed off a server and trying to @require a local file, then extensions.greasemonkey.fileIsGreaseable must be set to true in about:config.

For JS in the same folder as the script:

// @require  Local_Require_1.js


Or use a relative path:

// @require  resources/Local_Require_2.js


A full path:

// @require  file:///D:/Local_Require_3.js

Don't forget the drive letter on Windows.


Note that any or all parts of the @require directive can be case-sensitive, depending on your OS. So, match case exactly.

Also note that when live-editing a script, especially changing @require directives, the script may sometimes silently stop working. If that happens, close the target page tab, uninstall and reinstall the script.

发布评论

评论列表(0)

  1. 暂无评论