bowser vs ua-parser-js vs platform
ユーザーエージェント解析ライブラリ
bowserua-parser-jsplatform類似パッケージ:
ユーザーエージェント解析ライブラリ

ユーザーエージェント解析ライブラリは、ブラウザやデバイスの情報を解析し、特定の機能や特性を特定するために使用されます。これにより、開発者は異なる環境でのアプリケーションの動作を最適化し、ユーザーに対してより良い体験を提供することができます。これらのライブラリは、特にレスポンシブデザインやクロスブラウザ互換性を考慮する際に重要です。

npmのダウンロードトレンド
3 年
GitHub Starsランキング
統計詳細
パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
bowser23,296,3245,683252 kB10114日前MIT
ua-parser-js20,709,7109,9731.29 MB234日前AGPL-3.0-or-later
platform2,486,2423,241-345年前MIT
機能比較: bowser vs ua-parser-js vs platform

ブラウザ検出

  • bowser:

    Bowserは、ブラウザの名前、バージョン、エンジンを簡単に検出できる機能を提供します。特に、特定のブラウザに対して異なるコードパスを実装する際に便利です。

  • ua-parser-js:

    ua-parser-jsは、ブラウザの詳細な情報を提供し、特にバージョンやエンジンの情報を正確に取得できます。複雑なユーザーエージェント文字列を解析する際に非常に役立ちます。

  • platform:

    Platformは、ブラウザの基本情報を提供しますが、Bowserほど詳細ではありません。主にプラットフォームの識別に重点を置いています。

デバイス検出

  • bowser:

    Bowserは、デバイスの種類(モバイル、タブレット、デスクトップ)を簡単に特定でき、特定のデバイスに対して異なるスタイルや機能を提供する際に役立ちます。

  • ua-parser-js:

    ua-parser-jsは、デバイスの詳細な情報を提供し、特にOSやデバイスモデルに関する情報を深く理解するのに役立ちます。

  • platform:

    Platformは、デバイスの種類を特定するためのシンプルな機能を提供しますが、詳細な情報は提供しません。主にデバイスの基本的な特性を知りたい場合に適しています。

カスタマイズ性

  • bowser:

    Bowserは、必要に応じてカスタマイズ可能で、特定のブラウザやデバイスに合わせた機能を追加することができます。

  • ua-parser-js:

    ua-parser-jsは、非常に柔軟で、独自の解析ルールを追加することができるため、特定のニーズに応じたカスタマイズが可能です。

  • platform:

    Platformは、シンプルさを重視しているため、カスタマイズ性は限られていますが、基本的な情報を迅速に取得するのに適しています。

パフォーマンス

  • bowser:

    Bowserは軽量で、高速なパフォーマンスを提供します。特に、ブラウザの情報を迅速に取得したい場合に最適です。

  • ua-parser-js:

    ua-parser-jsは、詳細な解析を行うため、他のライブラリに比べて若干のオーバーヘッドがありますが、その分、豊富な情報を提供します。

  • platform:

    Platformは、シンプルな設計により、パフォーマンスが良好ですが、詳細な情報を必要とする場合には制限があります。

使用シナリオ

  • bowser:

    Bowserは、特定のブラウザ機能に依存したコードを実装する際に最適です。特に、古いブラウザへの対応が必要な場合に役立ちます。

  • ua-parser-js:

    ua-parser-jsは、詳細なユーザーエージェント情報が必要な場合に最適で、特にデバイスやブラウザの特性を深く理解する必要がある場合に役立ちます。

  • platform:

    Platformは、デバイスの種類に基づいて異なるコンテンツを表示したい場合に適しています。特に、モバイルファーストのアプローチを取る際に便利です。

選び方: bowser vs ua-parser-js vs platform
  • bowser:

    Bowserは、軽量で使いやすいライブラリで、特にブラウザのバージョンや機能を簡単に特定したい場合に最適です。特定のブラウザに依存した機能を実装する必要がある場合に選択してください。

  • ua-parser-js:

    ua-parser-jsは、非常に詳細なユーザーエージェント解析を提供するライブラリで、特定のデバイスやブラウザの特性を深く理解したい場合に最適です。多くの情報を必要とする場合や、カスタマイズされた解析が必要な場合に選択してください。

  • platform:

    Platformは、プラットフォーム情報を簡単に取得できるライブラリで、デバイスの種類やOSに基づいて異なる処理を行いたい場合に適しています。特に、デスクトップとモバイルの区別が重要な場合に選択してください。

