StorageManager.estimate()

Baseline 2023

Newly available

Since September 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The estimate() method of the StorageManager interface asks the Storage Manager to obtain quota and usage information for the current origin. This method operates asynchronously, so it returns a Promise which resolves once the information is available. The promise's fulfillment handler receives as an input a StorageEstimate with the usage and quota data.

Синтаксис

var estimatePromise = StorageManager.estimate();

Параметры

None.

Возвращаемый результат

A Promise that resolves to an object which conforms to the StorageEstimate dictionary. This dictionary contains estimates of how much space is available to the origin or app (in StorageEstimate.quota, as well as how much is currently used (in StorageEstimate.usage). These are not exact numbers; between compression, deduplication, and obfuscation for security reasons, they will not be precise.

You may find that the quota varies from app to app based on factors such as the frequency with which the user visits it, commonly-known site popularity data, and so forth.

Примеры

In this example, we obtain the usage estimates and present the percentage of storage capacity currently used to the user.

HTML content

html
<p>
  You're currently using about <span id="percent"> </span>% of your available
  storage.
</p>

JavaScript content

js
navigator.storage.estimate().then(function (estimate) {
  document.getElementById("percent").innerHTML = (
    estimate.usage / estimate.quota
  ).toFixed(2);
});

Результат

Спецификации

Specification
Storage Standard
# ref-for-dom-storagemanager-estimate

Совместимость с браузерами

BCD tables only load in the browser

Смотрите также