Skip to content

API in Storage

StorageManager.persist() and persisted()

Published Updated

navigator.storage.persist() requests persistent storage for the origin’s storage bucket. Persistence exempts Cache Storage, IndexedDB, OPFS, and service worker registrations from automatic eviction under storage pressure. Use navigator.storage.persisted() to check whether the bucket is persistent. Persistence controls whether the browser may clear data without a user request; in Firefox it also raises the origin’s quota ceiling.

navigator.storage.persist()
navigator.storage.persisted()

Both return a Promise<boolean>. persist() fulfils with true when the bucket is persistent after the call, whether it was just granted or already was, and false when the browser declined or an internal error got in the way. persisted() only reads the current mode. persist() is exposed on Window but not inside workers; persisted() is available in both (BCD api.StorageManager.persist: Chrome 55, Firefox 57, Safari 15.2). Both require a secure context.

None.

Exception When
TypeError The browser cannot obtain a storage shelf for the origin: the origin is opaque (a sandboxed <iframe> without allow-same-origin, a data: or file: document in some engines) or the user has disabled storage for the site. The promise rejects.

If the browser declines persistence, persist() fulfils with false and the origin stays best-effort. It does not throw an exception.

The Storage Standard leaves the decision to the browser, and the three engines took three different routes (Storage quotas and eviction criteria, developer.mozilla.org).

Engine Behaviour on persist() What tips the decision
Chromium (Chrome, Edge) No prompt. The request is granted or silently denied, and a denied request can be made again later (Persistent storage, web.dev). Site engagement score, whether the site is installed or bookmarked, whether the notifications permission is granted.
Firefox Shows a permission doorhanger and waits for the user. The user’s click.
WebKit (Safari 15.2+) No prompt; the request is auto-granted or denied from the user’s interaction history with the site. The user’s interaction history with the site.

Because Chromium’s grant depends on those signals, a call before the site has earned any engagement can come back false, and web.dev advises asking when the user saves critical data, not on page load. A denied request is evaluated again on a later call, so asking after the user installs the app or enables notifications can succeed without changing the code.

There is no API to revoke persistence from script. The user removes persistent data through the browser’s site settings (in Chrome, chrome://settings/content/siteDetails?site=<origin>; in Firefox, the permissions section of Page Info), and clearing the site’s data deletes what was stored.

Request persistence once after user engagement, and read the storage mode on each launch.

Requesting persistence after an engagement signal

Section titled “Requesting persistence after an engagement signal”

Request persistence after an action that signals the site is valuable to the user, such as a successful install or a granted notification permission. Check the returned boolean to find out whether the request succeeded.

async function requestDurableStorage() {
if (await navigator.storage.persisted()) return true;
const granted = await navigator.storage.persist();
if (!granted) {
console.info('Storage stays best-effort; queued work will be re-synced if evicted.');
}
return granted;
}

A false result leaves the origin best-effort: data written to IndexedDB or Cache Storage normally stays until storage pressure, a user deletion, the end of a private session, or, in Safari with cross-site tracking prevention on, seven days of browser use without interaction (see Eviction and best-effort storage), so the app should work when data goes missing. Design the sync layer so a missing record is re-fetched or re-derived. A missing record does not by itself indicate corruption.

Reporting the current mode in a settings screen

Section titled “Reporting the current mode in a settings screen”

persisted() only reads the mode and never prompts. Read it on each launch, because the user can revoke persistence between visits and Chromium can grant a previously denied request once engagement rises.

async function describeStorageMode() {
const persistent = await navigator.storage.persisted();
return persistent
? 'Offline data is protected from automatic clearing.'
: 'Offline data may be cleared when the device runs low on space.';
}

Pair the sentence with the usage figures from StorageManager.estimate() so the screen explains both how much is stored and how safe it is.

navigator.storage is missing on insecure origins and in browsers older than Chrome 55, Firefox 57, and Safari 15.2. Treat a missing method as best-effort storage.

async function ensurePersistence() {
if (!('storage' in navigator) || typeof navigator.storage.persist !== 'function') {
return false; // not supported: behave as best-effort storage
}
try {
return await navigator.storage.persist();
} catch (err) {
if (err.name === 'TypeError') return false; // opaque origin or storage disabled
throw err;
}
}

The function returns the same false for “unsupported”, “declined”, and “storage disabled”, which is deliberate: the calling code has one fallback, and it is the same in each case.

Specifications

SpecificationStatus
None.