WebSockets in Chrome and Firefox Disconnecting After One Minute of Inactivity : <p>I have found that WebSockets in Chrome and Firefox disconnect after exactly one minute of inactivity.  Based on stuff I've seen online, I was all set to blame proxies or some server settings or something, but this does not happen in IE or Edge.  It seems like if sockets are disconnected by the server after one minute of inactivity that would apply to IE and Edge just as much as Chrome and Firefox.</p>

<p>Does anyone know why this is?  Is it documented anywhere?  I know a possible way to stop it by pinging, but I'm more interested in why it's happening.  The reason code given on disconnect is 1006, indicating that the browser closed the connection.  No errors are thrown and the onerror event for the socket is not triggered.</p>

<p>This project was built at <a href="https://glitch.com/edit/#!/noiseless-helmet" rel="noreferrer">https://glitch.com/edit/#!/noiseless-helmet</a> where you can see and run everything.  The client page is served here: <a href="https://noiseless-helmet.glitch.me/" rel="noreferrer">https://noiseless-helmet.glitch.me/</a></p>

<p>Here is my client page:</p>

<pre><code>&lt;div id="div"&gt;
&lt;/div&gt;
&lt;script&gt;
  let socket = new WebSocket("wss://noiseless-helmet.glitch.me/");
  socket.onmessage = function(event) {
    div.innerHTML += "&lt;br&gt;message " + new Date().toLocaleString() + " " + event.data;
  };
  socket.onopen = function (event) {
    div.innerHTML += "&lt;br&gt;opened " + new Date().toLocaleString();
    socket.send("Hey socket! " + new Date().toLocaleString());
  };
  socket.onclose = function(event) {
    div.innerHTML += "&lt;br&gt;socket closed " + new Date().toLocaleString();
    div.innerHTML += "&lt;br&gt;code: " + event.code;
    div.innerHTML += "&lt;br&gt;reason: " + event.reason;
    div.innerHTML += "&lt;br&gt;clean: " + event.wasClean;
  };
  socket.onerror = function(event) {
    div.innerHTML += "&lt;br&gt;error: " + event.error;
  };
&lt;/script&gt;
</code></pre>

<p>And here is my Node.js server code:</p>

<pre><code>var express = require('express');
var app = express();
app.use(express.static('public'));

let server = require('http').createServer(),
  WebSocketServer = require('ws').Server,
  wss = new WebSocketServer({ server: server });

app.get("/", function (request, response) {
  response.sendFile(__dirname + '/views/index.html');
});

let webSockets = [];
wss.on('connection', function connection(socket) {
  webSockets.push(socket);
  webSockets.forEach((w) =&gt; { w.send("A new socket connected"); });
  socket.on('close', (code, reason) =&gt; {
    console.log('closing socket');
    console.log(code);
    console.log(reason);
    let i = webSockets.indexOf(socket);
    webSockets.splice(i, 1);
  });
});

server.on('request', app);
server.listen(process.env.PORT, function () {
  console.log('Your app is listening on port ' + server.address().port);
});
</code></pre>
