Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 782
TheGhost Avatar asked Aug 06 '12 22:08

TheGhost


People also ask

Can a webpage detect a Tampermonkey Userscript?

IF you make any changes to the javascript and/or DOM, it is possibly detectable by the page.

How does Greasemonkey work?

GreaseMonkey is a Firefox extension that lets you run arbitrary Javascript code against selected web pages. What this means is that GreaseMonkey lets you change how other people's web pages look and how they function (but just in your own browser, of course).

Can websites detect scripts?

Yes, in theory, a site can deduce the presence of scripts in various situations. This is not foolproof and usually is way too much trouble for the negligible "threat" to the site. (Then again, some webmasters can be obsessive-paranoids about such things. ;) )


1 Answers

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:

  • Troubleshooting for Script Authors
  • Avoid Common Pitfalls in Greasemonkey
like image 193
Brock Adams Avatar answered Sep 20 '22 15:09

Brock Adams