This weekend I spent some time playing around with the Google Chrome Extensions API (aka plugin API). I've been kicking some ideas around for a browser plugin, and I thought I would take a look to see how hard it would be to write a Chrome extension. I took a look at developing a Firefox plugin before, but the (apparently) steep learning curve caused me to turn my attention elsewhere.
Getting Started
The documentation for the Extensions API is very well written and well organized. They even have some good tutorial videos to explain some of the more complex parts.
It's really easy to start creating a plugin (hello world!). A minimal plugin requires only a directory containing three files: a simple manifest file in JSON format, an HTML page containing the plugin code, and an icon file. The exploded plugin directory can be loaded/reloaded directly from the Chrome extensions tab, and Chrome even has a built-in tool for signing and packaging the plugin.
APIs and development
Developing a Chrome extension is pretty straightforward; everything is written in HTML and JavaScript, just like an Ajax application. There's no XML configuration to mess around with like with Firefox. The manifest file contains metadata about the plugin; it tells Chrome what kind of plugin you have (there are several different types), lists the plugin's files, and also specifies the "permissions" needed for accessing remote sites via XHR. The plugin code itself is contained in one or more HTML files, and a special non-visible "background" page optionally maintains global (to the plugin) application data. Using callback functions, plugins can listen on various browser events (e.g. tab opening/closing, window focus). Plugins can also manipulate the browser directly; they can manipulate windows and tabs and can of course modify the DOM of loaded pages. There's too much functionality to describe here; the documentation can be found at the Google Chrome Extensions developer site.
Unfortunately, the APIs are still under heavy development and aren't as fully featured as in Firefox. The extension API doesn't have anything like XUL (in Firefox) where you can create native-looking GUI components like dialogs, so developers will have to develop RIA-style interfaces using JavaScript instead of developing interfaces that look and feel like actual UI components that are part of the browser.
Batteries Included
Since Chrome is built on top of WebKit, it includes the same suite of powerful developer tools already available in Safari. This includes a DOM inspector/editor, a JavaScript interactive console, and a JavaScript debugger. There is also a Storage Browser for browsing the embedded HTML 5 database (sqlite) and browser cookies and running SQL queries. There are also some nice tools for optimizing performance like a CPU and memory profiler. All these tools are integrated directly into the browser and don't require any additional setup.
Coming from a Java background, I'm pretty impressed by the easy availability and polish of these tools. In the Java world you need a full-blown IDE to get tools like this, and even then they don't always play nice together or are not that easy to get running. Of course they're not as sophisticated, but it's nice that these are available in every browser without having to tinker around with configurations or install any additional plugins. The polished look and feel of the tools probably comes from the influence of the Apple developers who originally created WebKit (from Konqueror).
The future
It's not clear to me how far authors of the API plan to go in supporting more hooks for interacting with the browser and creating native UI components, since Chrome by nature is fairly streamlined. It would be useful to open up more parts of the browser to the extension API, because otherwise people will have to resort to all kinds of JavaScript tricks and workarounds in order to implement common functionality. Judging by the number of plugins already in the Extension Gallery, it looks like the Chrome extension API has a pretty bright future.
Recent Comments