chromium iconfirefox icon

Browser-Specific Manifest Fields

In some cases during the development of a cross-browser extension, certain manifest fields or API configurations are only relevant to specific browsers. With Extension.js, you can prefix the manifest field with the browser name to ensure that the field is only compiled for that browser.

How Does It Work?

For Chromium-based browsers (Chrome, Edge, ...)

{
  "chromium:background": {
    "service_worker": "sw.js"
  }
}

For Firefox

{
  "firefox:background": {
    "scripts": ["sw.js"]
  }
}

This approach ensures that the service_worker field is only applied when targeting Chromium-based browsers, while the scripts field works exclusively for Firefox. Below is a list of supported prefixes and their corresponding target browsers:

Browser Prefix Target browser
Chromium chromium: All Chromium-based browsers
Chrome chrome: Chrome browser
Edge edge: Edge browser
Firefox firefox: Firefox browser
Gecko gecko: All Gecko-based browsers
Safari Coming soon Safari browser
WebKit Coming soon All WebKit-based browsers
Desktop Coming soon All desktop browsers
Mobile Coming soon All mobile browsers

This feature works for any manifest field at any level, including permissions, content_scripts, background, and more.

Best Practices

  • Use browser-specific fields: When developing a cross-browser extension, use browser-specific fields to ensure that the manifest is correctly compiled for each target browser.
  • Check the compatibility: Before using browser-specific fields, check the compatibility of the field with the target browser to avoid any issues during the build process. A good place is the MDN Web Docs for the WebExtensions API.

Next Steps