While some content on writing web applications in Kotlin has been published, the niche of writing browser extensions has seemed to be ignored until now. That’s why in this post we are going explore the process of writing a simple extension for Firefox using Kotlin JS.
You must see this : Top 20 Daily used Kotlin Code Snippet
How to Create Firefox Extension Using KotlinJS?
The extension is based on Your first extension by Mozilla and will simply add a red border to the kotlinlang.org website.
For testing our Firefox extension, we will use the web-ext tool from Mozilla. To obtain it you need to install node.js and then run the following command in a terminal:
- npm install --global web-ext
Apart from that, we will be using IntelliJ IDEA 2017.2.6 with the Kotlin plugin version 1.1.60 to develop the extension.
You must aware of it : Kotlin Problems and How to avoid them?
Setting up the project with KotlinJS
We proceed through the wizard until the empty project is created and opened.
As the next step, we will enable the Dead Code Elimination plugin for KotlinJS. This is necessary because a Kotlin JS program needs to bundle the Kotlin stdlib which is over a megabyte in size. However, we can reduce the size of our compiled code drastically by removing code that’s never getting called.
You must see : Bye bye Gradle and Maven !! Say hello Kotlin Kobalt
To enable the plugin, simply add the following line to the
- apply plugin: 'kotlin-dce-js'
Creating the extension manifest
In the next step, we add the manifest file which is required for a Firefox extension. This fileis called manifest.json and resided in the root directory of our project. The file should have the following content.
"name": "Kotlin Borderify",
"description": "Adds a red border to kotlinlang.org",
In this file we declare that our extension will inject a content script in any website matching the patternFull article and Source : http://www.tellmehow.co/create-firefox-extension-using-kotlinjs/
*://kotlinlang.org/*. The necessary script files are are the Kotlin stdlib
kotlin.jsas well as our code in the