extension-js / extension.js

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

manifest 'background' processing bug? #132

Open bugficks opened 1 month ago

bugficks commented 1 month ago

given:

  "background": {
    "service_worker": "./background.ts",
    "background": {
      "scripts": [
        "background.ts"
      ]
    }
  },

results in (notice the unprocessed background.ts):

  "background": {
    "service_worker": "background/service_worker.js",
    "background": {
      "scripts": [
        "background.ts"
      ]
    }
  },

recent browser versions are able to deal with this. I guess another question is to use the same .ts or allow a different one, in case of possible differences.

Browser support

Support for the scripts, page, and service_worker properties varies between browsers like this:

cezaraugusto commented 1 month ago

we support non-standard cross-browser manifest fields (not released), made by a great contribution here: https://github.com/extension-js/extension.js/pull/128. It allows you to add a browser prefix to manifest fields, like:

{
  background: {
    firefox:scripts: [...], // applied only to Firefox
    service_worker: 'sw.js' // applied only to Chrome
}

this way you can work on multiple browsers at once and ensure compatibility

bugficks commented 1 month ago

not sure what I am doing wrong but if I add to source manifest:

    "background": {
        "chromium:service_worker": "background.ts",
        "firefox:scripts": [
            "background.ts"
        ]
    },

after running build this ends up in dist/chrome/manifest.json

  "background": {
    "chromium:service_worker": "background.ts",
    "firefox:scripts": [
      "background.ts"
    ]
  },

which is even worse :)

my workaround is:

  "background": {
    "service_worker": "background.ts",
    "background": {
      "scripts": [
        "background/service_worker.js"
      ]
    }
  },

which produces the manifest I want :)

cezaraugusto commented 1 month ago

@bugficks yeah it's not released yet, there are a few issues with current implementation. Will land in the next release once #137 is out