The following code works in Chrome, but not in Firefox:
document.querySelector('#some-element').addEventListener('click', () => {
const url = 'https://example.com';
chrome.permissions.contains(
{ origins: [url] },
(result) => {
if (!result) {
chrome.permissions.request(
{ origins: [url] },
(granted) => {
if (granted) {
console.log('granted permission');
);
}
},
);
}
});
});
Firefox errors with
Unchecked lastError value: Error: May only request permissions from a user input handler
But Chrome adds it just fine. Is this a bug? Is there some info on how to avoid checking for redundant permissions if it is not a bug?
Edit: I should add, the code above is run in the options/settings UI of the addon.