sync storage area. Items in
sync storage are synced by the browser. The data is then available on all instances of the browser the user is logged into (for example, when using Firefox account on desktop versions of Firefox or a Google account on Chrome) across different devices.
For Firefox, a user must have
Add-ons checked under the "Sync Settings" options in
Note that the implementation of
storage.sync in Firefox relies on the Add-on ID. If you use
storage.sync, you must set an ID for your extension using the
browser_specific_settings manifest.json key.
The main use case of this API is to store preferences about your extension and allow the user to sync them to different profiles.
The browser enforces limits on the amount of data each extension is allowed to store in the sync area:
|Name||Description||Value in bytes|
|Maximum total size||The maximum total amount of data that each extension is allowed to store in the sync storage area, as measured by the JSON stringification of every value plus every key's length.||102400|
|Maximum item size||The maximum size of any one item that each extension is allowed to store in the sync storage area, as measured by the JSON stringification of the item's value plus the length of its key.||8192|
|Maximum number of items||The maximum number of items that each extension can store in the sync storage area.||
If an extension attempts to store items that exceed these limits, calls to
storage.sync.set() are rejected with an error. An extension can use
storage.sync.getBytesInUse() to find out how much of its quota is in use.
In Firefox, extension data is synced every 10 minutes or whenever the user selects Sync Now in Settings > Sync or Firefox account. When the browser performs a sync, for each key stored, it:
- compares the value on the server with the value at the last sync; if they are different, the value from the server is written to the key in the browser's sync storage.
- compares the browser's sync storage values with the value on the server; if they are different, writes the browser's key value to the server.
This means that, for each key, a change on the server takes precedence over a change in the browser's sync storage.
This mechanism is generally OK for data such as user preferences or other global settings changed by the user.
However, a key's value can be updated on one browser and synchronized then updated on a second browser before the second browser is synchronized, resulting in the local update being overwritten during sync. This mechanism is, therefore, not ideal for data aggregated across devices, such as a count of page views or how many times an option is used. To handle such cases, use
storage.sync.onChanged to listen for sync updates from the server (for example, a count of page views on another browser instance). Then adjust the value locally to take the remote value into account (for example, update the total views based on the remote count and new local count).
sync object implements the methods defined on the
Retrieves one or more items from the storage area.
Gets the amount of storage space (in bytes) used for one or more items in the storage area.
Stores one or more items in the storage area. If the item exists, its value is updated.
Removes one or more items from the storage area.
Removes all items from the storage area.
BCD tables only load in the browser