{"id":20235702,"url":"https://github.com/browserslist/browserslist-useragent-ruby","last_synced_at":"2025-06-19T01:40:21.565Z","repository":{"id":43694929,"uuid":"131245543","full_name":"browserslist/browserslist-useragent-ruby","owner":"browserslist","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-22T07:37:24.000Z","size":58,"stargazers_count":29,"open_issues_count":7,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-06T15:52:18.596Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/browserslist.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2018-04-27T04:29:09.000Z","updated_at":"2023-10-09T08:48:39.000Z","dependencies_parsed_at":"2025-04-10T18:54:57.555Z","dependency_job_id":"ba735459-a25c-4bb0-bf2f-6d2a3dd73d05","html_url":"https://github.com/browserslist/browserslist-useragent-ruby","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/browserslist/browserslist-useragent-ruby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/browserslist%2Fbrowserslist-useragent-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/browserslist%2Fbrowserslist-useragent-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/browserslist%2Fbrowserslist-useragent-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/browserslist%2Fbrowserslist-useragent-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/browserslist","download_url":"https://codeload.github.com/browserslist/browserslist-useragent-ruby/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/browserslist%2Fbrowserslist-useragent-ruby/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260665356,"owners_count":23044277,"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-14T08:17:21.934Z","updated_at":"2025-06-19T01:40:16.547Z","avatar_url":"https://github.com/browserslist.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# browserslist_useragent gem\n[![Gem Version](https://badge.fury.io/rb/browserslist_useragent.svg)](https://badge.fury.io/rb/browserslist_useragent)\n[![Build Status](https://travis-ci.org/browserslist/browserslist-useragent-ruby.svg?branch=master)](https://travis-ci.org/browserslist/browserslist-useragent-ruby)\n\n\u003cimg align=\"right\" width=\"120\" height=\"120\"\n  src=\"https://cdn.rawgit.com/pastelsky/browserslist-useragent/master/logo.svg\" alt=\"Browserslist Useragent logo (original by Anton Lovchikov)\" /\u003e\n\nFind if a given user agent string satisfies a [Browserslist](https://github.com/ai/browserslist) browsers.\n\n[Browserslist](https://github.com/browserslist/browserslist) is a popular config in many front-end tools like [Autoprefixer](https://github.com/postcss/autoprefixer) or [Babel](https://github.com/babel/babel/tree/master/packages/babel-preset-env). This gem allow you to use this config in Ruby project to check user agent string and, for examplle, show “Your browsers is outdated” warning for user with old browser.\n\n## Usage\n\n### 1. Setup Browserslist\n\nRun in webpack directory to install `browserslist` npm package:\n\n```sh\nnpm install --save-dev browserslist\n```\n\nAdd the following lines to your webpack config to generate the `browsers.json`file during build step:\n\n```javascript\nconst browserslist = require('browserslist')\nconst fs = require('fs')\n\nfs.writeFileSync('./browsers.json', JSON.stringify(browserslist()))\n```\n\nIn a Rails/Webpacker environment add the above lines to the top of your `app/config/webpack/environment.js` file.\n\nAdd `browsers.json` file to `.gitignore`.\n\n### 2. Install gem\n\nAdd this line to `Gemfile`\n\n```ruby\ngem 'browserslist_useragent'\n```\n\nRun `bundle install`.\n\n### 3. Add helper\n\nDefine new helper in `app/helpers/application_helper.rb`:\n\n```ruby\ndef supported_browser?\n  @browsers ||= JSON.parse(File.read(PATH_TO_BROWSERS_JSON))\n  matcher = BrowserslistUseragent::Match.new(@browsers, request.user_agent)\n  matcher.browser? \u0026\u0026 matcher.version?(allow_higher: true)\nend\n```\n\n### 4. Use helper in template\n\nPut a warning message for users with an unsupported browser in `app/views/layouts/_unsupported_browser_warning` and add this check in application layout:\n\n```haml\nbody\n  - if !supported_browser?\n    render 'layouts/unsupported_browser_warning'\n```\n\n### Separated projects\n\nIf you have separated projects for Ruby backend and Node.js frontend, you will prefer to get `browsers.json` over HTTP.\n\n```javascript\nfs.writeFileSync(\n  path.join(__dirname, 'public', 'browsers.json'),\n  JSON.stringify(browserslist(undefined, { path: path.join(__dirname, '..') }))\n)\n```\n\nGets `browserslist.json` over HTTP (with caching) once (per web application instance) and use it to match user agent for every request:\n\n```ruby\n# caches http response locally with etag\nhttp_client = Faraday.new do |builder|\n  builder.use Faraday::HttpCache, store: Rails.cache\n  builder.adapter Faraday.default_adapter\nend\n\n@browsers = JSON.parse(\n  http_client.get(FRONTEND_HOST + '/browsers.json').body\n)\n```\n\n## API\n`BrowserslistUseragent::Match` is the main class performing matching user agent string to browserslist.\n\nIt provides 2 methods:\n - `version?(allow_higher: false)` - determines matching browser and it's version\n - `browser?` - determines matching only browser family\n\n```ruby\nrequire 'browserslist_useragent'\n\nmatcher = BrowserslistUseragent::Match.new(\n  ['Firefox 53'],\n  'Mozilla/5.0 (Windows NT 10.0; rv:54.0) Gecko/20100101 Firefox/53.0'\n)\nmatcher.browser? # returns true\nmatcher.version? # return true\n\nmatcher = BrowserslistUseragent::Match.new(\n  ['Firefox 54'],\n  'Mozilla/5.0 (Windows NT 10.0; rv:54.0) Gecko/20100101 Firefox/53.0'\n)\nmatcher.browser? # returns true\nmatcher.version? # return false\n```\n\n## Supported browsers\n\nChrome, Firefox, Safari, IE, Edge\n \nPRs to add more _browserslist supported_ browsers are welcome 👋\n\n## Notes\n\n* All browsers on iOS (Chrome, Firefox etc) use Safari's WebKit as the underlying engine, and hence will be resolved to Safari. Since `browserslist` is usually used for\n  transpiling / autoprefixing for browsers, this behaviour is what's intended in most cases, but might surprise you otherwise.\n* Right now, Chrome for Android and Firefox for Android are resolved to their desktop equivalents. The `caniuse` database does not currently store historical data for these browsers separately (except the last version) See [#156](https://github.com/ai/browserslist/issues/156)\n\n## Development (with Docker))))\n\nAfter checking out the repo, run:\n\n```bash\ndocker-compose run app bundle install\n```\n\nRun tests with:\n\n```bash\ndocker-compose run app bundle exec rspec\n```\n\nRun RuboCop with:\n\n```bash\ndocker-compose run app bundle exec rubocop\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/browserslist-useragent-ruby.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrowserslist%2Fbrowserslist-useragent-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrowserslist%2Fbrowserslist-useragent-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrowserslist%2Fbrowserslist-useragent-ruby/lists"}