Creating Firefox browser extensions-24

Image for post
Image for post
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.

Image for post
Image for 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.

Image for post
Image for post
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.

Image for post
Image for post
background.js

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

Image for post
Image for post
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.

Image for post
Image for post
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.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store