Google Chrome announced its support for GreaseMonkey back in Feb 2010 which opened the gates for GM script writers to write thousands of scripts for Chrome. Any script that doesn’t use specific GreaseMonkey API (GM_*) should work fine with Chrome. However, a study conducted by GreasePot reveals that about 40% of scripts in userscripts.org use GreaseMonkey API. In other words, only 60% of the scripts in userscripts.org will work in Chrome. Top APIs being used include GM_getValue, GM_setValue, GM_xmlhttpRequest. Chrome does not support any of the GreaseMonkey API for security reasons. The rest of the post will sketch out two mechanisms to make your script fully compatible with Chrome.
Google Chrome GM_* emulation
- An userscript to emulate the GreaseMonkey functionalities in Chrome. Supported functions: GM_setValue, GM_getValue, GM_deleteValue, GM_registerMenuCommand, GM_xmlhttpRequest, GM_addStyle.
- GM_getValue and GM_setValue functions use Chrome’s local storage to store the data.
- GM_xmlhttpRequest can be used to make only *same domain* AJAX requests. This is a major limitation with this approach.
- Download and install the script from here.
TamperMonkey
- A Chrome extension which provides enhanced userscript support on Google Chrome and Chromium browsers. All GM_* functions are supported. This is a cleaner solution than the above script.
- GM_xmlhttpRequest is supported with cross domain access.
- A small UI has also been included with the extension from which you can manage the installed scripts.
- The extension also takes care of checking if there are any new versions of the installed userscript is available. This will be useful to keep your userscripts up-to-date. If you a GM script writer, recommend your users to install this extension before installing your script.
- Download and install the extension form here.
-- Varun
No comments:
Post a Comment