My very simple Greasemonkey script is not running?
I am having issues with this very basic Greasemonkey script, most likely with the metadata configuration.
Here is the full source of the basic file
// ==UserScript==
// @name Google Hello
// @namespace https://google.com
// @description Basic Google Hello
// @include *
// @version 1
// ==/UserScript==
alert("hi google!");
This script should run when I access Google.com, but the alert is not popping up. What is the issue?
I am attempting to run this script on Ubuntu with Firefox.
If alerts()
are not firing, chances are you may have clicked Firefox's Prevent this page from creating additional dialogs
option, or set a browser preference (older versions of Firefox), or Firefox may have become unstable in memory.
Universal Greasemonkey debug steps:
(With one step added for problems with alert()
.)
First make sure that the script is even firing for the page in question.
While browsing that page, click on the down-triangle next to the Greasemonkey icon (Alternatively, you can Open Tools -> Greasemonkey on the Firefox menu.) and verify that the expected script name appears and is checked. EG:
-
See if there are any relevant messages/errors on Firefox's Browser Console.
Activate the console by pressing CtrlShiftJ, or equivalent.Here's a screenshot showing how both messages and errors appear in the Browser Console -- caused by both the web page and the Greasemonkey script:
Open
about:config
, search forcapability.policy.default.Window.alert
and delete or reset the value, if it is found.- Uninstall the Greasemonkey script.
- Completely clear the browser cache.
- Shutdown Firefox completely. Use Task Manager, or equivalent, to verify that there is no Firefox thread/task/process in memory.
- Restart Firefox.
- Install the Greasemonkey script afresh.
- If it still doesn't work, create a new Firefox profile or try a different computer altogether.
Additional issues:
Please supply your versions of three things: (1) The OS, (2) Firefox, (3) Greasemonkey or Tampermonkey or Scriptish, etc.
@include *
means that the script will fire for every page! This is almost always a poor practice. (There are some exceptions, but your case is not one.)@namespace
does not control where the page runs. The only thing@namespace
does is allow more than one script to have the same name (as long as their@namespace
s are different). See the@namespace
documentation.Avoid using
alert()
for debugging. It's annoying and can mask timing problems.
Useconsole.log()
. You can see the results, and helpful error messages (hint, hint) on the Browser Console.-
Google almost always uses/redirects to
www.google.com
(For English USA users). So,// @include https://google.com
will almost never work like you want.Recommend you use:
// @match *://www.google.com/*
as a starting point.
In Firefox Greasemonkey, you can also use the magic
.tld
to support most of Google's international domains, like so:// @include http://www.google.tld/* // @include https://www.google.tld/*
Use both lines. Note that this does not perform as well as the
@match
line does. So, if you only care about one nation/locale, just use@match
.
Putting it all together:
- Uninstall your script.
- Restart Firefox.
-
Install this script:
// ==UserScript== // @name Google Hello // @namespace John Galt // @description Basic Google Hello // @match *://www.google.com/* // @version 1 // @grant none // ==/UserScript== console.log ("Hi Google!");
Visit Google and note the results on Firefox's Browser Console.
- If there is still a problem, follow all of the debug steps above.
- If there is still a problem, Open a new question and supply ALL of the following:
- The three versions, mentioned above.
- The relevant errors and messages you get on the Browser Console.
- The exact code and steps needed to duplicate the problem. Make an MCVE for this!
- A short summary of what you have tried to solve the problem.