Removing Host Permission from Extension

341 views
Skip to first unread message

Malcolm Mason Rodriguez

unread,
May 13, 2023, 11:12:34 AM5/13/23
to Chromium Extensions
I have an extension with a content script that works on "<all_urls>". I want to make this permission optional but am a bit confused on how to do that. 

Do I simply add the following to my manifest?
"optional_host_permissions": ["https://*/*"],

And do I have to remove or add anything to content.matches?
{
"matches": [
"<all_urls>"
],
"js": [
"content/index.js"
],
"run_at": "document_start"
}

Jackie Han

unread,
May 13, 2023, 12:43:53 PM5/13/23
to Malcolm Mason Rodriguez, Chromium Extensions
For dynamic content script,

in manifest.json,
1. add "optional_host_permissions"
2. remove "content_scripts" entirely

in your code, let users enable/disable this optional function. when the user enables it


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/485ef197-f829-4bfc-b5ea-2747442ce894n%40chromium.org.

Malcolm Mason Rodriguez

unread,
May 13, 2023, 1:22:31 PM5/13/23
to Chromium Extensions, Jackie Han, Chromium Extensions, Malcolm Mason Rodriguez
Thanks for the response Jackie! What warning does the scripting permission display when the user attempts to add the extension?

Jackie Han

unread,
May 13, 2023, 1:35:00 PM5/13/23
to Malcolm Mason Rodriguez, Chromium Extensions
1. When users install your extension from the Web Store, no host permissions warning display.
2. When you request host permission by chrome.permissions.request(), users will see host permission and decide whether to grant it.
3. chrome.scripting.registerContentScripts() itself doesn't display any warning, but without host permission it doesn't work.

Jackie Han

unread,
May 13, 2023, 1:38:27 PM5/13/23
to Malcolm Mason Rodriguez, Chromium Extensions
4. "permissions": ["scripting"] doesn't display warning when install the extension

Malcolm Mason Rodriguez

unread,
May 13, 2023, 2:29:35 PM5/13/23
to Chromium Extensions, Jackie Han, Chromium Extensions, Malcolm Mason Rodriguez
Got it, thanks!
Reply all
Reply to author
Forward
0 new messages