Skip to main content
Version: 1.x

Interface: WebStorageHelper

Typed helper for a single Web Storage area (localStorage or sessionStorage).

Remarks

Wraps the Playwright 1.61+ storage area API with convenience methods for reading, writing, seeding bulk data, and introspecting the current state.

Capability

webStorage.helper

Example

await webStorage.localStorage.seed({ token: 'abc', userId: '42' });
const token = await webStorage.localStorage.getItem('token');

Methods

clear()

clear(): Promise<void>

Removes all entries from the storage area.

Returns

Promise<void>

Promise that resolves once the area is cleared.

Example

await webStorage.sessionStorage.clear();

getItem()

getItem(key): Promise<string | null>

Retrieves the value for a key, or null if the key does not exist.

Parameters

key

string

Storage key to look up.

Returns

Promise<string | null>

Promise resolving to the stored string value or null.

Example

const lang = await webStorage.localStorage.getItem('lang');

items()

items(): Promise<Record<string, string>>

Returns all current entries as a Record<string, string>.

Returns

Promise<Record<string, string>>

Promise resolving to a plain object mapping all keys to their values.

Example

const all = await webStorage.localStorage.items();
console.log(all['theme']); // 'dark'

removeItem()

removeItem(key): Promise<void>

Removes a single key from the storage area.

Parameters

key

string

Storage key to remove.

Returns

Promise<void>

Promise that resolves once the key is removed.

Example

await webStorage.localStorage.removeItem('tempFlag');

seed()

seed(data): Promise<void>

Seeds multiple entries at once, equivalent to calling setItem for each pair.

Parameters

data

Record<string, string>

Key-value pairs to seed into storage.

Returns

Promise<void>

Promise that resolves once all items are stored.

Example

await webStorage.localStorage.seed({ theme: 'dark', lang: 'en', userId: '42' });

setItem()

setItem(key, value): Promise<void>

Sets a single key-value pair in the storage area.

Parameters

key

string

Storage key.

value

string

Storage value (string).

Returns

Promise<void>

Promise that resolves once the item is stored.

Example

await webStorage.localStorage.setItem('theme', 'dark');

size()

size(): Promise<number>

Returns the number of entries currently in the storage area.

Returns

Promise<number>

Promise resolving to the entry count.

Example

const count = await webStorage.localStorage.size();