-
-
Notifications
You must be signed in to change notification settings - Fork 118
Description
Description:
I am using extension.js to enable cross-browser compatibility, but I am encountering issues with the handling of background.scripts in the generated manifest.js file.
What I have tried:
-
Using Browser Prefixes:
I initially tried using thebrowserprefixes forservice_workerandscriptsto ensure compatibility across different browsers, as referenced in this issue comment.Input:
{ ... "background": { "firefox:scripts": ["./src/background/main.ts"], "chromium:service_worker": "./src/background/main.ts" }, ... }Output:
{ ... "background": {}, ... }The
backgroundobject is empty in the output, which is not the expected behavior. -
Without Browser Prefixes:
Next, I removed the browser-specific prefixes and specified bothscriptsandservice_workerkeys without any prefixes.Input:
{ ... "background": { "scripts": ["./src/background/main.ts"], "service_worker": "./src/background/main.ts" }, ... }Output:
{ ... "background": { "scripts": ["./src/background/main.ts"], "service_worker": "background/service_worker.js" }, ... }This transformation works for Chrome, but it does not function as expected in Firefox as the path in the
scriptsis incorrect (seems just copied exactly same as what is mentioned in the orignal manifest). -
Only
service_worker:
I then attempted to specify only theservice_workerkey, which obviously wouldn't work on Firefox due to the known issue I mentioned earlier.Input:
{ ... "background": { "service_worker": "./src/background/main.ts" }, ... }Output:
{ ... "background": { "service_worker": "background/service_worker.js" }, ... }However, note that the transformation of the service_worker path is correct. It would work on Chrome, but not on Firefox.
-
Only
scripts:
Finally, I tested specifying only thescriptskey, which would obviously break compatibility with Chrome, as Chrome only supportsscriptsin manifest v2.Input:
{ ... "background": { "scripts": ["./src/background/main.ts"] }, ... }Output:
{ ... "background": { "scripts": ["background/scripts.js"] }, ... }Note that, again, the scripts path was correctly transformed! While this transformation works for Firefox, but it does not ensure cross-browser compatibility.
Reference:
- Earlier issue that raised similar concern but not quite the same.
- Inconsistencies across browsers for scripts, page, and service_worker properties of
backgroundis detailed in the MDN documentation.