◐ Shell
clean mode source ↗

WebStorage | Playwright Java

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().

page.navigate("https://example.com");

page.localStorage().setItem("token", "abc");

String token = page.localStorage().getItem("token");

List<WebStorageItem> all = page.localStorage().items();

page.localStorage().removeItem("token");

page.localStorage().clear();


Methods

clear

Added in: v1.61

webStorage.clear

Removes all items from the storage.

Usage

Returns


getItem

Added in: v1.61

webStorage.getItem

Returns the value for the given name if present.

Usage

WebStorage.getItem(name);

Arguments

  • name String#

    Name of the item to retrieve.

Returns


items

Added in: v1.61

webStorage.items

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

Usage

Returns


removeItem

Added in: v1.61

webStorage.removeItem

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

Usage

WebStorage.removeItem(name);

Arguments

  • name String#

    Name of the item to remove.

Returns


setItem

Added in: v1.61

webStorage.setItem

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

Usage

WebStorage.setItem(name, value);

Arguments

  • name String#

    Name of the item to set.

  • value String#

    New value for the item.

Returns