StorageManager: persist() method
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 insecure contexts (HTTPS), in some or allsupporting browsers.
Thepersist() method of theStorageManager interface requests permission to use persistent storage, and returns aPromise that resolves totrue if permission is granted and bucket mode is persistent, andfalse otherwise. The browser may or may not honor the request, depending on browser-specific rules. (For more details, see the guide toStorage quotas and eviction criteria.)
Note:This method is not available inWeb Workers, though theStorageManager interface is.
In this article
Syntax
persist()Parameters
None.
Return value
Exceptions
TypeErrorThrown if obtaining a local storage shelf failed. For example, if the current origin is an opaque origin or if the user has disabled storage.
Example
if (navigator.storage && navigator.storage.persist) { navigator.storage.persist().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."); } });}Specifications
| Specification |
|---|
| Storage> # dom-storagemanager-persist> |