• Which version of chrome do you have? I just bodged your code into something using the websocket example HTML, and this works for me:

    var WIFI_NAME = "";
    var WIFI_OPTIONS = { password : "" };
    var MATRIXPIN = B5;
    var info = {};
    
    var page = `<html><body><script>var ws;setTimeout(function(){
    ws = new WebSocket("ws://" + location.host + "/my_websocket", "protocolOne");
    ws.onmessage = function (event) { console.log("MSG:"+event.data); };
    setTimeout(function() { ws.send("Hello to Espruino!"); }, 1000);
    },1000);</script></body></html>`;
    
    function processRequest(req,res) {
      console.log(req);
      res.writeHead(200, {'Content-Type': 'text/html'});
      res.end(page);
    }
    
    function onInit() {
      neopixel = require("neopixel");
      neopixel.write(MATRIXPIN,[255,0,0]); // On
      wifi = require("EspruinoWiFi");
      wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(e) { 
        if (e) {
          console.log("Connection Error: "+e);
          neopixel.write(MATRIXPIN,[0,255,0]); // Connection Error
          return;
        }
        wifi.getIP(function(f,ip) {
          info.macaddress = ip.mac;
          info.ipaddress = ip.ip;
          console.log("Connected: ",info);
          var server = require("ws").createServer(processReques­t);
          server.listen(80);
          server.on("websocket", function(ws) {
            console.log("Connection upgraded");
            ws.on('message',function(msg) {
              console.log("Message received");
              print("[WS] "+JSON.stringify(msg));
            });
            ws.send("Hello from Espruino!");
          });
          neopixel.write(MATRIXPIN,[0,0,255]); // Connected
        });
      });
    }
    
    onInit();
    

    How are you accessing the server? I wonder if something differs when it's cross-origin?

About

Avatar for Gordon @Gordon started