Spec-Zone.ru › Playwright

WebStorage

WebStorage exposes the page's localStorage or sessionStorage for the current origin via an async, browser-consistent API.

Instances are accessed through page.localStorage and page.sessionStorage.

await page.goto('https://example.com');
await page.localStorage.setItem('token', 'abc');
const token = await page.localStorage.getItem('token');
const all = await page.localStorage.items();
await page.localStorage.removeItem('token');
await page.localStorage.clear();

Methods​

clear​

Removes all items from the storage.

Usage

await webStorage.clear();

Returns

  • Promise<void>

getItem​

Returns the value for the given name if present.

Usage

await webStorage.getItem(name);

Arguments

  • name string

    Name of the item to retrieve.

Returns

  • Promise<null | string>

items​

Returns all items in the storage as name/value pairs.

Usage

await webStorage.items();

Returns

  • Promise<Array<Object>>
    • name string

    • value string

removeItem​

Removes the item with the given name. No-op if the item is absent.

Usage

await webStorage.removeItem(name);

Arguments

  • name string

    Name of the item to remove.

Returns

  • Promise<void>

setItem​

Sets the value for the given name. Overwrites any existing value for that name.

Usage

await webStorage.setItem(name, value);

Arguments

  • name string

    Name of the item to set.

  • value string

    New value for the item.

Returns

  • Promise<void>

© 2026 Microsoft
Licensed under the Apache License, Version 2.0.
https://playwright.dev/docs/api/class-webstorage

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API