Difference between revisions of "Greasemonkey Manual:API"

From GreaseSpot Wiki
Jump to navigationJump to search
m (→‎Notes: Unused and unsupported magic word from last user edit.)
m (Undo revision 3234 by Marti (Talk) FULLPAGENAME is supported and I was using to keep things alphabetical under "*")
Line 40: Line 40:
These functions were restored with updates making them secure, and the new [[unsafeWindow]] object was added, in version 0.5.
These functions were restored with updates making them secure, and the new [[unsafeWindow]] object was added, in version 0.5.

[[Category:API Reference|*]]
[[Category:API Reference|*{{FULLPAGENAME}}]]

Revision as of 00:59, 6 April 2009

Greasemonkey Manual
Using Greasemonkey
Installing Scripts
Monkey Menu
Getting Help
User Script Authoring

What is an API?

An API, or application programming interface, provides a framework, or set of commonly used functions or methods in a program, or in this case, Greasemonkey.

The API Methods

This section of the manual will be short and sweet. As mentioned elsewhere, Greasemonkey provides several methods in its API to enhance the power of user scripts. They will be listed here, with a brief description, but each separate method has its own page with more in-depth information, please continue reading there!


Through JavaScript comments, Greasemonkey has a specialized metadata capability, which gives information about the script, and recently, provides resources and functionality to scripts.


A function intended to get stored values, see GM_setValue below.
A function that accepts the name and value to store, persistently. This value can be retrieved later, even on a different invocation of the script, with GM_getValue.
This deletes a value from chrome that was previously set.
This API method retrieves an array of preference names that start with the branches root.


A function that loads an external resource via a URL, such as an image, and returns the string containing the base64 encoded in the data: URL scheme.
Like the previous, loads raw, plaintext from a resource.


A function that accepts a parameter which will be routed to the Error Console, useful for examining values when writing a script.

Common Task Helpers

This object provides access to the raw javascript window scope of the content page. It is most commonly used to access JavaScript variables on the page.
A function, taking one parameter, a string of CSS to apply to the page.
A version of the xmlHttpRequest method underlying AJAX, this API call does not use the same-origin policy that a script running in a normal page is limited with, allowing complex mashups.
This object provides access to XPath XML and HTML document querying via XPathResult and XPathExpression.


An advanced function which allows a user script to register a menu item, and command to run when clicked, in the Firefox user interface.
Similar in spirit to window.open(), this function accepts a single parameter, the URL of a page to open in a new tab.


All GM_* functions were blocked in version 0.3.5, due to security vulnerabilities. These functions were restored with updates making them secure, and the new unsafeWindow object was added, in version 0.5.