I am trying to get a Greasemonkey script to run on a page. But it does not.
How do you debug scripts?
What are the smallest possible baby-steps to start a new Greasemonkey script?
I am trying to get a Greasemonkey script to run on a page. But it does not.
How do you debug scripts?
What are the smallest possible baby-steps to start a new Greasemonkey script?
When I was starting with user scripts, my first error was not using wildcards.
// Broken:
// @include https://www.example.com/
// Working:
// @include https://www.example.com/*
That's the simplest way for the script to not even apply, and thus not run at all. In addition, make sure to check for syntax errors; a misplaced semicolon can prevent the script from being parsed, and thus it is ignored.
For me there was a syntax error in the script and Greasemonkey didn't give an error message. Copy-pasting the script to the JS Console revealed the secret.
you can write logs everywhere in your scripts to get better traces of what if being done in them:
GM_log("Hello, World!");
http://wiki.greasespot.net/GM_log
More info: http://wiki.greasespot.net/Greasemonkey_Manual:Other_Useful_Tools#JavaScript_Console
Another tip: Take a look at the whole greasemonkey wiki. They have a lot of good stuff in there: http://wiki.greasespot.net/Main_Page
My greasemonkey script was working; I added a line; it stopped working; I removed the line; it still didn't work.
I determined that greasemonkey had installed a broken updater.php
script when I reloaded the script with the new line added. Reloading the old script kept the broken version of the updater.php
script. I eventually found an error message referring to the updater.php
script in my Firefox Web console. I replaced the updater.php
script with a file containing a comment after loading the new version of the script, and my script started being executed.
On mac, my updater.php
was in: /Users/csimmons/Library/Application Support/Firefox/Profiles/81ri7k71.default/gm_scripts/Extended_LoU_Tweak
You may be able to find a similar updater.php
file in your Firefox default profile gm_scripts/
directory.
In Firefox, open Tools > Error Console and watch it as you load the page. If you're getting overwhelmed by Warnings from the page you can filter on Errors, which still often highlights your script problem.
Also, the syntax of @include
is to have only one matching pattern. If you want another one, add another @include
line.
If the URL of a page is set with Javascript instead of by navigating (like Instagram giving its popup windows a permalink URL), Greasemonkey will show the script as running but it actually won't start. Try reloading the URL and seeing if it actually goes to the same page. If not, you'll have to match the home page URL instead of the popup URL.
I had this trouble too; this was the solution for me:
Check the (and Modify the tricky) part of the code I was working on when it happen
uninstall and reinstall GreaseMonkey
then i got a real error report
EDIT: Today the probleme come more often than usually (new release?) It looks like Firefox web tools are fighting with greasemonkey or JS engine for error messages.
So when you're looking somewhere (ctrl+alt+k) the error message appears somewhere else (try opening the other console) it's like a funny game.