是否有可能以某种方式捕获错误:
WebSocket 连接到“ws://127.0.0.1:8080/”失败:连接建立错误:net::ERR_CONNECTION_REFUSED
或不?尝试通过try catch
没有帮助。
升级版:
再深入一点 - 错误发生在库内部的injected
方法中:
function WrappedWebSocket(url, ...args) {
// Throw correct exceptions if the constructor is used improperly.
if (!(this instanceof WrappedWebSocket)) return RealWebSocket();
if (arguments.length < 1) return new RealWebSocket();
let websocket = new RealWebSocket(url, ...args);
checkRequest("websocket", websocket.url, blocked =>
{
if (blocked)
closeWebSocket(websocket);
});
return websocket;
}
在线上:
let websocket = new RealWebSocket(url, ...args);
无法捕获此错误。