fregante / webext-permission-toggle

Browser-action context menu to request permission for the current tab.
https://fregante.github.io/webext-permission-toggle/
MIT License
70 stars 5 forks source link

Can't remove permissions broader than exactly `currentOrigin/*` (support more wildcards and `all_urls`) #37

Closed fregante closed 3 months ago

fregante commented 9 months ago

The remove action currently doesn't work if the permission isn't exactly currentprotocol://currenthost.tld/*

https://github.com/fregante/webext-domain-permission-toggle/blob/ba697453ee5de2b8889aa2c76a2798d90addca16/index.ts#L61-L70

await chrome.permissions.request({origins: ["*://*.example.com/*"]})
await chrome.permissions.remove({origins: ["https://example.com/*"]})

The remove call will not do anything.

This also applies to <all_urls> and *://*/* granted via request()

The solution is to:

  1. see what exact permissions is currently matching the domain
  2. remove that

For step 1, I might have to add a new helper to webext-permissions, like

findMatchingPermission(
    'https://example.com/some/page',
    await chrome.permissions.getAll()
)
// => "*://*.example.com/*" | undefined