{"id":26244012,"url":"https://github.com/shystruk/no-internet","last_synced_at":"2025-04-23T14:35:10.124Z","repository":{"id":27582871,"uuid":"114353526","full_name":"shystruk/no-internet","owner":"shystruk","description":"📡 Checking if the internet is accessible in the browser (not local connection only)","archived":false,"fork":false,"pushed_at":"2023-07-11T13:14:50.000Z","size":381,"stargazers_count":36,"open_issues_count":4,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-13T15:41:09.066Z","etag":null,"topics":["browser","connectivity","internet","internet-connection","javascript","network","offline","online"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/no-internet","language":"JavaScript","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/shystruk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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}},"created_at":"2017-12-15T09:37:46.000Z","updated_at":"2024-06-02T07:18:13.000Z","dependencies_parsed_at":"2024-06-18T22:48:20.213Z","dependency_job_id":"f8312f54-8742-49bb-bc58-61114e7cba3d","html_url":"https://github.com/shystruk/no-internet","commit_stats":{"total_commits":68,"total_committers":5,"mean_commits":13.6,"dds":0.7058823529411764,"last_synced_commit":"7a2a5759b0cecf4f7e19b03f617acea8fb4aa643"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shystruk%2Fno-internet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shystruk%2Fno-internet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shystruk%2Fno-internet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shystruk%2Fno-internet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shystruk","download_url":"https://codeload.github.com/shystruk/no-internet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250452865,"owners_count":21433102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["browser","connectivity","internet","internet-connection","javascript","network","offline","online"],"created_at":"2025-03-13T10:38:45.045Z","updated_at":"2025-04-23T14:35:10.098Z","avatar_url":"https://github.com/shystruk.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# no-internet [![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?hashtags=javascript%20%23Internet%20%23connection\u0026original_referer=https%3A%2F%2Fpublish.twitter.com%2F\u0026ref_src=twsrc%5Etfw\u0026text=%F0%9F%93%A1Check%20if%20the%20internet%20is%20accessible%20(not%20local%20connection%20only).%20Do%20it%20in%20interval%20or%20one%20check%20\u0026tw_p=tweetbutton\u0026url=https%3A%2F%2Fgithub.com%2Fshystruk%2Fno-internet\u0026via=shystrukk) #\n[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php) [![codecov](https://codecov.io/gh/shystruk/no-internet/branch/master/graph/badge.svg)](https://codecov.io/gh/shystruk/no-internet) [![Build Status](https://travis-ci.org/shystruk/no-internet.svg?branch=master)](https://travis-ci.org/shystruk/no-internet)\n[![Known Vulnerabilities](https://snyk.io/test/github/shystruk/no-internet/badge.svg?targetFile=package.json)](https://snyk.io/test/github/shystruk/no-internet?targetFile=package.json)\n[![npm version](https://badge.fury.io/js/no-internet.svg)](https://badge.fury.io/js/no-internet)\n\nChecking if the internet is accessible in the browser (not local connection only)\n\n`window.navigator.onLine` is the simplest approach to return the online status of the browser. It is not guaranteed to be accurate. Most implementations of the API watch for changes in the local network interface to determine if your application is online or not. But what if your network interface is up, but your router is down ☝️. `window.navigator.onLine` will return `true` and it means that you are online and that is WRONG. To handle that case we make `XMLHttpRequest` and listen to change in the network state by events `window.ononline` and `window.onoffline` to be notified immediately 😎 \n\n## Getting no-internet ##\n\n#### npm\n`npm install --save no-internet`\n\n#### yarn\n`yarn add no-internet --save` \n\n## Examples ##\n```javascript\nimport noInternet from 'no-internet'\n```\n\n### One check ###\n```javascript\nnoInternet().then(offline =\u003e {\n    if (offline) {\n        // no internet  \n    }\n})\n```\n\n### Interval checking ###\n```javascript\nfunction noInternetCallback(offline) {\n    if (offline) {\n        // no internet  \n    }\n}\n\n// connection is checked and callback is called each 5000 milliseconds\nnoInternet({ callback: noInternetCallback })\n\n// clear interval\nnoInternet.clearInterval()\n```\n\n### With options ###\n```javascript\nnoInternet({\n    milliseconds: 10000,\n    timeout: 4000,\n    callback: noInternetCallback,\n    url: 'https://github.com/favicon.ico',\n    headers: { 'Access-Control-Allow-Origin': '*' }\n})\n```\n\n## API ##\n### noInternet(options) ###\n\n### options ###\nType: `Object`\n\n#### milliseconds ####\nType: `number` \u003cbr\u003e\nDefault: 5000\n\nConnection is checked at specified intervals (in milliseconds)\n\n#### timeout ####\nType: `number` \u003cbr\u003e\nDefault: 5000\n\nNumber of milliseconds a request can take before automatically being terminated (completed).\n\n#### url ####\nType: `string` \u003cbr\u003e\nDefault: `${window.location.protocol}//${window.location.host}/favicon.ico`\n\nHTTP request is sent to `DOMAIN/favicon.ico` for connection checking. \u003cbr\u003e\nYou can specify URL with domain for e.g. `https://github.com/favicon.ico`\n\n#### headers ####\nType: `Object` \u003cbr\u003e\nDefault: `{ 'Cache-Control': 'no-cache' }`\n\nAn object of additional headers key/value pairs to send along with request\n\n#### callback ####\nType: `function` \u003cbr\u003e\nArguments: `offline` type `boolean` \u003cbr\u003e\nDefault: `undefined`\n\nFunction that gets called in each connection checking\n\n## Contributing\n\nAny contributions you make **are greatly appreciated**.\n\nPlease read the [Contributions Guidelines](CONTRIBUTING.md) before submitting a PR.\n\n## License\n\nMIT © [Vasyl Stokolosa](https://about.me/shystruk)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshystruk%2Fno-internet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshystruk%2Fno-internet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshystruk%2Fno-internet/lists"}