net-watch

Introduction

net-watch tells your app whether the user can really reach the internet, and how good the connection is.

net-watch is a small TypeScript library that answers two questions in the browser:

  1. Is the user really online? Not "is a network interface up", but "can this page reach a server".
  2. How good is the connection? Latency, a quality band from excellent to poor, download speed, and what the browser knows about the link.

It gives you one immutable state object, a way to subscribe to it, and an optional offline banner. The core has no dependencies. React, Vue and Angular get a tiny adapter each.

import { createNetworkWatcher } from '@net-watch/core'

const watcher = createNetworkWatcher({ pingUrl: '/api/ping' })

watcher.subscribe((state) => {
  console.log(state.online, state.quality, state.rtt) // true 'good' 150
})

Where to go next

Packages

PackageUse it for
@net-watch/coreThe watcher, plus @net-watch/core/fetch (watchFetch) and @net-watch/core/banner (createBanner). No dependencies.
@net-watch/reactuseNetworkStatus() for React 18 and later.
@net-watch/vueuseNetworkStatus() for Vue 3.3 and later.
@net-watch/angularinjectNetworkStatus() for Angular 17 and later.

All four packages share one version number. They run in Chrome and Edge 90, Firefox 90 and Safari 15 or newer; see browser support.

On this page