11

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?

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/… Commented Dec 14, 2012 at 17:55

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

When you say "Also, if the script is installed of a server ...' are you referring to a script installed directly from the web, as opposed to one created locally or downloaded onto the computer before adding it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.