From 55ac05eba147edb3cc81e9f302055c15cf7fd7a4 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 10 Mar 2021 20:29:15 -0500 Subject: Fix permissions changes not being supported on some browsers (#1513) --- ext/js/background/backend.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'ext/js/background') diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 9b35e9b1..5ab1b5bd 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -180,9 +180,11 @@ class Backend { const onMessage = this._onMessageWrapper.bind(this); chrome.runtime.onMessage.addListener(onMessage); - const onPermissionsChanged = this._onWebExtensionEventWrapper(this._onPermissionsChanged.bind(this)); - chrome.permissions.onAdded.addListener(onPermissionsChanged); - chrome.permissions.onRemoved.addListener(onPermissionsChanged); + if (this._canObservePermissionsChanges()) { + const onPermissionsChanged = this._onWebExtensionEventWrapper(this._onPermissionsChanged.bind(this)); + chrome.permissions.onAdded.addListener(onPermissionsChanged); + chrome.permissions.onRemoved.addListener(onPermissionsChanged); + } } async _prepareInternal() { @@ -2088,7 +2090,12 @@ class Backend { this._updateBadge(); } + _canObservePermissionsChanges() { + return isObject(chrome.permissions) && isObject(chrome.permissions.onAdded) && isObject(chrome.permissions.onRemoved); + } + _hasRequiredPermissionsForSettings(options) { + if (!this._canObservePermissionsChanges()) { return true; } return this._permissions === null || this._permissionsUtil.hasRequiredPermissionsForOptions(this._permissions, options); } } -- cgit v1.2.3