Syntax error on new WebSocket in edge, internet explorer

陌路散爱 提交于 2021-02-08 10:30:04

问题


So I think I am getting crazy.

I use javaScript to make a WebSocket connection on port 443.

The problem is that the WebSocket declaration is throwing a SyntaxError only on edge and internet explorer browsers, on other browsers like Chrome and Firefox it works perfectly.

The code that I use:

var Connection;
Connection = new WebSocket("ws:/127.0.0.1:443");

Does someone knows what am I doing wrong?


回答1:


change it to:

var connection = new WebSocket("ws://127.0.0.1:443");



回答2:


This issue comes from the webpackHotDevClient.js file (line 60)

./node_modules/react-dev-utils/webpackHotDevClient.js:60

Add slashes: true, to the format object to solve it, your update should look like the following snippet:

// Connect to WebpackDevServer via a socket.
var connection = new WebSocket(
  url.format({
    protocol: window.location.protocol === 'https:' ? 'wss' : 'ws',
    hostname: window.location.hostname,
    port: window.location.port,
    // Hardcoded in WebpackDevServer
    pathname: '/sockjs-node',
    slashes: true,
  })
);


来源:https://stackoverflow.com/questions/36667587/syntax-error-on-new-websocket-in-edge-internet-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!