Chrome doesn't allow unsecure websocket (ws) connections to localhost (only wss, so you should setup a TLS certificate for your local web/websocket server). However the same should work fine with Firefox.
浏览器不支持使用不安全的ws,把localhost改为自己的服务器IP地址即可,或者使用更高级的wss。