Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. StorageManager
  4. persist()

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.

Syntax

js
persist()

Parameters

None.

Return value

APromise that resolves to aBoolean.

Exceptions

TypeError

Thrown 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

js
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

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp