我有一个示例 JavaFX 应用程序,其中 WebView 从本地文件加载 HTML。在 HTML 中,我打开 websocket(到 wss://echo.websocket.org/)并定义 onopen、onmessage 和 onerror 回调。
当我使用 8u401 运行它时,我看到弹出窗口,但没有看到 8u411 的任何内容。
我能够在 Windows 10 和 MacOS 上重现它。
要重现的Java代码:
package org.example.javafx;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import java.net.URL;
public class WebViewExample extends Application {
public static void main(String[] args) {
launch(args);
}
public void start(Stage primaryStage) {
primaryStage.setTitle("JavaFX WebView Example running with " + Runtime.class.getPackage().getImplementationVersion());
WebView webView = new WebView();
webView.getEngine().setOnAlert(arg0 -> {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Message");
alert.setHeaderText(arg0.getData());
alert.show();
});
URL url = this.getClass().getResource("main.html");
webView.getEngine().load(url.toString());
VBox vBox = new VBox(webView);
Scene scene = new Scene(vBox, 960, 600);
primaryStage.setScene(scene);
primaryStage.show();
}
}
和 HTML 文件:
<!DOCTYPE html>
<html>
<body>
<script>
let socket = new WebSocket("wss://echo.websocket.org/");
socket.onopen = function(e) {
alert("[open] Connection established");
socket.send("My name is John");
};
socket.onmessage = function(event) {
alert('[message] Data received from server!');
};
socket.onerror = function(event) {
alert("ERROR!");
};
</script>
</body>
</html>
8u401 上的结果 - 有关连接和收到消息的警报可见: 8u411 上的结果 - 没有弹出任何内容:
还有什么遗漏吗?
我尝试过32位、64位JRE、Mac OS和Windows。
@tucoramirez37 如果问题仍然存在,
访问被拒绝
您无权访问此服务器上的“http://bugreport.java.com/bugreport/submit_start”。
请提供参考编号 [参考:18.................]