Document.hasStorageAccess()
Baseline 2023
Newly available
Since December 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
语法
var promise = document.hasStorageAccess();
参数
None.
返回值
一个用来判断文档是否有权利访问其第一方存储的Promise
。
If the promise gets resolved and a user gesture event was being processed when the function was originally called, the resolve handler will run as if a user gesture was being processed, so it will be able to call APIs that require user activation.
Examples
document.hasStorageAccess().then((hasAccess) => {
if (hasAccess) {
// storage access has been granted already.
} else {
// storage access hasn't been granted already;
// you may want to call requestStorageAccess().
}
});
Specifications
The API is currently only at the proposal stage — the standardization process has yet to begin. You can currently find specification details of the API at Apple's Introducing Storage Access API blog post, and WHATWG HTML issue 3338 — Proposal: Storage Access API.
Browser compatibility
BCD tables only load in the browser