question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ChromePromise instance doesn't update when optional permissions are requested

See original GitHub issue

The 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:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tfoxycommented, Apr 3, 2018

Thanks for all the research. I didn’t add the alias for webRequestBlocking because the webRequest permission is also needed. So I added a condition to check if the api exists or not. You are right about clipboardRead and clipboardWrite, so I didn’t do anything with those. Finally, for enterprise.deviceAttributes, it will add the enterprise api.

When permissions are removed, the api still exists in chrome, but calling a method throws an error. When using chromep, the promise is rejected. So I think the current behaviour is correct.

1reaction
fwextensionscommented, Mar 19, 2018

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 the webRequest API, not a webRequestBlocking API. So requesting just the blocking permission would fail.

Also, the clipboardRead and clipboardWrite 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 like webRequestBlocking would be using an object to map the permission string to a different object name:

const permAliases = { webRequestBlocking: "webRequest" };
...
  perms.permissions.forEach(function(permission) {
    permission = permAliases[permission] || permission;
    approvedPerms[permission] = chrome[permission];
  });

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found