Fix options watchers in Firefox
chrome.storage.sync.onChanged doesn't exist in Firefox, but the generic
chrome.storage.onChanged does exist both in Chrome and Firefox. This
prevented some features from working in the Community Console in
Firefox.
This CL fixes the issue by using the second variant of the onChanged
listener.
Fixed: twpowertools:112
Change-Id: I971e663b5c9cc4de29f6a3637e6e3749246c3ab9
diff --git a/src/bg.js b/src/bg.js
index a0864d8..4244e93 100644
--- a/src/bg.js
+++ b/src/bg.js
@@ -75,7 +75,8 @@
// Clean up optional permissions and check that none are missing for enabled
// features, and also handle background option changes as soon as the extension
// starts and when the options change.
-chrome.storage.sync.onChanged.addListener(changes => {
+chrome.storage.onChanged.addListener((changes, areaName) => {
+ if (areaName !== 'sync') return;
cleanUpOptPermissions();
for (let [key, {oldValue, newValue}] of Object.entries(changes)) {
diff --git a/src/common/optionsWatcher.js b/src/common/optionsWatcher.js
index 97a7ee8..de14a85 100644
--- a/src/common/optionsWatcher.js
+++ b/src/common/optionsWatcher.js
@@ -14,7 +14,8 @@
// We could try only doing this only when we're sure it has changed, but
// there are many factors (if the user has changed it manually, if a kill
// switch was activated, etc.) so we'll do it every time.
- chrome.storage.sync.onChanged.addListener(() => {
+ chrome.storage.onChanged.addListener((changes, areaName) => {
+ if (areaName !== 'sync') return;
console.debug('[optionsWatcher] Marking options as stale.');
this.isStale = true;
});