Represents the
sync
storage area. Items in
sync
storage are synced by the browser, and are available across all instances of that browser that the user is logged into (e.g. via Firefox sync, or a Google account), across different devices.
For Firefox a user must have
附件
checked under the "Sync Settings" options in
"about:preferences"
.
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:
| 名称 | 描述 | 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 is allowed to store in the sync storage area. | 512 |
If an extension attempts to store items that exceed these limits, the call to
storage.sync.set()
will be rejected with an error. An extension can use
storage.sync.getBytesInUse()
to find out how much of its maximum total quota it is currently using.
sync
object implements the methods defined on the
storage.StorageArea
类型:
storage.StorageArea.get()
Retrieves one or more items from the storage area.
storage.StorageArea.getBytesInUse()
Gets the amount of storage space (in bytes) used one or more items being stored in the storage area.
storage.StorageArea.set()
Stores one or more items in the storage area. If the item already exists, its value will be updated.
storage.StorageArea.remove()
Removes one or more items from the storage area.
storage.StorageArea.clear()
Removes all items from the storage area.
BCD tables only load in the browser
注意:
This API is based on Chromium's
chrome.storage
API. This documentation is derived from
storage.json
in the Chromium code.
Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.
最后修改: , 由 MDN 贡献者