How to test a Greasemonkey script, especially on a local copy of a webpage?

I have my own javascript that I need to test with Greasemonkey. I've never worked with Greasemonkey before; How do I test the script?

I am not testing it on the World Wide Web, I have saved the target page (Firefox > Save page as > Web page, complete), so I am testing it locally.

What is the process? How do I test the script?

Here are some guidelines for troubleshooting Greasemonkey scripts, both in general, and on local copies of webpages.

  1. For testing on local pages (without a local web-server), you must change a setting of Greasemonkey.
    Open about:config and set greasemonkey.fileIsGreaseable to true

  2. Make sure the local copy of the webpage is not in the system's /tmp or /temp folder(s). The script will not work reliably, if it is.

  3. Make sure the script source is not in the system's /tmp or /temp folder(s). The script will not install if it is.

  4. For a script to work on local files, be sure you have an appropriate @include directive aimed at the local webpage copy. For example:

    // @include file:///D:/web/local%20page%20copies/*
  5. Familiarize yourself with Firefox's error console (CtrlShiftJ) and how it can be used to determine the source of errors in Greasemonkey scripts.

  6. Install Firebug and get familiar with it. Firebug's excellent console functions work great from within a GM script -- although you might have to preface them with unsafeWindow..

  7. Test as much of the javascript as you can, that doesn't use GM_ functions, in Firebug's JavaScript console first.

See also: