This works on Chrome, Firefox, Edge, and Opera. But I can't get it to work on Safari. When I call browser.storage.local.set, the onChanged listener is not called.
Below is the code I'm using to test this in Safari. This has to be in an extension with the Storage permission.
Given this works in all other browsers and I'm following the documentation, I'm inclined to believe this is a bug in Safari. Am I missing something?
Code Block /* Function to handle changes to storage */ function handleChange(changes) { for (var key in changes) { var storageChange = changes[key]; console.log('onChanged triggered. '+ 'Storage key "%s" changed. ' + 'Old value was "%s", new value is "%s".', key, storageChange.oldValue, storageChange.newValue); } } /* Add listener for storage changing */ browser.storage.onChanged.addListener(handleChange) /* Confirm that the listener has been attached (expect "true" to be returned)*/ browser.storage.onChanged.hasListener(handleChange) /* Set value for ['testKey] (should trigger onChanged event which calls handleChange) */ browser.storage.local.set({testKey: true}, () => { console.log('Storage updated'); }); /* Get current value for ['testKey] in storage.local, should return {testKey: true}*/ browser.storage.local.get(['testKey'], (result) => { console.log(result); }); /* Change value for ['testKey] (should trigger onChanged event which calls handleChange) */ browser.storage.local.set({testKey: false}, () => { console.log('Storage updated'); });