{"id":18324017,"url":"https://github.com/dirk/browser2","last_synced_at":"2025-04-09T15:13:57.393Z","repository":{"id":56843108,"uuid":"48449957","full_name":"dirk/browser2","owner":"dirk","description":"Optimized browser user agent detection library.","archived":false,"fork":false,"pushed_at":"2016-01-13T05:04:27.000Z","size":302,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T15:13:54.648Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/dirk/browser2","language":"Ruby","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/dirk.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}},"created_at":"2015-12-22T19:28:19.000Z","updated_at":"2016-01-13T04:56:31.000Z","dependencies_parsed_at":"2022-09-01T11:30:32.465Z","dependency_job_id":null,"html_url":"https://github.com/dirk/browser2","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirk%2Fbrowser2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirk%2Fbrowser2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirk%2Fbrowser2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirk%2Fbrowser2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dirk","download_url":"https://codeload.github.com/dirk/browser2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055275,"owners_count":21040157,"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-11-05T18:31:08.329Z","updated_at":"2025-04-09T15:13:57.375Z","avatar_url":"https://github.com/dirk.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Browser\n\n[![Travis-CI](https://travis-ci.org/dirk/browser2.png)](https://travis-ci.org/dirk/browser2)\n\nPerformance-optimized fork of the [`browser`](https://github.com/fnando/browser) Ruby gem.\n\n## Installation\n\n```bash\ngem install browser\n```\n\n## Usage\n\n```ruby\nrequire 'rubygems'\nrequire 'browser2'\n\nbrowser = Browser.new ua: 'some string', accept_language: 'en-us'\nbrowser.name            # readable browser name\nbrowser.version         # major version number\nbrowser.full_version\nbrowser.safari?\nbrowser.opera?\nbrowser.chrome?\nbrowser.chrome_os?\nbrowser.mobile?\nbrowser.tablet?\nbrowser.console?\nbrowser.firefox?\nbrowser.ie?\nbrowser.ie?(6)          # detect specific IE version\nbrowser.edge?           # Newest MS browser\nbrowser.modern?         # Webkit, Firefox 17+, IE 9+ and Opera 12+\nbrowser.platform        # return :mac, :windows, :linux or :other\nbrowser.ios?            # detect iOS\nbrowser.ios?(9)         # detect specific iOS version\nbrowser.mac?\nbrowser.windows?\nbrowser.windows_x64?\nbrowser.linux?\nbrowser.blackberry?\nbrowser.blackberry?(10) # detect specific BlackBerry version\nbrowser.bot?\nbrowser.search_engine?\nbrowser.phantom_js?\nbrowser.quicktime?\nbrowser.core_media?\nbrowser.silk?\nbrowser.android?\nbrowser.android?(4.2)   # detect Android Jelly Bean 4.2\nbrowser.known?          # has the browser been successfully detected?\nbrowser.meta            # an array with several attributes\nbrowser.to_s            # the meta info joined by space\n```\n\nSee the [tests](https://github.com/dirk/browser2/blob/master/test/browser_test.rb) and [implementation](https://github.com/dirk/browser2/blob/master/lib/browser.rb) for more examples.\n\n### Integrations\n\nBrowser comes out-of-the-box with helpers for use in Ruby on Rails applications and Rack servers. See [`doc/rails_and_rack.md`](doc/rails_and_rack.md) for more details.\n\n### What defines a modern browser?\n\nThe current rules that define a modern browser are pretty loose:\n\n* Webkit\n* IE9+\n* Microsoft Edge\n* Firefox 17+\n* Firefox Tablet 14+\n* Opera 12+\n\nYou can define your own rules. A rule must be a proc/lambda or any object that implements the method === and accepts the browser object. To redefine all rules, clear the existing rules before adding your own.\n\n```ruby\n# Only Chrome Canary is considered modern.\nBrowser.modern_rules.clear\nBrowser.modern_rules \u003c\u003c -\u003e b { b.chrome? \u0026\u0026 b.version.to_i \u003e= 37 }\n```\n\n### Internet Explorer\n\nInternet Explorer has a compatibility view mode that allows newer versions (IE8+) to run as an older version. Browser will always return the navigator version, ignoring the compatibility view version, when defined. If you need to get the engine's version, you have to use `Browser#msie_version` and `Browser#msie_full_version`.\n\nSo, let's say an user activates compatibility view in a IE11 browser. This is what you'll get:\n\n```ruby\nbrowser.version\n#=\u003e 11\n\nbrowser.full_version\n#=\u003e 11.0\n\nbrowser.msie_version\n#=\u003e 7\n\nbrowser.msie_full_version\n#=\u003e 7.0\n\nbrowser.compatibility_view?\n#=\u003e true\n\nbrowser.modern?\n#=\u003e false\n```\n\nThis behavior changed in `v1.0.0`; previously there wasn't a way of getting the real browser version.\n\n### Bots\n\nBrowser used to detect empty user agents as bots, but this behavior has changed. If you want to bring this detection back, you can activate it through the following call:\n\n```ruby\nBrowser::Bots.detect_empty_ua!\n```\n\n## Authors\n\n* [Dirk Gadsden](https://dirk.to) (`browser2` maintainer)\n* [Nando Vieira](http://nandovieira.com.br) (original author of `browser`)\n\n## License\n\nLicensed under the MIT license. See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirk%2Fbrowser2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdirk%2Fbrowser2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirk%2Fbrowser2/lists"}