Home  Programming   Firefox ext ...

firefox extension manifest file

Here is a basic manifest.json file for a WebExtension in Firefox, which is used to define various properties and configurations for the extension.

{
  "manifest_version": 3,
  "name": "webextensions-selenium-example",
  "description": "Inject a div with id webextensions-selenium-example to verify that WebExtensions work in Firefox/Selenium",
  "version": "0.1",
  "content_scripts": [
    {
      "matches": [
        "https://*/*",
        "http://*/*"
      ],
      "js": [
        "inject.js"
      ]
    }
  ],
  "browser_specific_settings": {
    "gecko": {
      "id": "[email protected]"
    }
  }
}

Let's break down each section and its components:

manifest.json Structure

1. Manifest Version

"manifest_version": 3

2. Basic Information

"name": "webextensions-selenium-example",
"description": "Inject a div with id webextensions-selenium-example to verify that WebExtensions work in Firefox/Selenium",
"version": "0.1"

3. Content Scripts

"content_scripts": [
  {
    "matches": [
      "https://*/*",
      "http://*/*"
    ],
    "js": [
      "inject.js"
    ]
  }
]

4. Browser-Specific Settings

"browser_specific_settings": {
  "gecko": {
    "id": "[email protected]"
  }
}

Example of inject.js

For completeness, here’s an example of what inject.js might look like. This script injects a div with the specified ID into the web page.

// inject.js
(function() {
  const div = document.createElement('div');
  div.id = 'webextensions-selenium-example';
  div.style.position = 'fixed';
  div.style.top = '0';
  div.style.right = '0';
  div.style.width = '200px';
  div.style.height = '100px';
  div.style.backgroundColor = 'yellow';
  div.style.zIndex = '1000';
  div.innerText = 'WebExtension is active!';
  document.body.appendChild(div);
})();
Published on: Jun 27, 2024, 03:56 AM  
 

Comments

Add your comment