Recent from talks
Nothing was collected or created yet.
Greasemonkey
View on Wikipedia
| Greasemonkey | |
|---|---|
| Original author | Aaron Boodman |
| Developers | Anthony Lieuallen, Johan Sundström,[1] 13 more[2] |
| Initial release | 28 March 2005[3] |
| Stable release | 4.13
/ 5 August 2024 |
| Written in | JavaScript, XUL, CSS |
| Operating system | Cross-platform |
| Available in | English |
| Type | Mozilla extension |
| License | MIT License |
| Website | www |
| Repository | |
| Related articles |
|---|
| Origins and lineage |
| Category |
Greasemonkey is a userscript manager made available as a Mozilla Firefox extension. It enables users to install scripts that make on-the-fly changes to web page content after or before the page is loaded in the browser (also known as augmented browsing).
The changes made to the web pages are executed every time the page is viewed, making them effectively permanent for the user running the script.
Greasemonkey can be used for customizing page appearance, adding new functions to web pages (for example, embedding price comparisons within shopping sites), fixing rendering bugs, combining data from multiple web pages, and numerous other purposes.
History
[edit]The Greasemonkey project began 28 November 2004, written by Aaron Boodman.[4][5][6] Boodman was inspired to write Greasemonkey after looking at a Firefox extension designed to clean up the interface of AllMusic,[7] written by Adrian Holovaty, who later became a userscript developer. By May 2005, there were approximately 60 general and 115 site-specific userscripts distributed for Greasemonkey.[7] In July 2005, serious vulnerabilities were found in Greasemonkey by Mark Pilgrim,[8][9] and fixed in the 3.5 version of Greasemonkey.[10] During this time, a Greasemonkey compiler was also developed for converting a userscript into a standalone Firefox extension.[11] Greasemonkey was initially met with complaints by publishers for its ability to block ads.[12] However, this criticism shifted its focus to other addons starting with the 2006 release of Adblock Plus.
Userscripts.org
[edit]To accommodate the growing number of scripts, userscripts.org was founded by Britt Selvitelle and other members of the Greasemonkey community in late 2005. Userscripts.org was open sourced in 2007 but the site later moved away from this code base.[13] As the main script repository listed on Greasemonkey's official site, userscripts.org accumulated thousands of scripts per year.
In 2010, the last known admin Jesse Andrews posted that the site was in maintenance mode due to lack of time and asked for a new maintainer to volunteer.[14] Nevertheless, he remained the sole admin of the site until a discussion about install counts began on 1 April 2013.[15] Prior to this, many of the "most popular scripts" as listed by the site had nominal install counts of zero. Over the following year spam scripts became more common, server downtime increased and the install count bug remained.[16] With no further communication by Andrews, userscript writers described the site as neglected and the official Greasemonkey site removed its front page link.[17][18] In response, script writers and other developers began working on the fork "openuserjs.org",[19][20] and later greasyfork.org,[21] as an immediate replacement.[22]
In May 2014, userscripts.org became inaccessible on port 80, prompting users to access it on port 8080 instead.[16] In August 2014, the site was shut down completely. Most of its scripts were backed up to the static mirror userscripts-mirror.org where they can now be found.[16]
Technical details
[edit]Greasemonkey user scripts are written in JavaScript and manipulate the contents of a web page using the Document Object Model interface. Scripts are generally written to be either page-specific or domain-specific (applying to all pages within a domain) but may also be tagged to apply to all domains for global browser enhancements. Users of Greasemonkey can write or download scripts and save them to their own personal library. When users visit a website matching a script in their personal script library, Greasemonkey invokes the relevant scripts.
Greasemonkey scripts can modify a webpage in any way that JavaScript allows, with certain Greasemonkey security restrictions. Scripts can also access other web pages and web services via a non-domain-restricted XMLHTTP request, allowing external content to be merged with the original page content.
Scripts are named somename.user.js, and Greasemonkey offers to install any such script when a URL ending in that suffix is requested. Greasemonkey scripts contain metadata which specifies the name of the script, a description, resources required by the script, a namespace URL used to differentiate identically named scripts, and URL patterns for which the script is intended to be invoked or not.
Writing a Greasemonkey script is similar to writing JavaScript for a web page, with some additional allowances such as cross-site XMLHttpRequests. Compared to writing a full-fledged Firefox extension, user scripting is a very modest step up in complexity from basic web programming. However, Greasemonkey scripts are limited due to security restrictions imposed by Mozilla's XPCNativeWrappers[23] For example, Greasemonkey scripts do not have access to many of Firefox's components, such as the download manager, I/O processes or its main toolbars. Additionally, Greasemonkey scripts run per instance of a matching webpage. Because of this, managing lists of items globally is difficult. However, script writers have been using cookies, and Greasemonkey even offers APIs such as GM_getValue and GM_setValue to overcome this.
User scripts
[edit]File hosting servers for Greasemonkey require that the URLs for the scripts end with .user.js and not with a MIME type like text/html. Support for HTTPS will meet with[clarification needed] Greasemonkey's built in update checker. As of July 2019, the Greasemonkey project lists three recommended user script hostings:[24]
- Gist, a pastebin service operated by GitHub where simple files are hosted. Files can be pasted into a web form and saved. HTTPS is used by default. Files may follow the naming scheme with the ".user.js" suffix for the URL serving as an install link.
- Greasy Fork, a site created by the maintainer of userstyles.org.[21]
- OpenUserJS.org, a site that started as a fork for the deprecated script repository userscripts.org.[19][20]
Compatibility
[edit]Greasemonkey is available for Firefox, Flock, and GNOME Web (formerly called Epiphany). The Greasemonkey extension for Web is part of the Web extensions package. However, this extension is not fully compatible as of release 2.15.1, since some Greasemonkey API functions (e.g. GM_getValue) are unsupported. There are also custom versions for SeaMonkey,[25][26] Songbird,[27] Pale Moon,[28] qutebrowser,[29] and Falkon browser.
See also
[edit]References
[edit]- ^ boots (23 August 2009). "Greasespot: Outie". Greasespot.
- ^ "The greasemonkey network graph". GitHub.
- ^ "Version history – GreaseSpot Wiki". wiki.greasespot.net.
- ^ "Greasemonkey Project Info". Archived from the original on 25 March 2012. Retrieved 31 August 2011.
- ^ Pilgrim, Mark (2005). Greasemonkey Hacks. O'Reilly. ISBN 978-0-596-55357-9.
- ^ Boodman, Aaron (1 February 2010). "40,000 More Extensions!". Chromium Blog. Retrieved 5 March 2023.
- ^ a b Singel, Ryan (17 May 2005). "Firefox Users Monkey With the Web?". Wired magazine.
- ^ "[Greasemonkey] greasemonkey for secure data over insecure networks / Sites". Archived from the original on 3 March 2020. Retrieved 24 February 2021.
- ^ "Security [LWN.net]".
- ^ "mozdev.org – : /pipermail/greasemonkey/2005-July/004379". mozdev.org. Archived from the original on 29 July 2005.
- ^ Nivi (8 May 2005). "Greasemonkey will blow up business models (as well as your mind)". Archived from the original on 3 June 2006. Retrieved 22 July 2010.
- ^ Festa, Paul (24 March 2005). "Firefox add-on lets surfers tweak sites, but is it safe?". CNET.
- ^ Selvitelle, Britt (3 January 2007). "Userscripts.org... Opensource!". Archived from the original on 17 January 2007. Retrieved 21 May 2014.
- ^ "Passing the torch on userscripts.org". Hacker News. 2010. Retrieved 24 October 2014.
- ^ "Fixing Install Counts". 1 April 2013. Archived from the original on 3 November 2013. Retrieved 21 May 2014.
- ^ a b c Brinkmann, Martin (9 May 2014). "Userscripts.org down for good? Here are alternatives". Retrieved 21 May 2014.
- ^ "User Script Hosting". 16 May 2014. Retrieved 21 May 2014.
- ^ "Please change the official userscript site". greasemonkey-dev (Mailing list). 21 April 2014. Retrieved 21 May 2014.
- ^ a b "OpenUserJS". openuserjs.org.
- ^ a b "Fixing Install Counts – Page 6". 1 April 2013. Archived from the original on 3 November 2013. Retrieved 5 November 2015.
- ^ a b "Greasy Fork". greasyfork.org.
- ^ Barnabe, Jason (19 February 2014). "Introducing Greasy Fork – a user scripts site". Retrieved 5 November 2015.
- ^ "XPCNativeWrapper – MDC Docs". Archived from the original on 28 June 2011. Retrieved 16 March 2011.
- ^ "User Script Hosting – GreaseSpot Wiki". wiki.greasespot.net. Retrieved 22 July 2019.
- ^ "Greasemonkey". mozdev.org. mozdev. Archived from the original on 23 April 2015. Retrieved 5 May 2009.
- ^ "Greasemonkey Port for SeaMonkey – About – OpenUserJS". openuserjs.org.
- ^ ianloic. "Greasemonkey". Songbird. Archived from the original on 2 June 2008. Retrieved 5 May 2009.
- ^ "janekptacijarabaci/greasemonkey". GitHub. Retrieved 23 March 2020.
- ^ "Improvements for GreaseMonkey support · Issue #3238 · qutebrowser/qutebrowser". GitHub. Retrieved 19 May 2020.
External links
[edit]
Media related to Greasemonkey at Wikimedia Commons
Greasemonkey
View on GrokipediaHistory
Origins and early development
Greasemonkey was created by Aaron Boodman on November 28, 2004, as a userscript manager extension for the Mozilla Firefox browser.[12] The extension was designed to enable users to install and run customizable JavaScript code that modifies web pages in real time, allowing alterations to content, structure, and behavior without changing the underlying website code.[13] Boodman's initial motivation stemmed from the growing need for user-driven web customization in the early days of Firefox, where users sought ways to personalize their browsing experience amid the static nature of many websites at the time.[14] He aimed to lower the barrier for non-developers to implement on-the-fly enhancements, such as removing ads, reformatting layouts, or adding interactive features, thereby empowering individuals to augment the web to their preferences.[15] Shortly after its inception, Boodman was joined by early collaborators Anthony Lieuallen and Johan Sundström, who contributed to maintenance and development as the project gained traction.[16] The first public prototype was released on March 28, 2005, marking the extension's broader availability.[17] By May 2005, the ecosystem had expanded rapidly, with more than 100 userscripts available, including both general-purpose tools and site-specific modifications.[15] To support the burgeoning collection of scripts, Userscripts.org was founded in late 2005 by Britt Selvitelle along with other community members, establishing it as the central repository for sharing and discovering Greasemonkey-compatible code.[18]Key milestones and versions
Greasemonkey's early development in 2005 was marked by rapid iterations to address security concerns, with version 0.3.5 released on July 19, 2005, specifically to fix a critical vulnerability that allowed malicious scripts to exploit browser privileges.[19] This update removed vulnerable features and urged all users to upgrade immediately to mitigate potential exploits.[17] Subsequent releases, such as version 0.5.1 on August 25, 2005, further hardened security by patching script privilege escalation issues.[20] A significant external challenge occurred in May 2014 when Userscripts.org, the primary repository for Greasemonkey scripts, was shut down due to severe security breaches and hacking incidents, prompting the community to migrate hosting to alternative platforms like Greasy Fork and OpenUserJS.org.[21] This event disrupted script distribution but spurred the growth of decentralized hosting solutions within the userscript ecosystem.[22] Development faced another pivot with Firefox's transition to the WebExtensions API in 2017, which deprecated legacy extensions; Greasemonkey's team restarted active work to adapt, culminating in version 4.0's release on November 2, 2017.[23] This major rewrite ensured compatibility with Firefox 57 and later but initially omitted some legacy features like certain API behaviors, with promises of gradual restorations in subsequent updates. Between 2017 and 2019, ongoing adaptations to Firefox's evolving extension policies, including stricter sandboxing and API restrictions, maintained Greasemonkey's viability amid browser changes.[24] The project continues under the MIT license, with maintenance handled by over 13 developers following the initial core team, fostering community-driven improvements.[2] The latest stable release, version 4.13 on August 5, 2024, supports Firefox 58.0 and later versions, including Android, while adding features like enhanced tab opening APIs and fixing script update mechanisms.[25]Features
Core capabilities
Greasemonkey enables users to install and execute JavaScript userscripts that modify web pages after they load, allowing alterations to the page's display, behavior, or content.[26] These scripts run automatically on matching URLs, injecting custom code to enhance or customize the browsing experience without altering the original website.[2] At its core, Greasemonkey supports on-the-fly changes through userscripts, such as adding new features like ad blocking, UI enhancements, automating user interactions, or integrating external data sources into the page.[27] For instance, scripts can hide unwanted elements, rearrange layouts, or fetch and display additional information from APIs, all executed dynamically as the page renders.[1] Userscripts leverage Document Object Model (DOM) manipulation to inject or modify HTML, CSS, and JavaScript elements in real time.[28] This includes accessing and altering the page'sdocument object via wrapped interfaces, enabling precise changes like inserting new buttons or styling overrides while the page is active.[28]
To ensure security, Greasemonkey employs a permissions model where scripts operate in isolated sandboxed contexts, granting access to the host page's DOM but restricting direct cross-origin requests unless explicitly permitted through enhanced APIs like GM.xmlHttpRequest.[29] This isolation uses XPCNativeWrapper to prevent unauthorized interactions, balancing functionality with protection against malicious code.[28]
Common applications include customizing social media feeds by filtering content or adding previews, enhancing search engine results with additional annotations, and implementing site-specific keyboard shortcuts for quicker navigation.[27] These capabilities make Greasemonkey a powerful tool for personalized web augmentation.[2]
Script management tools
Greasemonkey provides a centralized dashboard for managing installed user scripts, accessible through the Monkey Menu icon in the Firefox toolbar. This interface lists all scripts alphabetically by name, with enabled scripts displayed in full color and disabled ones in gray for quick visual identification. Users can view script details, including metadata such as @name, @namespace, and applicable domains via @include, @exclude, or @match directives. From here, scripts can be enabled or disabled individually by toggling checkboxes or selecting options in the detail view, allowing precise control over which scripts run on specific pages.[30] Automatic update checking is a key feature for maintaining script currency, triggered for scripts containing a @version directive in their metadata block. Greasemonkey periodically—by default every seven days—fetches the script from its original installation URL or a specified @updateURL if provided, comparing the remote @version against the installed one using semantic versioning rules. If a newer version is detected, Greasemonkey prompts the user for installation, automatically applying the update upon confirmation to ensure scripts remain functional and secure. Users can also manually initiate checks or toggle auto-updates globally via the dashboard's options.[31][32] A global toggle for script activation is available directly in the Monkey Menu, positioned at the top for easy access. When activated, this option disables all user scripts across the browser session, providing a quick way to troubleshoot issues or pause customizations without uninstalling. Re-enabling restores full functionality, with the monkey icon in the toolbar serving as the primary control point for this feature.[30] Script editing is supported through an embedded editor integrated into the dashboard. Selecting a script and choosing the edit option opens its source code in a multi-tab interface, where the main script appears in the first tab and any @require or @resource files in subsequent tabs. Changes can be saved directly with Ctrl+S or the save icon, applying modifications immediately upon browser reload for testing purposes; however, live reloading without restart is not natively supported in version 4.0 due to WebExtension limitations. External editors are not integrated, requiring manual file management for advanced workflows.[33] Greasemonkey executes scripts in the order displayed in the management interface, which sorts them alphabetically by @name by default.[30] This order determines the sequence of execution, with earlier scripts running first and potentially affecting the DOM for later ones. To mitigate conflicts, users can adjust the execution order directly via right-click context menu options such as 'Execute first,' 'Execute sooner,' 'Execute later,' or 'Execute last'; no drag-and-drop reordering is available.[34]Technical aspects
Implementation and execution
Greasemonkey is implemented primarily in JavaScript, leveraging the WebExtensions API for its core functionality in modern Firefox versions, while legacy versions prior to Firefox 57 utilized XUL for user interface elements and CSS for styling.[2][35] Scripts managed by Greasemonkey execute at specific timings controlled by the@run-at metadata directive, with document-end as the default, occurring after the document's HTML is parsed but before external resources like images fully load, at which point document.readyState is "interactive". Alternative timings include document-start, which injects the script early during page loading when document.readyState is "loading", and document-idle, which delays execution until after the page and all its resources, including scripts, have fully loaded. These options allow scripts to intervene at precise points in the page lifecycle, though support for document-start and document-idle is limited in Greasemonkey 4.x, with document-end being the only fully guaranteed timing.[31]
User scripts in Greasemonkey 4.x are injected as content scripts using the WebExtensions API, executing in an isolated JavaScript context (isolated world) separate from the page's JavaScript environment. This isolation prevents direct access to the page's variables and functions while allowing full read/write access to the DOM via the page's window and document objects. Scripts are executed within an anonymous function to avoid global namespace pollution, unless the @unwrap directive is specified in the metadata, which injects the script without the wrapper for compatibility purposes. The extension provides access to enhanced Greasemonkey APIs for privileged operations.[36]
Cross-site XMLHttpRequest (XHR) operations are supported through the GM.xmlHttpRequest API, which bypasses same-origin policy restrictions, allowing scripts to make requests to any domain provided the necessary permissions are granted via the @grant metadata directive, such as @grant GM.xmlHttpRequest. When @grant none is used, scripts rely on the standard XMLHttpRequest object, which adheres to CORS policies and may restrict cross-site access unless the target server permits it, thereby preventing unauthorized data exfiltration. This permission model ensures controlled access to network resources without compromising browser security.[37]
Error handling in Greasemonkey directs script failures to the browser's console for logging, where developers can inspect JavaScript errors, warnings, and custom logs via GM_log or console.log, without causing the extension to crash or halt overall functionality. Users can configure scripts to ignore non-critical errors or enable debugging modes to isolate issues, maintaining stability even if individual scripts encounter runtime exceptions.[38]
Metadata and APIs
Greasemonkey userscripts begin with a required metadata block enclosed in// ==UserScript== and // ==/UserScript== comments, which provides essential information for the extension to identify, install, and execute the script.[31] The block must include the // @name directive to specify a unique script name within its namespace, the // @namespace directive to define a unique identifier such as a URL for avoiding conflicts, and the // @version directive to indicate the script's version number for update management.[31] Additionally, matching directives such as // @include, // @match, or // @exclude are used to define URL patterns where the script should or should not run, using wildcard or glob-like matching to specify execution scope.[31]
Optional metadata headers enhance script discoverability and management without affecting core functionality. The // @description directive provides a brief summary of the script's purpose, while the // @author directive credits the creator.[31] For more precise URL targeting, the // @match directive employs glob-like match patterns, such as https://www.example.com/*, to determine applicability on specific pages.[31]
Upon installation, the Greasemonkey extension parses the metadata block at the script's top level, validating required headers and ignoring unrecognized keys to ensure integrity.[31] It uses the combined name and namespace for uniqueness, version for automatic updates, and URL patterns from include, exclude, or match directives to set execution scope and permissions, processing this information to manage script activation without executing the block's content.[31]
Greasemonkey provides a suite of native APIs prefixed with GM_ to extend userscript capabilities beyond standard JavaScript, focusing on secure and persistent operations. The GM_xmlhttpRequest function enables cross-domain HTTP requests, bypassing same-origin policy restrictions by accepting parameters like method, URL, headers, and callbacks for onload events.[39] For data persistence, GM.setValue(key, value) asynchronously stores key-value pairs across sessions (returns a Promise), while GM.getValue(key, defaultValue?) asynchronously retrieves them (also returns a Promise). These support various data types, with the key as a string. For compatibility with legacy scripts, polyfills may be used, but new scripts should handle the asynchronous nature using async/await or .then(). The GM_addStyle function injects custom CSS into the page by passing a string of styles, such as "body { background-color: yellow; }", to modify appearance dynamically.[40][41]
These GM_ APIs maintain compatibility with similar functions in other userscript managers like Violentmonkey and Tampermonkey, allowing scripts to function across platforms with minimal adjustments, though Greasemonkey emphasizes its native implementations for Firefox environments.[39]
Usage and installation
Browser compatibility
Greasemonkey primarily supports Mozilla Firefox versions 57 and later, functioning as a WebExtensions-compatible add-on that allows users to manage and execute userscripts across web pages.[35] This compatibility ensures seamless integration with modern Firefox features, including enhanced security and performance optimizations introduced in the WebExtensions API. Legacy versions of Greasemonkey, based on the XUL framework, remain compatible with Firefox 4 through 56, enabling continued use on older installations that do not support WebExtensions.[24] Community-maintained ports extend this legacy support to other Mozilla-derived browsers, such as SeaMonkey and Pale Moon, where adapted versions preserve XUL-based functionality for users preferring these forks.[42][43] Additional ports exist for Falkon and qutebrowser, allowing userscript management in these QtWebEngine and keyboard-centric browsers, respectively, though with varying degrees of feature parity to the Firefox implementation. However, it lacks native support for Google Chrome or Microsoft Edge, necessitating alternatives like Tampermonkey for userscript functionality in those environments.[44] As a browser extension, Greasemonkey is platform-independent, running on Windows, macOS, Linux, and Android through compatible Firefox installations.[2] In 2024, updates to Greasemonkey ensured alignment with Firefox's ongoing WebExtensions evolution.[45]Setup and basic usage
To install Greasemonkey, users should visit the official Firefox Add-ons page and click the "Add to Firefox" button, which downloads and prompts for installation of the extension. On Android, installation follows the same process via the Firefox browser's add-ons menu.[1] Once installed, Greasemonkey appears in the browser's toolbar as a monkey icon; if not visible, access it via the Add-ons Manager atabout:addons to enable it.[16] During or after installation, Firefox requests permissions for Greasemonkey to access and modify web content on all sites, which must be granted to allow script injection; denying this prevents functionality.[1]
For the first script, locate a user script file ending in .user.js—either by downloading it or navigating directly to a hosted URL—and open it in Firefox, triggering Greasemonkey's installation dialog.[46] The dialog displays the script's metadata, including its name, description, author, version, and rules like @include or @exclude patterns that define target websites.[46] Review this information, wait for a brief security delay that enables the "Install" button, then click it to add the script; to verify execution, navigate to a matching site (e.g., one specified in @include), where the script should apply its modifications automatically.[46]
In basic usage, open the Greasemonkey dashboard by clicking the toolbar icon (Monkey Menu), which lists all installed scripts with options to enable, disable, or edit them.[46] Browse to a target website; active scripts run on load, and you can toggle them individually via the dashboard if needed to test effects.[46] To monitor output or errors, open the Browser Console (Ctrl+Shift+J or Cmd+Shift+J on macOS) and check for script logs or issues.[38]
Common setup issues include the extension not being enabled, resolved by visiting about:addons, selecting Extensions, and toggling Greasemonkey on, followed by a browser restart.[38] If a script fails to run, refresh the page (Ctrl+R or Cmd+R) after installation or toggling, as changes may not apply immediately.[38] Mismatches in @include patterns—such as incorrect URL wildcards—can prevent execution; inspect these in the installation dialog or dashboard to ensure they align with the site's domain and path.[46]
Greasemonkey incorporates security prompts during script installation to mitigate risks from malicious code, requiring explicit user confirmation via the dialog and imposing a short delay before the "Install" option activates, giving time to review metadata and abort if suspicious.[46] This process ensures users intentionally approve each addition, preventing drive-by installations.[46]