I'm trying to load a local storage value into the HtmlUnit web client before it loads a specific website:
HtmlPage initialPage = webClient.getPage(url);
if (httpHeadersSpec != null && httpHeadersSpec.getLocal_storage() != null) {
for (StorageItemSpec item : httpHeadersSpec.getLocal_storage()) {
initialPage.executeJavaScript(
"localStorage.setItem('" + item.getKey() + "', '" + item.getValue() + "');");
}
}
HtmlPage page = webClient.getPage(url);
webClient.waitForBackgroundJavaScriptStartingBefore(3000);
URL baseUrl = page.getFullyQualifiedUrl(page.getBaseURI());
The problems are:
- How do I check if the local storage value is loaded?
- What is the correct approach to load a browser's local storage value to HtmlUnit before loading a page?
Starting with version 3.4.0 there is a documented (https://www.htmlunit.org/details.html#Local.2FSession_Storage) way to do this.
(Btw the latest 3.4.0-SNAPSHOT already constains this)