maanantai 13. syyskuuta 2010

Google Chrome extensions - my first experience

I have been ignoring browser plugins, not counting rare cases and adblock. Developing one has crossed my mind but there's never been a good reason to jump over the initial barrier. Today, I finally did, since a plugin seemed a sensible way to enhance a javascript application that I have been developing a week or so.

My project was to integrate existing html/css/javascript/css so that some data was fetched from a public game server. I just needed to parse a list of moves from browser's DOM. I thought first that Firefox and greasemonkey would be the best option but it seemed to me that only a single custom javascript file could be used. I don't believe that is the case for such a famous scripting engine but I didn't want to waste my time so I changed plans and headed for Google Chrome.

Chrome's basic development page was almost helpful enough to get everything done. A critical misunderstanding was cleared by founding out a question/answer from, though if I had read the whole Chrome page, I wouldn't have had that problem either.

In that site, there's sample applications that are neatly put in one page with links to API. Also the Hello world application was just what it needed to be. Overall the site is solidly done. However I would have liked also samples that weren't fully functional with particular aspect in mind. Or maybe FAQ. By the way the problem I had was opening new tab with existing resource. It was directly doable as a popup but not as a new tab. The latter needs function calls instead of configuring init file.

So how about technical side of the coin? Basically extensions work almost purely with javascript/css/html and I got my existing app to work with minimal changes. Though because of security issues, I had small inconvenience by defining a Chrome specific listener in a script that was defined in my app's html file. Maybe it's possible to work out it away, dunno.

The extension architecture looks solid: one has a background script that stays alive behind the curtains, so to speak. Message passing is in important role; you use them to localize script environment which makes sense security-wise but also forces user to separate the app into components. The API seemed straightforward and has lots of callbacks using higher order functions. It is a beautiful way to propagate events. Maybe in some cases the code can have too many inner functions but that's mainly my own fault for using anonymous functions.

Debugging felt somehow harder than normally but it's probably because I needed time to understand how things work. Anyway, Chrome's basic development tools provide enough to understand simple problems.

Public deployment of the extension via Chrome's repository would be probably easy but I haven't done that yet. I first want to make the app solid so that people won't rate it poorly. Later versions would suffer because of it.

What I gather from all this is that Chrome seems great browser for enriching the web and I intend to write small extension later since I find it fun to create a javascript application due to its dynamic nature.