{"id":31664031,"url":"https://github.com/esroyo/network-information-api-polyfill","last_synced_at":"2026-05-05T19:32:46.992Z","repository":{"id":306512718,"uuid":"1026444530","full_name":"esroyo/network-information-api-polyfill","owner":"esroyo","description":"Polyfill for navigator.connection Network Information API","archived":false,"fork":false,"pushed_at":"2025-08-20T14:38:27.000Z","size":154,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-07T01:29:23.411Z","etag":null,"topics":["api","browser","cloudflare","connection","connectivity","deno","javascript","jsr","measurement","monitoring","navigator","network","performance","polyfill","real-time","speed-test","typescript","w3c","web-api"],"latest_commit_sha":null,"homepage":"","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/esroyo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"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":"2025-07-25T22:50:30.000Z","updated_at":"2026-03-07T16:30:50.000Z","dependencies_parsed_at":"2025-07-26T06:06:17.388Z","dependency_job_id":"efc5a329-3d86-4fda-ab9e-06b431eb6ed5","html_url":"https://github.com/esroyo/network-information-api-polyfill","commit_stats":null,"previous_names":["esroyo/network-information-api-polyfilll"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/esroyo/network-information-api-polyfill","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esroyo%2Fnetwork-information-api-polyfill","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esroyo%2Fnetwork-information-api-polyfill/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esroyo%2Fnetwork-information-api-polyfill/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esroyo%2Fnetwork-information-api-polyfill/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/esroyo","download_url":"https://codeload.github.com/esroyo/network-information-api-polyfill/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esroyo%2Fnetwork-information-api-polyfill/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32664936,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-05T11:29:49.557Z","status":"ssl_error","status_checked_at":"2026-05-05T11:29:48.587Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["api","browser","cloudflare","connection","connectivity","deno","javascript","jsr","measurement","monitoring","navigator","network","performance","polyfill","real-time","speed-test","typescript","w3c","web-api"],"created_at":"2025-10-07T20:53:41.346Z","updated_at":"2026-05-05T19:32:46.972Z","avatar_url":"https://github.com/esroyo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Network Information API polyfill\n\n[![JSR](https://jsr.io/badges/@esroyo/network-information-api-polyfill)](https://jsr.io/@esroyo/network-information-api-polyfill)\n[![JSR Score](https://jsr.io/badges/@esroyo/network-information-api-polyfill/score)](https://jsr.io/@esroyo/network-information-api-polyfill)\n[![ci](https://github.com/esroyo/network-information-api-polyfill/actions/workflows/ci.yml/badge.svg)](https://github.com/esroyo/network-information-api-polyfill/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/esroyo/network-information-api-polyfill/graph/badge.svg?token=YO7XY0TDX5)](https://codecov.io/gh/esroyo/network-information-api-polyfill)\n\nA polyfill for the [W3C Network Information API](https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API) that provides real-time network connection information when the native API is not available.\n\n## Features\n\n- 🚀 **Automatic installation** - Just import and use with WICG classification\n- 📊 **Real-time measurements** - Active network speed testing using Cloudflare's infrastructure\n- ⚡ **Lightweight** - Less than **3kB** minified and compressed\n- 🎯 **Multiple classification standards** - WICG, Firefox DevTools, Chrome DevTools, or custom\n- 🌳 **Tree-shakeable** - Import only what you need\n- 🔧 **Fully configurable** - Customize thresholds and measurement parameters\n\n## Quick start\n\n### Try it now (no installation!)\n**[Live playground](https://esroyo.github.io/network-information-api-polyfill/) →**\n\nOr test in browser console:\n```javascript\nimport('https://esm.sh/jsr/@esroyo/network-information-api-polyfill').then(() =\u003e {\n    navigator.connection?.addEventListener('change', (e) =\u003e {\n        console.log('🔄 Network changed:', e.detail);\n    });\n});\n```\n\n### Installation\n\n**Automatic (recommended for most users):**\n```typescript\nimport '@esroyo/network-information-api-polyfill';\n\n// Now available on navigator\nnavigator.connection?.addEventListener('change', (event) =\u003e {\n    console.log('Network:', event.detail.effectiveType, event.detail.downlink + 'Mbps');\n});\n```\n\n**Manual with tree-shaking:**\n```typescript\nimport { installNetworkInformationPolyfill } from '@esroyo/network-information-api-polyfill/pure';\nimport CLASSIFICATION_FIREFOX from '@esroyo/network-information-api-polyfill/classifications/firefox';\n\ninstallNetworkInformationPolyfill({\n    classificationTable: CLASSIFICATION_FIREFOX,\n    measurementCount: 3,\n    periodicMeasurement: true\n});\n```\n\n**Standalone instance:**\n```typescript\nimport { createNetworkInformation } from '@esroyo/network-information-api-polyfill/network-information';\nimport CLASSIFICATION_CHROME from '@esroyo/network-information-api-polyfill/classifications/chrome';\n\nconst networkApi = createNetworkInformation({\n    classificationTable: CLASSIFICATION_CHROME,\n    periodicMeasurement: true\n});\n\nnetworkApi.addEventListener('change', (event) =\u003e {\n    console.log('Network changed:', event.detail);\n});\n```\n\n## ⚠️ DevTools throttling limitation\n\n**This polyfill may not reflect throttled speeds when using browser DevTools network throttling.**\n\nDevTools throttling is applied synthetically, but this polyfill uses the **Performance Resource Timing API** which reports actual network timings, not artificial throttling.\n\n**For accurate testing:** Use real mobile networks, network-level throttling, or deploy to staging environments.\n\n## API reference\n\n### Properties\n- `downlink`: Downlink speed in Mbps\n- `uplink`: Uplink speed in Mbps (estimated)\n- `rtt`: Round-trip time in milliseconds\n- `effectiveType`: Connection classification (`'slow-2g'`, `'2g'`, `'3g'`, `'4g'`)\n- `saveData`: Whether data saving mode is enabled\n- `type`: Connection type (always `'unknown'` in polyfill)\n\n### Methods\n- `measure()`: Manually trigger a network measurement\n- `getConnectionInfo()`: Get current connection information\n- `dispose()`: Clean up resources and stop periodic measurements\n- `addEventListener()` / `removeEventListener()`: Event handling\n\n### Configuration\n```typescript\ninterface NetworkInformationConfig {\n    classificationTable: ConnectionClassification[]; // Required\n    origin?: string; // Default: 'https://speed.cloudflare.com'\n    measurementCount?: number; // Default: 2\n    baseMeasurementSize?: number; // Default: 100000 bytes\n    measurementSizeMultiplier?: number; // Default: 2\n    periodicMeasurement?: boolean; // Default: false\n    measurementInterval?: number; // Default: 30000ms\n    estimatedServerTime?: number; // Default: 10ms\n    estimatedHeaderFraction?: number; // Default: 0.005\n}\n```\n\n## Classification standards\n\n### WICG (Default)\nBased on the [official specification](https://wicg.github.io/netinfo/):\n\n| Type      | Max Downlink | Min RTT   | Description                  |\n| --------- | ------------ | --------- | ---------------------------- |\n| `slow-2g` | \u003c 50 kbps    | \u003e 1400ms  | Very slow connection         |\n| `2g`      | \u003c 70 kbps    | \u003e 270ms   | Slow connection              |\n| `3g`      | \u003c 700 kbps   | -         | Moderate connection          |\n| `4g`      | -            | -         | Fast connection              |\n\n### Firefox DevTools / Chrome DevTools\n```typescript\nimport CLASSIFICATION_FIREFOX from '@esroyo/network-information-api-polyfill/classifications/firefox';\nimport CLASSIFICATION_CHROME from '@esroyo/network-information-api-polyfill/classifications/chrome';\n```\n\nDifferent thresholds based on browser DevTools standards. See the [classification files](./src/classifications/) for detailed specifications.\n\n### Custom classifications\n```typescript\nconst customClassification = [\n    { type: 'slow-2g', maxDownlink: 0.1, minRtt: 1000 },\n    { type: '2g', maxDownlink: 0.5, minRtt: 500 },\n    { type: '3g', maxDownlink: 2.0, minRtt: 200 },\n    { type: '4g' }\n];\n```\n\n## Performance tips\n\n- Use `measurementCount: 1` for minimal bandwidth usage\n- Call `dispose()` to prevent memory leaks\n- Balance accuracy vs. resource usage with appropriate intervals\n\n## Browser compatibility\n\nModern browsers with fetch API support.\n\n## Contributing\n\nContributions welcome! Especially new classification standards, bundle optimizations, and performance improvements.\n\n## License\n\nMIT License - see [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesroyo%2Fnetwork-information-api-polyfill","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fesroyo%2Fnetwork-information-api-polyfill","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesroyo%2Fnetwork-information-api-polyfill/lists"}