A usage of firefox GreaseMonkey

quoted from Greasemonkey’s web site (http://greasemonkey.mozdev.org/) : Greasemonkey is a Firefox extension which lets you to add bits of DHTML (“user scripts”) to any webpage to change it’s behavior. In much the same way that user CSS lets you take control of a webpage’s style, user scripts let you easily control any aspect of a webpage’s design or interaction.

Just tried the firefox greasemonkey — I was trying to use it for enhancing the batch website snapshot-capture script: One problem of the current script is that the mozilla remote control command is asynchronos so it does not know whether the current page has been fully loaded or not before taking the snapshot and moving to the next web site; what it can do is simply to wait for a constant period of time between two web sites. Using a user script that applies to all web sites we can make sure the snapshot-capturing script is notified when every web page is completely loadedbefore it takes the snapshot.

I chose to use xmlhttprequest for simplicity– of course we can use other things such as xml-rpc or soap for the same purposes.

Here is a simple example of such script that uses xmlhttprequest on firefox:

function getXmlHttp() {
    var xmlHttpObject;

    try {
            xmlHttpObject = new XMLHttpRequest();
    } catch (e) {
            xmlHttpObject = false;

    return xmlHttpObject;

var httpRequest = getXmlHttp();

httpRequest.open('GET', 'http://localhost/test1.php', true);

httpRequest.onreadystatechange = function()
  if (httpRequest.readyState == 4)
    { alert(httpRequest.responseText); }


When i tested it i got security exception because the xmlHttpRequest object tries to connect to a host (localhost) that is different than the host of the requested web page URL. To get around this one has to sign the javascript or enable the signed.applets.codebase_principal_support policy on firefox.

About: mmpower

Software Architect & Soccer Fan 黑超白袜 = IT 民工 + 摇滚大叔

21 thoughts on “A usage of firefox GreaseMonkey”

  1. that’s cool, thanks Aaron! Apparently I didn’t have the patient to read through the simple greasemonkey introduction page… 🙁

    btw, I had used your dom-drag script before and quite liked it– thanks for the great work.

Leave a Reply

Your email address will not be published. Required fields are marked *