HTML JavaScript弱网检测

HTML JavaScript Weak network detecting

我想做一个弱网络检测器。我已经制作了离线和在线检测器。像这样:当然还有一些 JavaScript.

<body onoffline="offlineDetect()" ononline="onlineDetect()">

所以我的问题是有什么方法可以检查连接是否高于 400 毫秒,如果 ping 达到 400 毫秒就会出现警告消息?

 <script>
window.addEventListener('load', function() {
  var status = document.getElementById("status");
  var log = document.getElementById("log");

  function updateOnlineStatus(event) {
    var condition = navigator.onLine ? "online" : "offline";

    status.className = condition;
    status.innerHTML = condition.toUpperCase();

    log.insertAdjacentHTML("beforeend", "Event: " + event.type + "; Status: " + condition);
  }

  window.addEventListener('online',  updateOnlineStatus);
  window.addEventListener('offline', updateOnlineStatus);
});
</script>
<div id="status"></div>
<div id="log"></div>
<p>This is a test</p>