Greasemonkey
A Mozilla Firefox extension and the user-script format it popularized, which lets ordinary JavaScript files modify, augment, or rewrite arbitrary web pages on the fly.
Created by Aaron Boodman
Greasemonkey is a Mozilla Firefox extension — and, by extension, the user-script format it established — that lets a user attach small JavaScript programs to specific web pages. When a matching page loads, Greasemonkey runs the user’s script after the page’s own scripts, giving the user the power to add, remove, or rewrite arbitrary parts of the page.
Strictly speaking, Greasemonkey is not a programming language: a Greasemonkey “script” is just a JavaScript file with a structured comment header that tells the extension where and how to run it. But that header, together with a small set of GM_* helper APIs, became a de facto specification that several other extensions adopted, and the resulting “user script” format is what most people mean when they talk about Greasemonkey today.
History and Origins
Greasemonkey was created by Aaron Boodman and first released in 2004 as a Firefox extension. At the time, end-user customization of the web typically meant bookmarklets — short snippets of JavaScript stored in a browser bookmark that the user clicked to run on the current page. Greasemonkey generalized that idea: instead of clicking a bookmark each time, the user installed a script once, declared which URLs it should apply to, and let the browser run it automatically thereafter.
Within a year of release, the project had attracted enough attention to spawn O’Reilly’s Greasemonkey Hacks (2005, by Mark Pilgrim) and the userscripts.org community site. A 2005 security incident, in which early versions of the extension exposed the local file system to web pages through the same APIs that scripts used, forced a redesign of the sandboxing model and underscored that user scripts were a security-sensitive feature rather than a casual toy.
For roughly a decade, the format flourished on top of Mozilla’s old XUL/XPCOM extension system, which gave the extension privileged access to the browser. The 2017 transition to WebExtensions, the cross-browser extension model now used by Firefox and Chromium-based browsers, forced Greasemonkey to be rewritten from scratch as Greasemonkey 4.x. The rewrite preserved the user-script metadata format but removed or restricted several GM_* APIs, and the resulting incompatibility split the community: many users migrated to Tampermonkey or Violentmonkey, which retained broader compatibility with older scripts.
Design Philosophy
Greasemonkey’s design rests on a few clear ideas:
- The user is in charge of the page. Web pages are content delivered to the user’s machine; the user has the right to modify them in their own browser.
- Scripts are JavaScript. Rather than inventing a new language, Greasemonkey leans on the language already running in the browser. Anyone who can write JavaScript can write a user script.
- A small header is the API contract. The metadata block declares matching rules, required permissions, and dependencies, and changes very rarely. Most innovation happens inside the script body.
- Per-script sandboxing. Each script runs in its own isolated scope, with limited access to page globals through a controlled bridge. This both protects the page from buggy scripts and protects the user from malicious ones.
- Local-first. Scripts live on the user’s machine, run in the user’s browser, and persist data through the user’s profile.
The User-Script Format
A Greasemonkey script is a JavaScript file (.user.js) that begins with a metadata block:
| |
Important metadata keys include:
| Key | Purpose |
|---|---|
@name, @namespace, @version | Identification and update tracking |
@match / @include / @exclude | URL patterns deciding which pages run the script |
@grant | Declares which privileged GM_* APIs the script needs |
@require | Loads an external JavaScript library before the script runs |
@resource | Bundles a static resource accessible via GM_getResourceText |
@run-at | Phase in which to inject the script (document-start, document-end, document-idle) |
The GM_* family of helper functions historically gave scripts capabilities the page itself could not have, such as cross-origin HTTP requests (GM_xmlhttpRequest) and persistent per-script storage (GM_setValue / GM_getValue). The WebExtensions rewrite renamed several of these to a promise-based GM.* namespace and removed some legacy variants.
Key Features
- Targeted injection. Scripts run only on pages whose URL matches their
@matchor@includerules, with@excluderules for carve-outs. - Privileged helpers.
GM_xmlhttpRequestallows requests to origins the page itself could not reach;GM_setValue/GM_getValueprovide per-script persistent storage independent of cookies andlocalStorage. - External libraries.
@requirepulls in JavaScript libraries (jQuery was a common choice in the format’s heyday), letting authors write higher-level code in a small script. - Resource bundling.
@resourcedeclarations attach static files (CSS, images, JSON) that the script can access at runtime. - Isolated scopes. Each script gets its own global scope, preventing accidental collisions with the page or with other user scripts.
Evolution
The user-script format has stayed remarkably stable since 2004, but its surrounding world has changed considerably:
- Browser model changes. Firefox’s Quantum release in 2017 retired the XUL/XPCOM extension system, forcing a WebExtensions rewrite. Chromium’s Manifest V2 → V3 transition has imposed similar constraints on the Chrome-side ecosystems that adopted the format.
- Ecosystem competitors. Tampermonkey (2010) brought the Greasemonkey format to Chrome and later to Edge, Safari, and Opera. Violentmonkey offers an open-source alternative across browsers. Scriptish, a Firefox-only fork, attempted to extend the API but is now defunct.
- Repository churn. userscripts.org, the longtime central repository, eventually went offline. Greasy Fork, launched in 2014, has taken its place as the most-used hub for sharing scripts.
- Security and trust. As scripts gained the ability to request cross-origin data and modify any page, the user-script community has had to wrestle with the same supply-chain risks that affect any code-sharing ecosystem.
Current Relevance
Greasemonkey itself, the original Firefox extension, is still maintained and still works, but most active scripting today happens through Tampermonkey or Violentmonkey, simply because they support more browsers and a slightly larger API surface. The format, on the other hand, is healthier than ever: Greasy Fork hosts a large catalog of community scripts that target everything from major social networks to obscure corners of the web.
User scripting also continues to serve as a low-friction prototyping tool. Browser extensions require packaging, signing, and a manifest of permissions; a Greasemonkey-compatible script is a single JavaScript file that a user can copy, paste, and edit. For tinkerers, students, and people who simply want to fix a small annoyance on a site they use every day, that immediacy is the format’s enduring appeal.
Why It Matters
Greasemonkey was one of the earliest and most influential expressions of the idea that the browser belongs to its user. By letting anyone with a little JavaScript reshape the pages they visited, it predated and shaped much of the modern extension ecosystem: ad blockers, accessibility add-ons, privacy tools, and per-site tweakers all draw on the same lineage. Its metadata header — // ==UserScript== ... // ==/UserScript== — has become a small but stable piece of web culture, recognized far beyond the extension that introduced it.
For programmers, Greasemonkey is also a reminder that a “language” need not be a new syntax or a new runtime. A handful of comment conventions and a few helper APIs, bolted on top of an existing language and platform, were enough to launch an ecosystem that has outlasted browsers, extension models, and central repositories alike.
Timeline
Notable Uses & Legacy
Greasy Fork
A community-run repository hosting tens of thousands of user scripts written in the Greasemonkey metadata format, covering everything from ad and tracker removal to site-specific tweaks for sites like YouTube, Reddit, and GitHub.
Tampermonkey ecosystem
Although Tampermonkey is a separate extension, it consumes scripts written in the Greasemonkey metadata format. The two ecosystems share a vast library of community scripts that target sites across the web.
Accessibility and usability tweaks
Users with specific accessibility needs have long relied on Greasemonkey scripts to enlarge fonts, recolor pages, add keyboard shortcuts, or strip animations from sites that lack such options natively.
Web research and scraping
Researchers and journalists have used Greasemonkey scripts to annotate, extract, or reformat data from web pages — for example, surfacing hidden metadata or normalizing inconsistent listings.
Site-specific patches
Communities around games, forums, and webmail services have historically maintained scripts that restore removed features, fix bugs, or add quality-of-life improvements that the site operators had not implemented.