When the webview is directed to page with an alert or confirm in a setTimeout function, the UI thread will be blocked in the call/handle functions that were set in setConfirmHandler or setOnAlert. The dialog box will not be drawn and the program will stop repainting. However, The dialog box responds the keyboard.
This bug does not manifest in a regular browser.
JOptionPane works as a temporary fix on Windows as the dialog will be drawn, however though the application will not repaint while the dialog is up.
The HTML below manifests the bug:
<html>
<head>
<script>
var x =function(){confirm("message")};
setTimeout(x,250);
</script>
</body>
</html>
This bug does not manifest in a regular browser.
JOptionPane works as a temporary fix on Windows as the dialog will be drawn, however though the application will not repaint while the dialog is up.
The HTML below manifests the bug:
<html>
<head>
<script>
var x =function(){confirm("message")};
setTimeout(x,250);
</script>
</body>
</html>
public class Test extends Application {
public void start(Stage t) {
Group g = new Group();
final Scene s = new Scene(g);
final WebView w = new WebView();
g.getChildren().add(w);
w.getEngine().setOnAlert(new EventHandler<WebEvent<String>>() {
@Override
public void handle(WebEvent<String> event) {
Stage p = new Stage();
p.initOwner(s.getWindow());
p.setScene(new Scene(new Group(), Color.RED));
p.setWidth(400);
p.setHeight(400);
p.showAndWait();
// p.show();
}
});
w.getEngine().loadContent("<html><head><script>"
+ "var x = function(){alert('message')}; setTimeout(x,500);"
+ "</script><body></body></html>");
t.setScene(s);
t.show();
}
public static void main(String[] args) {
launch(args);
}
}
Note that commented call to p.show(). If showAndWait() is replaced with show(), the hang is not observed. I also noticed that if x() is called from <body onload='x();'>, the hang with showAndWait() is still there, but if onload is replaced with onclick, it isn't. It looks like a webkit issue.