安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
存储标准定义公共、共享存储系统,用于为单个 Web 站点存储可访问内容数据的所有 API 和技术。存储 API 使站点代码能够知道它们可以使用多少空间,它们已使用多少空间,甚至控制它们是否需要警报先于 用户代理 处置站点数据以便为其它事情腾出空间。
注意: 此特征可用于 Web 工作者 .站点存储 — 由存储标准管理的网站存储数据 — 包括:
window.localStorage
History.pushState()
The site storage system described by the Storage Standard and interacted with using the Storage API consists of a single site storage unit for each origin . In essence, every Web site or Web application has its own storage unit into which its data gets placed. The diagram below shows a site storage pool with three storage units within, showing how storage units can have different data types stored within and may have different quotas (maximum storage limits).
User agents are likely to use various techniques to determine the quota for various origins. One of the most likely methods—one which the specification specifically encourages, in fact—would be to consider the popularity and/or usage levels of individual sites to determine what their quotas should be. It's also conceivable that the browser might offer a user interface to customize these quotas.
The actual data storage within each site storage unit is called its box . Each site storage unit has exactly one box into which all of its data is placed, and has a box mode that describes the data retention policy for that box. There are two modes:
"best-effort"
"persistent"
"best-effort"
boxes before considering clearing a box marked
"persistent"
. If it becomes necessary to consider clearing persistent boxes, the user agent will notify the user and provide a way to clear one or more persistent boxes as needed.
To change an origin's box mode requires permission to use the
"persistent-storage"
特征。
If the site or app has the
"persistent-storage"
feature permission, it can use the
StorageManager.persist()
method to request that its box be made persistent. It's also possible for the user agent to decide to make the site's storage unit persistent due to usage characteristics or other metrics. The
"persistent-storage"
feature's permission-related flags, algorithms, and types are all set to the standard defaults for a permission, except that the
permission state
must be the same across the entire origin, and that if the permission state isn't
"granted"
(meaning that for whatever reason, access to the persistent storage feature was denied), the origin's site storage unit's box mode is always
"best-effort"
.
注意 : See 使用权限 API for further details about obtaining and managing permissions.
When clearing site storage units, an origin's box is treated as a single entity; if the user agent needs to clear it and the user approves, the entire data store is cleared rather than providing some means of clearing only data from individual APIs.
If a box is marked as
"persistent"
, the contents won't be cleared by the user agent without either the data's origin itself or the user specifically doing so. This includes scenarios such as the user selecting a "Clear Caches" or "Clear Recent History" option. The user will be asked specifically for permission to remove persistent site storage units.
The user agent determines, using whatever mechanism it chooses, the maximum amount of storage a given site can use. This maximum is the origin's quota . The amount of this space which is in use by the site is called its usage . Both of these values are estimates; there are several reasons why they're not precise:
User agents may use any method they choose to determine the size of origins' quotas, and are encouraged by the specification to provide popular or frequently-used sites with extra space.
To determine the estimated quota and usage values for a given origin, use the
navigator.storage.estimate()
method, which returns a promise that, when resolved, receives a
StorageEstimate
that contains these figures. For example:
navigator.storage.estimate().then(estimate => {
// estimate.quota is the estimated quota
// estimate.usage is the estimated number of bytes used
});
| 规范 | 状态 | 注释 |
|---|---|---|
| 存储 | 实时标准 | 初始定义。 |
StorageManager
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
StorageManager
|
Chrome 48 | Edge ≤79 |
Firefox
57
|
IE ? | Opera Yes | Safari ? | WebView Android 48 | Chrome Android 48 |
Firefox Android
51
Disabled
|
Opera Android Yes | Safari iOS ? | Samsung Internet Android 5.0 |
estimate
|
Chrome 52 | Edge ≤79 | Firefox 51 | IE ? | Opera Yes | Safari ? | WebView Android 52 | Chrome Android 52 | Firefox Android 51 | Opera Android Yes | Safari iOS ? | Samsung Internet Android 6.0 |
persist
|
Chrome
52
|
Edge ≤79 | Firefox 55 | IE ? | Opera Yes | Safari ? |
WebView Android
52
|
Chrome Android
52
|
Firefox Android 55 | Opera Android Yes | Safari iOS ? |
Samsung Internet Android
6.0
|
persisted
|
Chrome
52
|
Edge ≤79 | Firefox 55 | IE ? | Opera Yes | Safari ? |
WebView Android
52
|
Chrome Android
52
|
Firefox Android 55 | Opera Android Yes | Safari iOS ? |
Samsung Internet Android
6.0
|
完整支持
兼容性未知
见实现注意事项。
用户必须明确启用此特征。
使用非标名称。
navigator.storage
StorageManager
(对象的返回通过
navigator.storage
)