跳到正文
本页尚未翻译成中文,以下为英文原文。 查看英文版

WebStorage ​

Added in: v1.61

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

java
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 ​

webStorage.clear() ​

Added in: v1.61

Removes all items from the storage.

webStorage.getItem() ​

Added in: v1.61

Returns the value for the given name if present.

Arguments

  • name string

    Name of the item to retrieve.

Returns

  • null | string

webStorage.items() ​

Added in: v1.61

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

Returns

  • Array<Object>

webStorage.removeItem() ​

Added in: v1.61

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

Arguments

  • name string

    Name of the item to remove.

webStorage.setItem() ​

Added in: v1.61

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

Arguments

  • name string

    Name of the item to set.

  • value string

    New value for the item.

基于 Apache 2.0 许可证发布。