javascript - 如何在 chrome websocket 代码中接收 TLS 握手错误
问题描述
https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
1015 TLS Handshake Reserved. Indicates that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified).
请参阅:浏览器兼容性
示例 chrome(版本 71.0)返回 1006 错误,firefox(版本 64.0(64 位))1015:
<script>
try{
var websocket = new WebSocket("wss://self-signed.badssl.com/");
websocket.onopen = function (event) {
};
websocket.onclose = function (event) {
var reason;
alert(event.code);
};
websocket.onmessage = function (event) {
};
websocket.onerror = function (event) {
};
}
catch(err){
document.getElementById("demo").innerHTML = err.message;
}
</script>
<p id="demo"></p>
解决方案
catch 不能捕获错误,回调接收的是错误。您可以按照本指南
推荐阅读
- mysql - 无法分析 OSSEC 中的 MySQL 错误日志
- tensorflow - 将两个 tensorflow 数据集连接成一个数据集元素,如示例所示
- c++ - 无法弄清楚如何使用 SDL2 正确格式化 Makefile。未定义参考
- java - 我的代码一直在打印“ [Ljava.lang.String;@4e50df2e”,不太确定该放在哪里以及如何放置 toString()
- java - 需要使用 java 的 lamda 表达式打印字符串的最后一位
- java - 调试:合并排序
- selenium - 使用 goroutine 意外关闭 selenium
- c - C 编程中的蛮力搜索,在 C 编程中读取 .fna 文件
- go - 将 int 切片转换为十六进制值的更好方法
- java - 使用 Spring clound contract 为云合约端点编写生产者测试