dmlls / yang

Yang! - Yet Another Bangs anywhere Firefox extension
https://addons.mozilla.org/addon/yang-addon/
GNU General Public License v3.0
13 stars 1 forks source link

Migrate to Manifest v3 #4

Open dmlls opened 1 year ago

dmlls commented 1 year ago

As discussed in https://github.com/dmlls/yang/pull/3, this PR implements the necessary changes to comply with Manifest V3, following the Firefox Manifest V3 migration guide.

dmlls commented 1 year ago

@NyanKiyoshi here is the PR, as promised :)

Do you think you could give it a try also on Chrome to see how things work there?

NyanKiyoshi commented 1 year ago

@dmlls that seems tricky to implement proper manifest v3 support.

The first issue is background.scripts becomes background.service_worker.

The second is permissions: webRequest and webRequestBlocking are no longer valid in manifest v3 (at least for chrome and chromium browsers). Thus instead of using browser.webRequest in background.js, we need to define JSON rules for the overrides.

The manifest changes required:

Patch File ```patch diff --git a/manifest.json b/manifest.json index facdcb3..83d7c0d 100644 --- a/manifest.json +++ b/manifest.json @@ -20,8 +20,7 @@ }, "permissions": [ - "webRequest", - "webRequestBlocking", + "declarativeNetRequest", "activeTab" ], @@ -363,8 +362,6 @@ ], "background": { - "scripts": [ - "background.js" - ] + "service_worker": "background.js" } } ```

On the compatibility matrix I do not see any support for rules in Firefox thus it may not work: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/declarativeNetRequest#browser_compatibility.

I do not personally see a way to re-implement background.js without whether having a huge amount of dynamic rules, or redirecting to the extension's URL (e.g. extension://yang-extension-id/handle-yang.html?search=foo) which sounds like bad UX due to having to redirect twice the user (doesn't work based on: https://bugs.chromium.org/p/chromium/issues/detail?id=1262147).

dmlls commented 1 year ago

Hi @NyanKiyoshi, thanks a lot for the detailed feedback! 💯

I see things are not looking all that great... I'll take a close look during the next week and see what we can do, but yeah, hope there's a solution that doesn't involve any ugly workarounds, as you mentioned.

dmlls commented 1 year ago

@NyanKiyoshi So actually the webRequestBlocking permission is not needed, so it can be simply removed.

As for the background.scripts vs background.service_worker conflict, it seems indeed there is currently no way of making them work simultaneously on both Firefox and Chrome. A possible solution would be to keep two separate manifest.json as mentioned here. Since the change is minimal, at least for now this wouldn't add much overhead.