There's a bunch of Web APIs that are pretty usable today:

  1. Detect page visibility:
window.addEventListener('visibilitychange', () => {
  console.log(document.visibilityState); // prerender | hidden | visible
});
  1. Detect online state:
window.addEventListener('offline', () => {});
window.addEventListener('online', () => {});
console.log(navigator.onLine); // bool
  1. Vibration:
navigator.vibrate(50); // ms
navigator.vibrate([50, 20, 50]); // pattern (vibrate, wait, ...)
navigator.vibrate(0); // stop vibrating
  1. Detect orientation:
window.addEventListener('deviceorientation', e => {
  console.log(e.gamma);
  console.log(e.beta);
  console.log(e.alpha);
});

...and more! clipboard, ambient light detection, battery status, etc.

Previous on Javascript