Creating Firefox browser extensions-24

Nabendu Biswas
3 min readApr 26, 2020

--

Photo by Ihsan Aditya from Pexels

Welcome to part-24 of the series. You can find part-23 here.

In this part we will create a new addon called Read Mode. This addon allows the user to change, the currently opened tab to reader mode if available.

So, go ahead and create a folder ReadMode and inside it another folder icons. Inside that folder place three icons. You can get them from the github link at the end of this post.

ReadMode

Now, create a file manifest.json inside the folder ReadMode and put the below content in it.

It is using the permissions for notifications and tabs which we are going to use soon.

manifest.json

We only have another file ie background.js in this addon. So, go ahead and create it in the same folder and put the below content in it.

Now, our program starts from Line 10 where we have an event listener for browserAction.onClicked(). This event will fire when the browser icon is clicked.

Inside the listener, we are passing the tab to tabs.toggleReaderMode(), which toggles reader mode for the current tab.

Now, some of the web-pages don’t have reader mode and the promise will fire the catch block. For such tabs, we are calling a function failureCallback(). The function shows an browser notification that the reader mode is not available.

background.js

So, our code is complete. I had checked it by testing the temporary addon and it works perfectly.

Gif

So, it’s time to publish it in the mozilla addon store. I will follow the procedure from another of my blog in the series. The link is here.

Since, the name Read Mode was not available, i had to change the name of the addon to My Read Mode.

My Read Mode

This complete part-24 of the series. You can find the part-25 here.

You can find the code for the same in my github account here.

--

--

Nabendu Biswas
Nabendu Biswas

Written by Nabendu Biswas

Architect, ReactJS & Ecosystem Expert, Youtuber, Blogger

No responses yet