Chrome extension storage onChanged() not detecting changes (not firing)

Viewed 1028

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

1 Answers

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.

Related