ChromePromise instance doesn't update when optional permissions are requested
See original GitHub issueThe ChromePromise
constructor wraps whatever Chrome extension APIs are available when the library is first loaded. But it’s also possible to request optional permissions after the extension first loads. If the user gives that permission, though, any existing ChromePromise
instances aren’t updated to provide the newly available API.
One way to solve this might be wrap the chrome.permissions.request()
method and intercept the request and the response. If the response is true
, then the instance could look at the requested permissions and update itself with those APIs.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
chrome.permissions - Chrome Developers
# Step 1: Decide which permissions are required and which are optional. An extension can declare both required and optional permissions. In general,...
Read more >Permissions requested by apps and extensions
Optional permissions will ask you to deny or allow permissions after the app or extension has been installed. When you allow optional permissions,...
Read more >chrome-promise/chrome-promise.d.ts at master - GitHub
Promises for chrome JavaScript APIs used in extensions and apps. ... When the file is selected, file access permission required to use the...
Read more >reprompt for permissions with getUserMedia() after initial denial
I'm working with getUserMedia to access the user's camera and pipe the data to a canvas. That bit all works fine. In testing,...
Read more >Permissions - W3C
This example uses the Permissions API to decide whether local news ... are creating specifications whose permission model doesn't fit in the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for all the research. I didn’t add the alias for
webRequestBlocking
because thewebRequest
permission is also needed. So I added a condition to check if the api exists or not. You are right aboutclipboardRead
andclipboardWrite
, so I didn’t do anything with those. Finally, forenterprise.deviceAttributes
, it will add theenterprise
api.When permissions are removed, the api still exists in
chrome
, but calling a method throws an error. When usingchromep
, the promise is rejected. So I think the current behaviour is correct.Nice!
One thing to note is that there’s at least one optional permission where this won’t work correctly. The
webRequestBlocking
permission gives access to thewebRequest
API, not awebRequestBlocking
API. So requesting just the blocking permission would fail.Also, the
clipboardRead
andclipboardWrite
permissions don’t seem to map to an API (it’s not clear they’re even necessary, given the description).I haven’t done a thorough comparison of the list of optional permissions and the objects they give access to on these two pages, but did note the above discrepancies:
https://developer.chrome.com/extensions/permissions https://developer.chrome.com/extensions/declare_permissions
This wouldn’t work for the clipboard permissions or for ones like
enterprise.deviceAttributes
(not sure if those can be optional), but one quick way of handling permissions likewebRequestBlocking
would be using an object to map the permission string to a different object name:I decided not to use optional permissions in the extension I’m working on, so I haven’t gotten back to testing this out, but just wanted to call out these edge cases.
Also, it might be nice to support removing permissions as well.