I want to use clojurescript to write chrome extensions.
Another major difference between Chrome extensions and web apps is the fact that while extensions are used to enhance the functionality of the Chrome Browser, web apps run within the browser having a different user interface. Unlike web applications, extensions have little or sometimes no UI component.
Open the Chrome Web Store. Find and select the extension you want. Click Add to Chrome. Some extensions will let you know if they need certain permissions or data.
Extensions are software programs, built on web technologies (such as HTML, CSS, and JavaScript) that enable users to customize the Chrome browsing experience.
Google is planning to remove inline installation from Chrome for existing extensions starting on September 12th, and Chrome users will be redirected to the Web Store.
Chrome extensions are generally made with HTML/CSS/JS so ClojureScript should work just fine because it compiles to JavaScript. That being said, I don't think anyone has actually built a large extension with ClojureScript yet. As a proof of concept here's a general outline of how to make a simple alert extension that will say Zaboomafoo (sorry for that name):
Install Leiningen and lein-cljsbuild first. Read the docs for lein-cljsbuild and check out the wiki on ClojureScript to understand how to use lein-cljsbuild for projects and compiling.
Make a ClojureScript file that displays an alert saying "Zaboomafoo" like this:
(ns Zaboomafoo.hello)
(js/alert "Zaboomafoo")
Compile this with lein cljsbuild
to get a JavaScript file. Then add a basic HTML file and manifest.json for the extension.
Zaboomafoo.html:
<!Doctype html>
<html>
<head>
<title>Zaboomafoo!</title>
</head>
<body>
<script type="text/javascript" src="Zaboomafoo.js"></script>
</body>
</html>
manifest.json:
{
"name": "Displays Zaboomafoo when opening a new tab",
"version": "0.1",
"incognito": "split",
"chrome_url_overrides": {
"newtab": "Zaboomafoo.html"
},
"manifest_version": 2
}
Put the new manifest.json, Zaboomafoo.html, and Zaboomafoo.js into a folder somewhere obvious. Finally, go to the chrome extension page, turn on developer mode, load unpacked extension, and open a new tab. The extension should load an alert that annoyingly says "Zaboomafoo" when you open the tab. Hopefully making browser extensions gets to be a little more popular but this is the general flow of it.
I have just released a simple Chrome extension sample project along with some documentation: https://github.com/binaryage/chromex-sample
It uses Chromex library: https://github.com/binaryage/chromex
Disclaimer: I'm author of the library
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With