Starting from Firefox 77 (June 2nd, 2020) this polyfill is no longer necessary. 🎉
You can keep this polyfill if you want to support older versions as well; It's automatically disabled where supported.
Keep in mind the known issue, however.
WebExtensions: Polyfill for permissions.onAdded and permissions.onRemoved events for Firefox.
Optional permissions can be added and removed by both Chrome and Firefox, but Firefox doesn't yet support Permission Events: https://bugzilla.mozilla.org/show_bug.cgi?id=1444294
This polyfill will add those two events to Firefox.
You can just download the standalone bundle (it might take a minute to download) and include the file in your manifest.json
, or:
npm install webext-permissions-events-polyfill
import 'webext-permissions-events-polyfill';
Include the polyfill as a background script and then refer to the original Permissions Events documentation.
This polyfill will exclusively work if permissions are requested/removed from the same page where the listener is. That means, if you run chrome.permissions.request
in the background page, only the same exact page will receive the event.
If you want to request from options.html
or popup.html
, add your request here or send a PR to add support via runtime.sendMessage
chrome.permissions.onAdded.addListener(permissions => {
console.log('New permissions');
console.log(permissions.origins);
console.log(permissions.permissions);
});
chrome.permissions.onRemoved.addListener(permissions => {
console.log('Permissions that have been removed');
console.log(permissions.origins);
console.log(permissions.permissions);
});
- webext-domain-permission-toggle - Browser-action context menu to request permission for the current tab.
- webext-dynamic-content-scripts - Automatically registers your content_scripts on domains added via permission.request
- webext-additional-permissions - Get any optional permissions that users have granted you.
- webext-options-sync - Helps you manage and autosave your extension's options. Chrome and Firefox.
- webext-storage-cache - Map-like promised cache storage with expiration. Chrome and Firefox
- webext-detect-page - Detects where the current browser extension code is being run. Chrome and Firefox.
- webext-content-script-ping - One-file interface to detect whether your content script have loaded.
- web-ext-submit - Wrapper around Mozilla’s web-ext to submit extensions to AMO.
- Awesome-WebExtensions - A curated list of awesome resources for WebExtensions development.