Closed fregante closed 9 months 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 withactiveTab
. 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:
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"
]
}
]
}
😍
However it might be a long time before Firefox and Safari support it
A check needs to be updated here:
because *://*/*
won't appear in optional_permissions
but in optional_host_permissions
:
https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#host-permissions
This change might be required as well. Otherwise the item would not show up in the menu.
Add 'action'
contexts: ['action', 'page_action', 'browser_action'],
And 'page_action', 'browser_action'
might not be required anymore, but I did not test that.
And another line needs update as well, replace optional_permissions
with optional_host_permissions
@fregante I have taken a stab at this and it seems to work:
although I noticed that executeScript()
in webext-content-scripts
seems to require the scripting
permission, since v3 replaces tabs.executeScript()
with scripting.executeScript()
.
Thanks for checking! It's possible that this only needs:
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?
My go-to is npx trash node_modules package-lock.json && npx npm-check-updates -u && npm i && npm test
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
Alright, seems to be sorted now. I've force-pushed to my mv3
branch (the same one linked above):
Submitting a PR next.
Any thoughts on this PR #28 yet?
Manifest v3 likely brought some changes that broke this script. I never tested it, but it should be.
At a minimum,Fixed in https://github.com/fregante/webext-content-scripts/pull/5injectScript
withcode
doesn't work.