Fires when one or more items in a storage area change. Compared to storage.onChanged, this event enables you to listen for changes in one of the storage areas: local, managed, session, and sync.
Fires when one or more items in a storage area change. Compared to storage.onChanged, this event enables you to listen for changes in one of the storage areas: local, managed, session, and sync.
// local can also be sync, managed, or session browser.storage.local.onChanged.addListener(callback) browser.storage.local.onChanged.removeListener(listener) browser.storage.local.onChanged.hasListener(listener)
Events have three functions:
addListener(callback)Adds a listener to this event.
removeListener(listener)Stops listening to this event. The listener argument is the listener to remove.
hasListener(listener)Checks whether listener is registered for this event. Returns true if it is listening, false otherwise.
callbackThe function called when this event occurs. The function is passed these arguments:
changesobject. Object describing the change. This contains one property for each key that changed. The name of the property is the name of the key that changed, and its value is a storage.StorageChange object describing the change to that item.
/* Log the old value and its new value of changes in the local storage. */ function logStorageChange(changes) { const changedItems = Object.keys(changes); for (const item of changedItems) { console.log(`${item} has changed:`); console.log("Old value: ", changes[item].oldValue); console.log("New value: ", changes[item].newValue); } } browser.storage.local.onChanged.addListener(logStorageChange);
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
onChanged |
73 | Yes | 101 | ? | Yes | 14 | ? | ? | 101 | ? | 15 | ? |
Note: This API is based on Chromium's chrome.storage API. This documentation is derived from storage.json in the Chromium code.
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/StorageArea/onChanged