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?
- 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 pattern
*://kotlinlang.org/* . The necessary script files are are the Kotlin stdlib
kotlin.js as well as our code in the
Full article and Source : http://www.tellmehow.co/create-firefox-extension-using-kotlinjs/