Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in establishing websocket connection

I am using ws npm in the server side, websocket in the client side.

When running this code from node-js it works fine, but running it from the browser gives the following error:

failed: Error in connection establishment: net::ERR_CERT_COMMON_NAME_INVALID
const ws = new WebSocket('wss://domain:port', null, { 
  rejectUnauthorized: false 
});

ws.onerror = function (e) {
  console.log(e)
}

ws.onclose = function (e) {
  console.log(e)
}

ws.onopen = function () {
  console.log('connected ')
  ws.send(JSON.stringify({ msg: 'msg' }));
}
like image 267
HaYa Abu Al Halawa Avatar asked Feb 05 '19 20:02

HaYa Abu Al Halawa


Video Answer


1 Answers

net::ERR_CERT_COMMON_NAME_INVALID this looks to be a certificate issue. There are various certificates that a browser use. For eg. you can see the certificates in Mozilla Firefox in Preferences > Privacy & Security > Certificates, and you can explore which certificate is causing you the problem.

Make sure your API is pointing to the correct certificate

like image 146
RC0993 Avatar answered Oct 10 '22 23:10

RC0993