My favorites | Sign in
Logo
             
Search
for
Updated Sep 16, 2009 by a...@chromium.org
DealingWithGreasemonkey  
A new plan for how to handle Greasemonkey user scripts in Chrome

Introduction

Lots of users still complain that Chrome does not support Greasemonkey user scripts. Even though we have had the infrastructure in place to handle user scripts for some time now, it has never been clear how the feature would relate to full extensions, and so it has remained incomplete.

http://crbug.com/16344 was the previous proposal for rationalizing these two features, but many team members disliked it due to the result of maintaining two parallel systems.

This new proposal is on how we can transparently convert existing .user.js files into extensions. This would make Greasemonkey user script support a first-class feature in Chrome.

Details

Our goal is to be able to click on a .user.js file on the web, get a Chrome extension install experience, and from that point on have a normal, fully-functioning Chrome extension.

A Greasemonkey user script includes:

  1. A unique name (using XML-style namespaces)
  2. A single script file
  3. Some include and exclude rules that control where it runs
  4. References to some Greasemonkey-specific APIs

A Chrome extension with similar functionality to a Greasemonkey script includes:

  1. A randomly-generated unique public key
  2. A unique ID which is a fingerprint of its public key
  3. Some match patterns that control where it runs (mostly compatible with Greasemonkey syntax but different in details)
  4. One or more physical JS files

It should be possible for Chrome to transparently convert a Greasemonkey script into an extension like so:

  1. Hash the user script's unique name into a public key.
  2. Convert Greasemonkey include rules into Chrome extension match patterns. In cases where this isn't possible, use a match pattern that matches everything and evaluate the Greasemonkey rule in JavaScript.
  3. Include a small Greasemonkey emulation layer for the Greasemonkey-specific APIs (we already have this implemented).

With all this in place, we could remove the support for the existing --enable-user-scripts feature, which would simplify lots of our code.

We could also in the future add a developer tool to start a new Chrome extension based on an existing Greasemonkey user script.