Unofficial news and tips about Google

November 7, 2007

Gmail API for Greasemonkey

Greasemonkey is an integral part of the web experience for many experienced users. Google acknowledges that some people are going to change their own experience of our web applications regardless of what we do. Resistance, as they say, is futile. It would also be somewhat hypocritical. After all, a Google employee wrote Greasemonkey in the first place [my note: Aaron Boodman], another wrote these scripts to add functionality to Gmail [my note: Mihai Parparita], and a third wrote two books on the subject (and these docs) [my note: Mark Pilgrim].

Instead, we would like to provide a little help to make such scripts more robust. Instead of finding elements by XPath or DOM traversal, this API provides accessor methods for getting common screen elements. Instead of forcing you to monkey-patch (ahem) our internal functions, this API provides callbacks to call your functions when specific events occur.

This API is experimental. New features and code changes may still cause Greasemonkey scripts to break.

The first Greasemonkey script that uses this API is Mihai Parparita's Macro, which brings additional keyboard shortcuts to Gmail, and the rest of his already famous scripts should also be ported to Gmail's new codebase. The API is not meant to expose messages, contacts or settings, it's more like a convenient way to customize Gmail's interface and functionality without relying too much on the implementation's details.

No new version for me yet (Sigh!), so I do not have to worry about broken GM plugins.. but then again, why the Gmail updates haven't been implemented to all the accounts? I have never used before a product from an online company that is that slow to update their products.

The API unfortunately doesn't expose messages themselves, only the views and panes, so you need to do some clever hacks to do things with message bodies. That, however, works both for Greasemonkey and GreaseKit users, which is a good thing in and of itself.

On November 17, 2009, two API functions, addNavModule() and getNavModule() stopped working. They now throw an exception with the message "Service H is not registered". Is this an intentional change, or a mistake of some kind?