I'm running a node.js websocket server with self signed certificate.
Sample code:
const WebSocket = require("ws").Server;
const HttpsServer = require('https').createServer;
const fs = require("fs");
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
server = HttpsServer({
cert: fs.readFileSync('cert.pem'),
key: fs.readFileSync('key.pem')
})
socket = new WebSocket({
server: server,
});
socket.on("connection", (ws,r) => {console.log(ws, r);})
server.listen(8443);
When I create the client socket using node.js I do this the following way and it works perfectly:
const WebSocket = require('ws');
s = new WebSocket("wss://0.0.0.0:8443", {rejectUnauthorized: false});
s.onopen = function() {console.log("OPENED")};
When I create a WebSocket via pure JS I get an error "code: 'DEPTH_ZERO_SELF_SIGNED_CERT'" telling me I can't connect because certificate is self-signed.
However I'm developing a chrome extension that needs to communicate with my server via websocket and plain JS WebSocket class doesn't seem to support that. Is there any equivalent, or am I forced to use node.js on client side as well, and is it even possible in sandbox environment via plugin?
Thanks!