ADDITIONAL SYSTEM INFORMATION :
Tested and reproducible on Java 8, 11 and 15 with Linux and Windows 10 with according according JavaFX.
A DESCRIPTION OF THE PROBLEM :
When "window.close()" in JavaScript is called within a webpage loaded into a WebEngine-instance, the "localStorage" (in JavaScript) will permanently become null.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- create empty file on /tmp/foo.html (or change path, or use web URL)
- make sure user-data-directory parent is writable (/tmp/java-store)
- run main in LocalStorageBugDemo (which reads localStorage, "closes" window and reads storage again)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
localStorage before close is: [object Storage]
localStorage before close is: [object Storage]
ACTUAL -
localStorage before close is: [object Storage]
localStorage after close is: null
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.application.Platform;
import javafx.concurrent.Worker;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import java.io.File;
public class LocalStorageBugDemo extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(final Stage stage) {
final WebView webView = new WebView();
final WebEngine webEngine = webView.getEngine();
webEngine.setJavaScriptEnabled(true);
webEngine.setUserDataDirectory(new File("/tmp/java-store"));
webEngine.load("file:///tmp/foo.html");
webEngine.getLoadWorker().stateProperty().addListener((observable, oldValue, newState) -> {
if (newState == Worker.State.SUCCEEDED) {
System.out.println("localStorage before close is: " + webEngine.executeScript("localStorage;"));
webEngine.executeScript("window.close();");
System.out.println("localStorage after close is: " + webEngine.executeScript("localStorage;"));
Platform.exit();
}
}
);
}
}
---------- END SOURCE ----------
Tested and reproducible on Java 8, 11 and 15 with Linux and Windows 10 with according according JavaFX.
A DESCRIPTION OF THE PROBLEM :
When "window.close()" in JavaScript is called within a webpage loaded into a WebEngine-instance, the "localStorage" (in JavaScript) will permanently become null.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- create empty file on /tmp/foo.html (or change path, or use web URL)
- make sure user-data-directory parent is writable (/tmp/java-store)
- run main in LocalStorageBugDemo (which reads localStorage, "closes" window and reads storage again)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
localStorage before close is: [object Storage]
localStorage before close is: [object Storage]
ACTUAL -
localStorage before close is: [object Storage]
localStorage after close is: null
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.application.Platform;
import javafx.concurrent.Worker;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import java.io.File;
public class LocalStorageBugDemo extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(final Stage stage) {
final WebView webView = new WebView();
final WebEngine webEngine = webView.getEngine();
webEngine.setJavaScriptEnabled(true);
webEngine.setUserDataDirectory(new File("/tmp/java-store"));
webEngine.load("file:///tmp/foo.html");
webEngine.getLoadWorker().stateProperty().addListener((observable, oldValue, newState) -> {
if (newState == Worker.State.SUCCEEDED) {
System.out.println("localStorage before close is: " + webEngine.executeScript("localStorage;"));
webEngine.executeScript("window.close();");
System.out.println("localStorage after close is: " + webEngine.executeScript("localStorage;"));
Platform.exit();
}
}
);
}
}
---------- END SOURCE ----------