ClojureScript and Chrome extensions

There’s not as much documentation on building a Chrome extension with ClojureScript, so I thought I’d document my findings on the current state of libraries.

Yes, you can of course build Chrome extensions with ClojureScript, as other articles have pointed out. It’s, after all, just Javascript underneath. There’s some set up involved, and the example given hew closely to the Javascript-way of doing things.

Below are some tools that can help you with a more idiomatic way of doing things in Clojure.

chrome-extension: For the initial set up, lein new chrome-extension takes care of the boilerplate. It’s dependencies are a bit out of date, and you’ll find that upgrading ClojureScript will break austin which is referenced by default, so you may need to remove that dependency.

chromebuild: chrome-extension uses chromebuild as a cljsbuild complement, to help move all extension related files to the right place. Chances are you won’t need to interact with it much - just keep in mind it’s there in case you need to add a new folder to your sources (say, for extension CSS files).

khroma: khroma provides idiomatic ClojureScript access to Chrome functions. It’s very much a work in progress. While you’ll find already functions for accessing some Chrome extension classes and functions, others have been neglected so far. I’m in the process of contributing patches for the ones I’m using myself, and others have also expressed interest, so it’s likely to continue moving forward.

Fair warning, though: khroma doesn’t hold your hand and requires at least a passing familiarity with core.async, an area where Clojure for the Brave and True can help. Also, don’t expect to just dive in and start writing code without first getting familiar with the Chrome API - its function names aren’t self-evident right now, so you’ll probably have to work backwards from knowing which even you need to hook with, so you can find the function that wraps it.

Update: I’ve published a project with khroma tests and usage samples, which you can find on Gitlab.

Happy hacking!


Published: 2015-09-21