{"id":49920840,"url":"https://github.com/en-atul/netlytics","last_synced_at":"2026-05-16T19:45:27.409Z","repository":{"id":337979458,"uuid":"1154191144","full_name":"en-atul/netlytics","owner":"en-atul","description":"A JavaScript library to reliably detect internet connectivity, latency, and connection type for web applications.","archived":false,"fork":false,"pushed_at":"2026-02-21T11:52:03.000Z","size":2433,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-21T17:52:50.184Z","etag":null,"topics":["bunjs","html-css-javascript","web"],"latest_commit_sha":null,"homepage":"https://netlytics.vercel.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/en-atul.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-10T05:30:22.000Z","updated_at":"2026-02-21T11:52:06.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/en-atul/netlytics","commit_stats":null,"previous_names":["en-atul/netlytics"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/en-atul/netlytics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/en-atul%2Fnetlytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/en-atul%2Fnetlytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/en-atul%2Fnetlytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/en-atul%2Fnetlytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/en-atul","download_url":"https://codeload.github.com/en-atul/netlytics/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/en-atul%2Fnetlytics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33117191,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T18:38:32.183Z","status":"ssl_error","status_checked_at":"2026-05-16T18:38:29.903Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bunjs","html-css-javascript","web"],"created_at":"2026-05-16T19:45:26.432Z","updated_at":"2026-05-16T19:45:27.397Z","avatar_url":"https://github.com/en-atul.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- ![Netlytics cover](assets/netlytics.avif) --\u003e\n\n\u003cdiv align=\"center\"\u003e\u003cstrong\u003eNetlytics\u003c/strong\u003e\u003c/div\u003e\n\u003cdiv align=\"center\"\u003eReliable internet connectivity, latency, and connection type for web apps.\u003cbr /\u003eValidates with real HTTP probes — never trust navigator.onLine alone.\u003c/div\u003e\n\u003cbr /\u003e\n\u003cdiv align=\"center\"\u003e\n\u003ca href=\"https://netlytics.vercel.app\"\u003eDemo/Usage\u003c/a\u003e\n\u003cspan\u003e · \u003c/span\u003e\n\u003ca href=\"https://github.com/en-atul/netlytics\"\u003eGitHub\u003c/a\u003e\n\u003cspan\u003e · \u003c/span\u003e\n\u003ca href=\"https://www.npmjs.com/package/netlytics\"\u003eNpm\u003c/a\u003e\n\u003c/div\u003e\n\n## Introduction\n\nA lightweight library for detecting internet connectivity, measuring latency, and identifying connection types (WiFi, mobile data, ethernet) in web applications. Built to fix the common problem where libraries report \"not connected\" even when the user is online.\n\nNetlytics validates connectivity with real HTTP probes instead of relying on unreliable browser APIs. It works consistently across WiFi and mobile data, providing accurate status updates for your users.\n\n## Why\n\nMany NPM connectivity libraries give **wrong results**:\n\n- Relying only on `navigator.onLine` (true when on any network, even without internet)\n- Single-endpoint checks that fail due to CORS, CDN issues, or that one URL being down\n- No distinction between WiFi and mobile data, or bad behavior when switching networks\n\nWe believe connectivity detection should be **reliable** and **accurate**. Netlytics uses multiple probe URLs, configurable timeouts, and validates both online and offline events with real network requests — never trusting `navigator.onLine` alone.\n\n## Install\n\nInstall Netlytics from your command line.\n\n#### With bun\n\n```sh\nbun add netlytics\n```\n\n#### With npm\n\n```sh\nnpm install netlytics\n```\n\n#### With pnpm\n\n```sh\npnpm add netlytics\n```\n\n#### With yarn\n\n```sh\nyarn add netlytics\n```\n\n## Getting started\n\nImport the functions you need and start checking connectivity.\n\n```ts\nimport {\n  checkConnectivity,\n  getConnectionType,\n  measureLatency,\n  watchConnectivity,\n} from \"netlytics\";\n\n// Check if the user is actually online (probe-based, not just navigator.onLine)\nconst result = await checkConnectivity();\nconsole.log(result.online); // true | false\nconsole.log(result.connectionType); // \"wifi\" | \"cellular\" | \"unknown\" | ...\nconsole.log(result.latencyMs); // optional RTT from probe\n\n// Get connection type hint (when supported by browser)\nconst type = getConnectionType(); // \"wifi\" | \"cellular\" | \"ethernet\" | \"unknown\"\n\n// Measure latency in ms\nconst latency = await measureLatency();\nconsole.log(latency); // number | null\n\n// Live updates: both \"online\" and \"offline\" events are validated with a probe\nconst unsubscribe = watchConnectivity(\n  (result) =\u003e {\n    console.log(result.online ? \"Connected\" : \"Disconnected\");\n  },\n  { observe: true } // default; set observe: false to disable\n);\n// later: unsubscribe();\n```\n\n## API\n\nA set of functions to help you build reliable connectivity detection without dealing with browser inconsistencies.\n\n### `checkConnectivity(options?)`\n\nChecks if the device has reachable internet by probing one or more URLs. Returns `Promise\u003cConnectivityResult\u003e`:\n\n- `online: boolean` — Internet reachable (at least one probe succeeded)\n- `connectionType: ConnectionType` — Best-effort: `\"wifi\"` | `\"cellular\"` | `\"ethernet\"` | `\"none\"` | `\"unknown\"`\n- `networkQuality: NetworkQuality` — Best-effort: `\"slow-2g\"` | `\"2g\"` | `\"3g\"` | `\"4g\"` | `\"unknown\"`\n- `latencyMs?: number` — RTT of the first successful probe\n\n**Options:**\n\n- `timeout` — Timeout in ms per probe (default: `5000`)\n- `requiredSuccesses` — How many probes must succeed (default: `1`)\n- `probeUrls` — Custom URLs (must support CORS)\n\n### `getConnectionType()`\n\nReturns `ConnectionType` from the Network Information API when available. Use for UX only; do not use as the only check for online/offline.\n\n### `getNetworkQuality()`\n\nReturns `NetworkQuality` from the Network Information API when available. Represents connection speed/quality (slow-2g, 2g, 3g, 4g).\n\n### `measureLatency(options?)`\n\nMeasures round-trip time (latency) in ms by sampling requests to a reliable endpoint. Returns `Promise\u003cnumber | null\u003e` — average RTT in ms, or `null` if all samples failed.\n\n**Options:**\n\n- `timeout` — Timeout per request (default: `5000`)\n- `sampleSize` — Number of samples (default: `3`)\n\n### `watchConnectivity(callback, options?)`\n\nSubscribes to `online` / `offline` events and **validates each with a network probe** (never relies only on `navigator.onLine`). Returns an `unsubscribe()` function.\n\n**Options (all optional):**\n\n- `observe` — When `true` (default), listen and validate. When `false`, no listeners (manual checks only).\n- `debounceMs` — Delay before probing after an \"online\" event (default: `400`).\n- `offlineProbeTimeoutMs` — Timeout when validating an \"offline\" event (default: `2000`).\n- `onChecking` — Called when a probe is about to run (e.g. to show \"Checking…\").\n- Plus all `ConnectivityOptions` (`timeout`, `probeUrls`, etc.).\n\n## Try it\n\nA live demo is available to test Netlytics in the browser before installing:\n\n- **[Demo (Vercel)](https://netlytics.vercel.app)** — See connectivity detection, connection type, and latency in real time\n\n## Support\n\nNetlytics works with all popular JavaScript frameworks and vanilla JavaScript:\n\n| \u003cimg src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/react/react-original.svg\" width=\"48px\" height=\"48px\" alt=\"React logo\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/vuejs/vuejs-original.svg\" width=\"48px\" height=\"48px\" alt=\"Vue logo\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/angularjs/angularjs-original.svg\" width=\"48px\" height=\"48px\" alt=\"Angular logo\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/svelte/svelte-original.svg\" width=\"48px\" height=\"48px\" alt=\"Svelte logo\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/javascript/javascript-original.svg\" width=\"48px\" height=\"48px\" alt=\"JavaScript logo\"\u003e |\n| ------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| React ✔                                                                                                                                         | Vue ✔                                                                                                                                       | Angular ✔                                                                                                                                            | Svelte ✔                                                                                                                                          | Vanilla JS ✔                                                                                                                                         |\n\n## Contributing\n\nContributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.\n\n## Security\n\nTo report a security vulnerability, please see [SECURITY.md](SECURITY.md).\n\n## License\n\nMIT License - see [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fen-atul%2Fnetlytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fen-atul%2Fnetlytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fen-atul%2Fnetlytics/lists"}