offline-detector is a lightweight TypeScript library designed for robustly detecting network online/offline status exclusively within browser environments. Its current stable version is 1.1.1. The library differentiates itself by combining native browser `online`/`offline` events with intelligent network verification through configurable polling, which significantly enhances detection accuracy. It is built to be bundler-agnostic, supporting modern tools like Webpack, Vite, and Rollup, and is tree-shakable for minimal bundle size. Development is active, with recent minor and patch releases introducing features like network polling (v1.1.0) and updating Node.js engine requirements for development/testing (v1.1.1). It provides full TypeScript support, debounced state changes to prevent rapid status fluctuations, and extensive configuration options for customizing network tests and event handling.
npm install offline-detectorVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes the offline detector, starts monitoring network status, and logs changes. It also demonstrates checking the current status and properly stopping/destroying the detector.
Ensure the `offline-detector` is only imported and executed within client-side browser code or use dynamic imports with `typeof window !== 'undefined'` checks for SSR applications.
Update your Node.js version to 18.0.0 or higher using a version manager like `nvm` or `volta`.
Customize the `networkVerification` options in `createOfflineDetector` to suit your application's needs, adjusting `interval` for less frequent checks and ensuring `url` points to a stable, low-latency endpoint, or disable `enabled` if only native events are desired.
Wrap the `createOfflineDetector` call and other library usages in a conditional block to ensure they only run in a browser: `if (typeof window !== 'undefined') { /* ... library usage ... */ }`. For frameworks like Next.js or Astro, use dynamic imports with `ssr: false`.Ensure you are using `import { createOfflineDetector } from 'offline-detector';` and that your build setup correctly processes ESM. Avoid `const detector = require('offline-detector');` which is not supported for this module.No dependency data recorded yet.