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.
You can click on the icon to toggle whether or not Greasemonkey is enabled. You can also click on the drop-down arrow and select "Manage User Scripts" to manage all of your installed Greasemonkey scripts.
To access Greasemonkey's management pane, click on the downward arrow on the right side of the button Greasemonkey to the right of your URL bar and select Manage User Scripts. This opens a tab with a list of your scripts. For each script, you'll find a button to disable or uninstall it.
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.
(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 for capability.policy.default.Window.alert
and delete or reset the value, if it is found.
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.
Use console.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
.
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 you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With