MDN self-hosted library · e01.org

StorageArea.getBytesInUse()

Gets the amount of storage space, in bytes, used by one or more items stored in the storage area.

no runnable cells webextension-api-function upstream source

Gets the amount of storage space, in bytes, used by one or more items stored in the storage area.

[!NOTE] In Firefox, this method is supported in:

  • storage.sync.
  • storage.session from Firefox 131.
  • storage.local and storage.managed from Firefox 144.

[!NOTE] storage.managed.getBytesInUse() always returns 0, at least in Chrome and Firefox.

Syntax

let gettingSpace = browser.storage.<storageType>.getBytesInUse(
  keys                      // null, string, or array of strings
)

Where <storageType> is one of the storage types: sync, local, session, or managed.

Parameters

  • keys
  • : A key (string) or keys (an array of strings) to identify the items whose storage space you want to retrieve. If an empty array is passed in, 0 is returned. If you pass null or undefined, the function returns the space used by the entire storage area.

Return value

A Promise that is fulfilled with an integer, bytesUsed, representing the storage space used by the objects specified in keys. If the operation fails, the promise is rejected with an error message.

Browser compatibility

[!NOTE] This API is based on Chromium's chrome.storage API. This documentation is derived from storage.json in the Chromium code.