Reputation: 234
I'm trying to require tab permission for current origin. Ex: I'm on http://stackoverflow.com, clicking on badge, then on button from popup, and I should get a prompt box to allow manipulating on this tab.
What I'm doing:
...
"permissions": ["tabs", "contextMenus"],
"optional_permissions": [ "<all_urls>"
],
...
popup
$('#reqPermision').click(function() { bg.reqPerm(url); });
background
function reqPerm(url) { chrome.permissions.request({permissions: ['tabs'], origins: [url]}, function (granted) { log('permision:', granted) }); }
What I'm getting:
Error during permissions.request: Optional permissions must be listed in extension manifest.
If I set url manually (in this ex. https://stackoverflow.com/) in "optional_permissions" array, all is working how I need.
Upvotes: 2
Views: 4407
Reputation: 31698
What you're trying to do should work. In the popup the code should be:
$('#reqPermision').click(function() {
chrome.permissions.request({origins: [url]}, function (granted) {
log('permision:', granted)
});
});
You don't need to call it from a background page.
However it's probably better to use a module like webext-domain-permission-toggle because it will handle the whole UI for you.
Upvotes: 0
Reputation: 140
firstly optional permission of is not allowed //error in your code secondly you need to specify the tab permission in the array of optional permission you did this
"permissions": ["tabs", "contextMenus"],
"optional_permissions": [ "<all_urls>" ],
you do it like this
"permissions": [, "contextMenus"],
"optional_permissions": [ 'tabs' ,<any other permission you want>],
third you should check before it request permission and it not granted then you you should request it refference google optional permission
Upvotes: -2
Reputation: 4236
This is currently not possible, you can only request permissions for URLs that have been explicitly listed in the manifest. However, this feature request should make what you are trying to do (automatically grant permission when clicking on a browser action) doable.
Upvotes: 0