Home

Awesome

The chrome-scalajs-template

Scala Steward badge

This is an opinionated template that can help you to get started fast while building browser extensions with scala-js.

NOTE Be aware that this template targets the Manifest Version 2, track the Manifest Version 3 support in this issue.

Why

While there are docs for building browser extensions, it isn't obvious how to do it with scala-js, after dealing with an extension for a while, I got a reasonable architecture that can be reused on other extensions and simplify its development, the goal from this template is to save you valuable time.

The current template includes the examples for the following:

NOTE: If you have any reason to not use webpack, checkout b92c0f08690a8cd3e57e6dcf0c5d7694a5f20810 and follow the instructions from there.

Get started

NOTE: This template works only with scalajs 1.0.0, if you want to use a previous version, run git checkout 402abfac9a4b9eba7f395009aa9b2243f3498273 and follow the docs from that version.

It's pretty simple to get started, just follow these steps:

Development

Release

Run: PROD=true sbt chromePackage which generates:

Docs

The project has 3 components, and each of them acts as a different application, there are interfaces for interacting between them.

Active Tab

The activetab package has the script that is executed when the user visits a web page that the app is allowed to interact with (like github.com), everything running on the active tab has limited permissions, see the official docs for more details, be sure to read about the content scripts too.

Popup

The activetab package has the script that is executed when the user visits clicks on the app icon which is displayed on the browser navigation bar.

There is a limited functionality that the popup can do, see the official docs for more details.

Background

The background package has the script that is executed when the browser starts, it keeps running to do anything the extension is supposed to do on the background, for example, interacts with the storage, web services, and alarms.

As other components can't interact directly with the storage or web services, they use a high-level API (BackgroundAPI) to request the background to do that.

Be sure to review the official docs.

Hints

While scalajs works great, there are some limitations, in particular, you must pay lots of attention while dealing with boundaries.

A boundary is whatever interacts directly with JavaScript, like the browser APIs, for example: