StorageShed Class

The local storage areas of Web Storage (window.localStorage): a storage shed (https://storage.spec.whatwg.org/#storage-shed) whose shelves are keyed by origin, each with the localStorage bottle of its origin. The items are kept in memory, and are persisted by the WebStoragePersistence given to the constructor, if any.

public sealed class StorageShed

Remarks

A shed can be shared by several browsing contexts (see BrowsingContextOptions.LocalStorage): the documents of the same origin read and write the same items, and the storage events are fired at the windows of the browsing contexts that share the shed. The shed is thread-safe.

The items of a storage area are limited by StorageShed.Quota: the sum of the lengths of the keys and the values, in UTF-16 code units. setItem() throws a QuotaExceededError when the new item would exceed it.

Constructors

NameDescription
StorageShed()Creates an empty shed whose storage areas have the default quota (StorageShed.DefaultQuota).
StorageShed(WebStoragePersistence)Creates a shed whose storage areas are persisted, with the default quota (StorageShed.DefaultQuota).
StorageShed(WebStoragePersistence?, long)Creates a shed whose storage areas are persisted.
StorageShed(long)Creates an empty shed.

StorageShed overloads

StorageShed()

StorageShed.cs

Creates an empty shed whose storage areas have the default quota (StorageShed.DefaultQuota).

public StorageShed()

StorageShed(WebStoragePersistence)

StorageShed.cs

Creates a shed whose storage areas are persisted, with the default quota (StorageShed.DefaultQuota).

public StorageShed(WebStoragePersistence persistence)
Parameters
persistence WebStoragePersistence
The persistent storage of the storage areas.

StorageShed(WebStoragePersistence?, long)

StorageShed.cs

Creates a shed whose storage areas are persisted.

public StorageShed(WebStoragePersistence? persistence, long quota)
Parameters
persistence WebStoragePersistence?
The persistent storage of the storage areas, or null to keep them in memory only.
quota long
The maximum size of a storage area: the sum of the lengths of its keys and values, in UTF-16 code units.

StorageShed(long)

StorageShed.cs

Creates an empty shed.

public StorageShed(long quota)
Parameters
quota long
The maximum size of a storage area: the sum of the lengths of its keys and values, in UTF-16 code units.

Properties

NameDescription
PersistenceGets the persistent storage of the storage areas, or null when they are kept in memory only.
QuotaGets the maximum size of a storage area: the sum of the lengths of its keys and values, in UTF-16 code units.

Persistence

StorageShed.cs

Gets the persistent storage of the storage areas, or null when they are kept in memory only.

public WebStoragePersistence? Persistence { get; }

Gets the maximum size of a storage area: the sum of the lengths of its keys and values, in UTF-16 code units.

public long Quota { get; }

Property value

long

Methods

NameDescription
Clear()Removes the items of all the origins, and the persisted items of StorageShed.Persistence. No storage event is fired.
GetItems(string)Returns the items of the storage area of an origin, in the order of Storage.key(). The items of an origin that was not used yet are loaded from StorageShed.Persistence.
GetOrigins()Returns the origins whose storage area has items in memory (the areas loaded from StorageShed.Persistence and the ones the documents used), e.g. to save the storage state of a session.
SetItem(string, string, string)Sets an item of the storage area of an origin (e.g. to restore the storage state of a session, as the storageState option of Playwright). No storage event is fired.

Removes the items of all the origins, and the persisted items of StorageShed.Persistence. No storage event is fired.

public void Clear()

GetItems(string)

StorageShed.cs

Returns the items of the storage area of an origin, in the order of Storage.key(). The items of an origin that was not used yet are loaded from StorageShed.Persistence.

public IReadOnlyList<KeyValuePair<string, string>> GetItems(string origin)

Parameters

origin string
The serialization of the origin (e.g. https://example.com, or http://example.com:8080).

Returns

IReadOnlyList<KeyValuePair<string, string>>

GetOrigins()

StorageShed.cs

Returns the origins whose storage area has items in memory (the areas loaded from StorageShed.Persistence and the ones the documents used), e.g. to save the storage state of a session.

public IReadOnlyList<string> GetOrigins()

SetItem(string, string, string)

StorageShed.cs

Sets an item of the storage area of an origin (e.g. to restore the storage state of a session, as the storageState option of Playwright). No storage event is fired.

public bool SetItem(string origin, string key, string value)

Parameters

origin string
The serialization of the origin (e.g. https://example.com, or http://example.com:8080).
key string
The key of the item.
value string
The value of the item.

Returns

bool True when the item is set, false when it exceeds the quota of the storage area (see StorageShed.Quota).

Constants

NameDescription
DefaultQuotaThe default quota of a storage area: 5 Mi UTF-16 code units (https://storage.spec.whatwg.org/#registered-storage-endpoints: 5 MiB).

DefaultQuota

The default quota of a storage area: 5 Mi UTF-16 code units (https://storage.spec.whatwg.org/#registered-storage-endpoints: 5 MiB).

public const long DefaultQuota = 5242880L