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.

安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。

estimate()StorageManager インターフェイスのメソッドで、ストレージマネージャーに、現在のオリジンが使用しているストレージの大きさ (usage) と、利用可能な空間の量 (quota) を要求します。

このメソッドは非同期的に動作するので、情報が利用可能になると解決する Promise を返します。プロミスの成功ハンドラーは、使用量とクォータのデータを含む StorageEstimate を入力として受け取ります。

構文

js
const estimatePromise = StorageManager.estimate();

引数

なし。

返値

Promise で、これは StorageEstimate 辞書に準拠したオブジェクトに解決します。この辞書には、このオリジンで利用可能なおよその大きさが StorageEstimate.quota に、現在使用されているおよその量が StorageEstimate.usage に入ります。

メモ: **これらは正確な数値ではありません。**圧縮、重複排除セキュリティ上の理由による難読化などが行われるため、正確な値にはなりません。

quota はオリジンごとに異なることに気づくかもしれません。この違いは次のような要因に基づきます。

  • ユーザーが訪れる頻度
  • 公開されたサイトの有名度データ
  • ブックマーク、ホーム画面へ追加、プッシュ通知の受付などのユーザーのエンゲージメントの印

この例では、使用量の概算値を取得し、現在使用しているストレージ容量のパーセント値をユーザーに提示します。

HTML の内容

html
<label>
  現在、使用可能なストレージの約 <output id="percent"> </output>%
  を使用しています。
</label>

JavaScript の内容

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

結果

仕様書

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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
estimate
usageDetails
Non-standard

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Non-standard. Check cross-browser support before using.

関連情報