fregante / webext-permission-toggle

Browser-action context menu to request permission for the current tab.
https://fregante.github.io/webext-permission-toggle/
MIT License
70 stars 5 forks source link

Manifest v3 compatibility #19

Closed fregante closed 9 months ago

fregante commented 3 years ago

Manifest v3 likely brought some changes that broke this script. I never tested it, but it should be. At a minimum, injectScript with code doesn't work. Fixed in https://github.com/fregante/webext-content-scripts/pull/5

fregante commented 3 years ago

From https://docs.google.com/document/d/1nPu6Wy4LWR66EFLeYInl3NzzhHzc-qnk4w4PX-0XMw8/edit#

In Manifest V3, we want activeTab-style host permissions to be the default, with a number of extra options. Instead of being granted access to all URLs on installation, extensions will be unable to request <all_urls>, and instead the user can choose to invoke the extension on certain websites, like they would with activeTab. Additional settings will be available to the user post-installation, to allow them to tweak behavior if they so desire.

This hints at webext-domain-permission-toggle and webext-dynamic-content-scripts being natively implemented by Google Chrome 🎉

With MV3, I think you can declare your content scripts with <all_urls> and the user will be able to enable the script on each site with this UI:

Screen Shot 2

This means that for an extension like Refined GitHub you'll now only need:

  {
-   "permissions": [
-       "contextMenus",
-       "activeTab"
-   ],
-   "optional_permissions": [
-       "*://*/*"
-   ],
-   "browser_action": {
-       "default_icon": "icon.png"
-   },
-   "background": {
-       "scripts": [
-           "webext-domain-permission-toggle.js",
-           "webext-dynamic-content-scripts.js",
-           "background.js"
-       ]
-   },
    "content_scripts": [
        {
            "matches": [
+               "*://*/*",
                "https://github.com/*",
                "https://gist.github.com/*"
            ],
            "js": [
                "refined-github.js"
            ]
        }
    ]
  }

😍

fregante commented 3 years ago

However it might be a long time before Firefox and Safari support it

fregante commented 2 years ago

A check needs to be updated here:

https://github.com/fregante/webext-domain-permission-toggle/blob/e125b40129e53342bc6ac07a1afc29696da347a4/index.ts#L157-L160

because *://*/* won't appear in optional_permissions but in optional_host_permissions:

https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#host-permissions

EnixCoda commented 1 year ago

This change might be required as well. Otherwise the item would not show up in the menu.

https://github.com/fregante/webext-domain-permission-toggle/blob/e125b40129e53342bc6ac07a1afc29696da347a4/index.ts#L168

Add 'action'

contexts: ['action', 'page_action', 'browser_action'],

And 'page_action', 'browser_action' might not be required anymore, but I did not test that.

EnixCoda commented 1 year ago

And another line needs update as well, replace optional_permissions with optional_host_permissions

https://github.com/fregante/webext-domain-permission-toggle/blob/e125b40129e53342bc6ac07a1afc29696da347a4/index.ts#L142

aspiers commented 9 months ago

@fregante I have taken a stab at this and it seems to work:

https://github.com/fregante/webext-domain-permission-toggle/compare/main...aspiers:webext-domain-permission-toggle:mv3

although I noticed that executeScript() in webext-content-scripts seems to require the scripting permission, since v3 replaces tabs.executeScript() with scripting.executeScript().

fregante commented 9 months ago

Thanks for checking! It's possible that this only needs:

aspiers commented 9 months ago

Thanks, I'll check the README for accuracy. Sorry for the dumb question but by dependencies update do you mean just an npm update or similar?

fregante commented 9 months ago

My go-to is npx trash node_modules package-lock.json && npx npm-check-updates -u && npm i && npm test

aspiers commented 9 months ago

Thanks, working on that. npm test found some type errors. Turns out there is an attribute missing in the latest @types/chrome: https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/68051

aspiers commented 9 months ago

Alright, seems to be sorted now. I've force-pushed to my mv3 branch (the same one linked above):

https://github.com/fregante/webext-domain-permission-toggle/compare/main...aspiers:webext-domain-permission-toggle:mv3

Submitting a PR next.

aspiers commented 9 months ago

Any thoughts on this PR #28 yet?