flienteen
flienteen

Reputation: 234

Chrome Extension - Request Optional Permissions for current tab

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:

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

Answers (3)

fregante
fregante

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

Bilal Naqvi
Bilal Naqvi

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

Mihai Parparita
Mihai Parparita

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

Related Questions