const url = location.origin.replace(/^http/, 'ws') + '/api' console.log("Connecting WebSocket...", url) const ws = new WebSocket(url) ws.onmessage = console.log ws.onopen = () => { ws.send('Hello from the client!') } ws.onerror = console.error