{"id":13671102,"url":"https://github.com/DamonOehlman/detect-browser","last_synced_at":"2025-04-27T14:33:05.297Z","repository":{"id":470514,"uuid":"21321647","full_name":"DamonOehlman/detect-browser","owner":"DamonOehlman","description":"Unpack a browser type and version from the useragent string","archived":false,"fork":false,"pushed_at":"2024-08-20T21:50:05.000Z","size":206,"stargazers_count":696,"open_issues_count":43,"forks_count":101,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-20T13:38:03.086Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/DamonOehlman.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2014-06-29T11:10:27.000Z","updated_at":"2025-04-10T17:57:38.000Z","dependencies_parsed_at":"2024-10-21T15:41:45.141Z","dependency_job_id":null,"html_url":"https://github.com/DamonOehlman/detect-browser","commit_stats":{"total_commits":149,"total_committers":39,"mean_commits":"3.8205128205128207","dds":0.3489932885906041,"last_synced_commit":"546e6f1348375d8a486f21da07b20717267f6c49"},"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DamonOehlman%2Fdetect-browser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DamonOehlman%2Fdetect-browser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DamonOehlman%2Fdetect-browser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DamonOehlman%2Fdetect-browser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DamonOehlman","download_url":"https://codeload.github.com/DamonOehlman/detect-browser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251154294,"owners_count":21544476,"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":[],"created_at":"2024-08-02T09:00:59.072Z","updated_at":"2025-04-27T14:33:04.968Z","avatar_url":"https://github.com/DamonOehlman.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Utilities"],"sub_categories":["React Components"],"readme":"# detect-browser\n\nThis is a package that attempts to detect a browser vendor and version (in\na semver compatible format) using a navigator useragent in a browser or\n`process.version` in node.\n\n[![NPM](https://nodei.co/npm/detect-browser.png)](https://nodei.co/npm/detect-browser/)\n\n[![stable](https://img.shields.io/badge/stability-stable-green.svg)](https://github.com/dominictarr/stability#stable) [![Build Status](https://api.travis-ci.org/DamonOehlman/detect-browser.svg?branch=master)](https://travis-ci.org/DamonOehlman/detect-browser) [![Maintainability](https://api.codeclimate.com/v1/badges/84947fce3f3b06da69d0/maintainability)](https://codeclimate.com/github/DamonOehlman/detect-browser/maintainability)\n\n## Installation\n\n[![CDN](https://img.shields.io/badge/CDN-UNPKG-blue.svg)](https://unpkg.com/browse/detect-browser)\n\n[![NPM](https://img.shields.io/badge/Package-npm-purple.svg)](https://www.npmjs.com/package/detect-browser)\n\n## Release History\n\nRelease history can be found in the [github releases list](https://github.com/DamonOehlman/detect-browser/releases).\n\n---\n\n## Example Usage\n\n```js\nconst { detect } = require('detect-browser');\nconst browser = detect();\n\n// handle the case where we don't detect the browser\nif (browser) {\n  console.log(browser.name);\n  console.log(browser.version);\n  console.log(browser.os);\n}\n```\n\nOr you can use a switch statement:\n\n```js\nconst { detect } = require('detect-browser');\nconst browser = detect();\n\n// handle the case where we don't detect the browser\nswitch (browser \u0026\u0026 browser.name) {\n  case 'chrome':\n  case 'firefox':\n    console.log('supported');\n    break;\n\n  case 'edge':\n    console.log('kinda ok');\n    break;\n\n  default:\n    console.log('not supported');\n}\n```\n\nAdditionally, from `5.x` a `type` discriminator is included in the result\nshould you want to use this (it's a nice convenience in a TS environment).\n\nContrived example:\n\n```ts\nimport { detect } from '../src';\n\nconst result = detect();\nif (result) {\n  switch (result.type) {\n    case 'bot':\n      // result is an instanceof BotInfo\n      console.log(`found ${result.name} bot`);\n      break;\n\n    case 'bot-device':\n      // result is an instanceof SearchBotDeviceInfo\n      console.log(`found ${result.name} device bot`);\n      break;\n\n    case 'browser':\n      // result is an instanceof BrowserInfo\n      console.log(`found ${result.name} browser`);\n      break;\n\n    case 'node':\n      // result is an instanceof NodeInfo\n      console.log(`found node version ${result.version}`);\n      break;\n  }\n}\n```\n\n**NOTE:** In addition to the the `detect` function, `browserName` and\n`detectOS` are provided as exports if you want to only access certain\ninformation.\n\nAn editable observable workbook is [available here](https://observablehq.com/@rayshan/browser-detection-tester-using-the-detect-browser-package).\n\n## Adding additional browser support\n\nThe current list of browsers that can be detected by `detect-browser` is\nnot exhaustive. If you have a browser that you would like to add support for\nthen please submit a pull request with the implementation.\n\nCreating an acceptable implementation requires two things:\n\n1. A test demonstrating that the regular expression you have defined identifies\n   your new browser correctly. Examples of this can be found in the\n   `test/logic.js` file.\n\n2. Write the actual regex to the `index.js` file. In most cases adding\n   the regex to the list of existing regexes will be suitable (if usage of `detect-browser`\n   returns `undefined` for instance), but in some cases you might have to add it before\n   an existing regex. This would be true for a case where you have a browser that\n   is a specialised variant of an existing browser but is identified as the\n   non-specialised case.\n\nWhen writing the regular expression remember that you would write it containing a\nsingle [capturing group](https://regexone.com/lesson/capturing_groups) which\ncaptures the version number of the browser.\n\n## LICENSE\n\nThe MIT License (MIT)\n\nCopyright (c) 2019 Damon Oehlman \u003cdamon.oehlman@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDamonOehlman%2Fdetect-browser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDamonOehlman%2Fdetect-browser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDamonOehlman%2Fdetect-browser/lists"}