StorageManager: phương thức persisted()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since December 2021.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
Phương thức persisted() của giao diện StorageManager trả về một Promise được giải quyết thành true nếu bucket lưu trữ của site bạn là persistent.
Cú pháp
js
persisted()
Tham số
Không có.
Giá trị trả về
Ngoại lệ
TypeError-
Được ném ra nếu không thể lấy shelf lưu trữ cục bộ. Ví dụ, nếu origin hiện tại là opaque origin hoặc nếu người dùng đã vô hiệu hóa lưu trữ.
Ví dụ
js
if (navigator.storage && navigator.storage.persist) {
navigator.storage.persisted().then((persistent) => {
if (persistent) {
console.log("Storage will not be cleared except by explicit user action");
} else {
console.log("Storage may be cleared by the UA under storage pressure.");
}
});
}
Thông số kỹ thuật
| Specification |
|---|
| Storage> # dom-storagemanager-persisted> |