Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 do I also get the script to run on URLs of the form file://...?

In the User Settings section I have http://* and file://* as the included pages and in the Script Settings section I have http* file* in the "Included Pages" box.

like image 564
Sol Avatar asked Nov 11 '13 15:11

Sol


1 Answers

See "Greaseable schemes" in the Greasemonkey docs. Greasemonkey ignores the file:// protocol by default.

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

You might possibly have to restart Firefox for this setting to take effect.



Also, // @include http* file* is invalid syntax. You would use:

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

except, avoid using such global includes as much as you can. Tune to the script to just the domain(s) and/or page(s) you explicitly target.

This: avoids unexpected side effects, increases performance, and reduces the chances of being pwned by some "zero day" exploit.


I also recommend that you delete the User Settings options for scripts you write yourself. This will only lead to heartache and confusion later. ;) Use the metadata section of the script, only, for scripts you control.

like image 93
Brock Adams Avatar answered Oct 16 '22 04:10

Brock Adams