Dive Into Greasemonkey

Teaching an old web new tricks

4.2. Testing whether a Greasemonkey function is available

New versions of Greasemonkey expose new functions to user scripts. If you plan to distribute your user scripts, you should check that the Greasemonkey functions you use actually exist.

Example: Alert the user if the GM_xmlhttpRequest function is not available

if (!GM_xmlhttpRequest) {
    alert('Please upgrade to the latest version of Greasemonkey.');
    return;
}
// more code here that uses GM_xmlhttpRequest
← Executing a user script on a domain and all its subdomains
Testing whether a page includes an HTML element →