extension-js / extension.js

🧩 Plug-and-play, zero-config, cross-browser extension development tool.
https://extension.js.org
MIT License
3.46k stars 80 forks source link

Support non-standard cross-browser manifest fields #122

Open cezaraugusto opened 6 days ago

cezaraugusto commented 6 days ago

There are cases when a feature is desired in a browser but not in the other browser, say using background.service_worker for Chrome and background.scripts for Firefox.

The easier route is having multiple manifest.json files specific for browsers (like manifest.edge.json). I'd like to avoid this for now.

The solution that comes to mind is having some sort of prefix to manifest fields, which would be handled by the CompatPlugin. Like:

{
  // Applies to Chrome only
  "chrome:side_panel": "...",
  "background": {
    // Applies to all Chromium-based browsers
    "chromium:service_worker": "sw.js",
    // Applies to Firefox
    "firefox:scripts": ["bg.js"]
  }
}

Chrome would understand the manifest.json as:

{
  // Applies to Chrome only
  "side_panel": "...",
  "background": {
    // Applies to all Chromium-based browsers
    "service_worker": "sw.js"
  }
}

Firefox:

{
  "background": {
    // Applies to Firefox
    "scripts": ["bg.js"]
  }
}
cezaraugusto commented 6 days ago

Lack of this feature prevent us from having templates using service workers from being compatible with Firefox in production mode.