bowser のREADME

Bowser

A small, fast and rich-API browser/platform/engine detector for both browser and node.

  • Small. Use plain ES5-version which is ~4.8kB gzipped.
  • Optimized. Use only those parsers you need — it doesn't do useless work.
  • Multi-platform. It's browser- and node-ready, so you can use it in any environment.

Don't hesitate to support the project on Github or OpenCollective if you like it ❤️ Also, contributors are always welcome!

Financial Contributors on Open Collective Build Status Greenkeeper badge Coverage Status Downloads

Contents

Overview

The library is made to help to detect what browser your user has and gives you a convenient API to filter the users somehow depending on their browsers. Check it out on this page: https://bowser-js.github.io/bowser-online/.

⚠️ Version 2.0 breaking changes ⚠️

Version 2.0 has drastically changed the API. All available methods are on the docs page.

For legacy code, check out the 1.x branch and install it through npm install bowser@1.9.4.

Use cases

First of all, require the library. This is a UMD Module, so it will work for AMD, TypeScript, ES6, and CommonJS module systems.

const Bowser = require("bowser"); // CommonJS

import * as Bowser from "bowser"; // TypeScript

import Bowser from "bowser"; // ES6 (and TypeScript with --esModuleInterop enabled)

By default, the exported version is the ES5 transpiled version, which do not include any polyfills.

In case you don't use your own babel-polyfill you may need to have pre-built bundle with all needed polyfills. So, for you it's suitable to require bowser like this: require('bowser/bundled'). As the result, you get a ES5 version of bowser with babel-polyfill bundled together.

You may need to use the source files, so they will be available in the package as well.

Browser props detection

Often we need to pick users' browser properties such as the name, the version, the rendering engine and so on. Here is an example how to do it with Bowser:

const browser = Bowser.getParser(window.navigator.userAgent);

console.log(`The current browser name is "${browser.getBrowserName()}"`);
// The current browser name is "Internet Explorer"

or

const browser = Bowser.getParser(window.navigator.userAgent);
console.log(browser.getBrowser());

// outputs
{
  name: "Internet Explorer"
  version: "11.0"
}

or

console.log(Bowser.parse(window.navigator.userAgent));

// outputs
{
  browser: {
    name: "Internet Explorer"
    version: "11.0"
  },
  os: {
    name: "Windows"
    version: "NT 6.3"
    versionName: "8.1"
  },
  platform: {
    type: "desktop"
  },
  engine: {
    name: "Trident"
    version: "7.0"
  }
}

Filtering browsers

You could want to filter some particular browsers to provide any special support for them or make any workarounds. It could look like this:

const browser = Bowser.getParser(window.navigator.userAgent);
const isValidBrowser = browser.satisfies({
  // declare browsers per OS
  windows: {
    "internet explorer": ">10",
  },
  macos: {
    safari: ">10.1"
  },

  // per platform (mobile, desktop or tablet)
  mobile: {
    safari: '>=9',
    'android browser': '>3.10'
  },

  // or in general
  chrome: "~20.1.1432",
  firefox: ">31",
  opera: ">=22",

  // also supports equality operator
  chrome: "=20.1.1432", // will match particular build only

  // and loose-equality operator
  chrome: "~20",        // will match any 20.* sub-version
  chrome: "~20.1"       // will match any 20.1.* sub-version (20.1.19 as well as 20.1.12.42-alpha.1)
});

Settings for any particular OS or platform has more priority and redefines settings of standalone browsers. Thus, you can define OS or platform specific rules and they will have more priority in the end.

More of API and possibilities you will find in the docs folder.

Browser names for .satisfies()

By default you are supposed to use the full browser name for .satisfies. But, there's a short way to define a browser using short aliases. The full list of aliases can be found in the file.

Similar Projects

  • Kong - A C# port of Bowser.

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

Licensed as MIT. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.