SecurityError while opening websocket


#1

I’m getting security error while opening websocket. I believe this is happening when http get request is made by Angular 2

this.socket = new WebSocket(‘ws://’ + window.location.hostname + ‘:’ + IonicDevServerConfig.wsPort);
Mozilla debugger is showing error on this line. I know this is due CORS, but still want to check if there is any workaround for this


#2

this happens because your page is loaded via https
change "ws://" + in your code to:

(window.location.protocol == "https:" ? "wss://" : "ws://")