WebStorage
WebStorage 通过异步、浏览器一致的 API 为当前源公开页面的 localStorage 或 sessionStorage。
🌐 WebStorage exposes the page's localStorage or sessionStorage for the current origin via an async, browser-consistent API.
可以通过 Page.localStorage() 和 Page.sessionStorage() 访问实例。
🌐 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从存储中移除所有物品。
🌐 Removes all items from the storage.
用法
WebStorage.clear();
返回
getItem
Added in: v1.61如果存在,返回给定name的值。
🌐 Returns the value for the given name if present.
用法
WebStorage.getItem(name);
参数
返回
items
Added in: v1.61以名称/值对的形式返回存储中的所有项目。
🌐 Returns all items in the storage as name/value pairs.
用法
WebStorage.items();
返回
removeItem
Added in: v1.61移除具有给定name的项目。如果项目不存在,则不执行任何操作。
🌐 Removes the item with the given name. No-op if the item is absent.
用法
WebStorage.removeItem(name);
参数
返回
setItem
Added in: v1.61为指定的 name 设置值。会覆盖该名称的任何现有值。
🌐 Sets the value for the given name. Overwrites any existing value for that name.
用法
WebStorage.setItem(name, value);
参数
返回