3

I've seen this question asked on here before, but there was never really a proper answer. So I have a listener registered on background.js to listen on chrome.storage.onChanged. However, as far as I can tell it's not firing the event despite changes to storage. The change happens from the popup.js file when the user clicks a button.

I have set up a polling button to get the latest data from storage and updates are showing there, but the console.log calls from the methods listening never get called.

The same item in the storage is being updated, i.e. there are no new items being added or removed. However, I have tested adding different items and it still doesn't fire.

Inside background.js

chrome.storage.onChanged.addListener(function() {
    console.log("hehe");
});

Inside popup.js

chrome.storage.sync.set({"databases": dbList}, function () {
            console.log("Successfully added: " + domain);
            document.getElementById("add-remove").innerText = remove;
            setForRemove(dbList, domain)
        });

Thanks in advance

Tazz
  • 181
  • 7
  • Possible duplicate of [Where to read console messages from background.js in a Chrome extension?](https://stackoverflow.com/questions/10257301/where-to-read-console-messages-from-background-js-in-a-chrome-extension) – wOxxOm Jun 10 '19 at 10:00
  • Nah I have console up and running, this is how I'm verifying that items are actually be saved to storage – Tazz Jun 10 '19 at 21:11
  • 1
    There are different consoles for each component of the extension. You need to open a separate one as shown in the linked topic. – wOxxOm Jun 11 '19 at 02:15

1 Answers1

0

Which manifest are you using? I've tried real hard to make storage listener to work:

chrome.storage.onChanged.addListener(() => {
    console.log("tick");
});

with Manifest v3, but it did not work, even before the service worker got inactive.

After switching to Manifest v2, everything worked smoothly. I am not discouraging using Manifest v3, you should try to make it work as it is recommended way now, but if it is does not work no matter what just like in my case, I don't see any other way than to use older Manifest.

Shota
  • 6,910
  • 9
  • 37
  • 67