What is Web Extension?
Web extensions are powerful tool to develop browser add-ons. There are several tools to develop a browser add-on, but web extension is one of the best tool to develop, because this is designed to be cross browser compatible. Web extensions are written for Firefox but can run on chrome, edge and opera.
First web extension
Here you can start developing the first web extension; the following files are needed –
- Route directory with the required name of your extension.
- Manifest.json file.
- Icon directory.
- JS file of your extension.
- Popup directory – which should contain required Html / CSS / JS for the popup.
Manifest.json is a json formatted file, which contains the necessary information of the web extension and configuration settings of the extension. It is the only file any web extension should contain. It mainly contains the metadata such as name and version and can also specify the extension aspects.
Here are the major keys –
- Manifest_version – version of your manifest file. – ex – 1 – mandatory
- Name – name of your add-on. – ex – “Debug It” – mandatory
- Version – version of your add-on. – ex – “1.0” – mandatory
- description – short description of your add-on – optional
- icons – Object with specified version of icons – need 48×48 and 96×96 version icons – should be png images – optional
- Content_scripts – This is the most interesting key which tells the add-on to load the specified scripts into web pages which matches the specified pattern of the url.
- Browser_action – If need to show the toolbar icon. It contains three keys
- Default_icon – specify the icon to be appears on toolbar.
- Default_title – to show tooltip when mouse over the toolbar button.
- default_popup – the html file to show as popup when toolbar button is clicked.
Create extension directories
- Create route directory under any of the drive. You can create it via command prompt.
- Open command prompt and enter –
- Create a new file called “manifest.json” directly under the route directory. And configure it as per above keys.
- Create the “icons” directory directly under the route directory. Save an icon there. The icon is very necessary as it appears next to the add-on’s listing add-on manager.
- Create the required js file directly under DebugIt directory.
- Create directory “popup” under route directory.
- Add the required HTML, CSS, JS files under popup directory.
Test your Extension
- On the address bar type – about:debugging. This will open the add-on manager window.
- Click on Load Temporary add on button.
- Choose the js file or manifest file to load the extension.
- Now it is ready to test/use.