Tuesday, October 4
Shadow

Detect system sleep and wake events in browser.

<html>

<head>
  <title>sleep.js</title>
</head>

<body>
  <h1>sleep.js</h1>

  <script src="sleep.js"></script>
  <script>
    function logEvent(event) {
      const time = new Date(event.detail).toTimeString().substr(0, 8);
      console.log(event.type, time);
    };

    document.addEventListener('sleep', logEvent);
    document.addEventListener('wake', logEvent);
  </script>
</body>

</html>

Leave a Reply