Simple Tab Closing Addon using WebExtension API

May 5, 2017

Before reading this post setup your Firefox so you can run WebExtensions in your browser.

In this blog we will be exploring more about how to close a tab quickly when we click on browserAction button (a small set of icons which is kept aside of address bars).

Step 1 : Defined Title and Icon

First we need to define the browserAction icon and browserAction title in the manifest.json I have defined as below

	"browser_action": {
	    "default_icon": "icons/page-32.png",
   	    "default_title": "Close New Tab"

Step 2: Listen to browserAction

The second step we have to do is to listen to the browserAction click. To listen to this click by default we have a listener


Here the lisetener is a function where we will be passing the tab (tabs.Tab) object. As said we will pass the tab Object, when the user clicks on browserAction icon we will be sending the current active tab object to the callback function as argument.

Step 3: Defining the callback

So we have got the tab Object, so we know we can get its id by use

Then after getting the tab id we can simply close it by using remove API browser.tabs.remove


My whole call back function is below

    function mylove(tab) {

	var removing = browser.tabs.remove(;

	console.log((")created sucessfully("));

Checkout the code in github and share your thoughts.

Read Other Related Posts about : Mozilla

  • MozillaTN SNSCT WebExtension Workshop
  • Creating ShortenURL Maker Addon
  • Creating Simple Easy Searcher Using ContextMenu
  • Comments

    comments powered by Disqus