Can Greasemonkey work with the file: // protocol?

I have a simple Greasemonkey script:

// ==UserScript== // @name hello // @namespace http://www.webmonkey.com // @description A test of accessing documents using file:// protocol // @include http* file* // @grant none // ==/UserScript== alert("hi"); 

It works fine as long as the URL is of the form http://... How can I also run the script at the URLs of the form file://... ?

In the "User Settings" section, I have http://* and file://* as the included pages, and in the script section of the Settings, I have http* file* in the "Included Pages" field.

+7
greasemonkey filepath url-scheme
source share
1 answer

See “Lubrication Schemes” in Greasemonkey docs . By default, Greasemonkey ignores the file:// protocol.

In order for scripts to work with file:// paths, you need to open about: config and set extensions.greasemonkey.fileIsGreaseable to true .

You may need to restart Firefox for this setting to take effect.



In addition, // @include http* file* is not valid syntax. You will use:

 // @include http://* // @include https://* // @include file://* 

except to avoid using as much global value as possible. Tune in to the script only on the domain and / or page (s) that you are clearly targeting.

This: avoids unexpected side effects, increases productivity and reduces the likelihood that you are using some kind of “zero day”.


I also recommend deleting user settings for scripts that you write yourself. This will only lead to misery and confusion .;) Use only the script metadata section, only for scripts that you control.

+8
source share

All Articles