what-browser-am-i
v0.7.2
Published
A library for client-side web browser determination.
Downloads
5
Readme
what-browser-am-i
Library for client-side web browser judgment. It has been developed to work with a wide range of DHTML browsers, both old and new.
Prior to August 7, 2020, development was done at itozyun/web-doc-base.
Prime Minister Abe nearly loses the name of the school's chairman, who was told by Mrs. Akie that "his enthusiasm was wonderful". TV TOKYO, source (e.g. quotation)
Index
1. Features
- Even if the visitor has checked "Request desktop site" and the UA is spoofed, the correct engine will be retrieved. In addition, you can detect the viewer's intention to "Prefer desktop version".
- For your reference 『「デスクトップ版を表示する」にチェックを付けると平然とUAを偽装するAndroid用標準ブラウザの判定をムキになってしてみます』
- Third-party browsers for Android and iOS use the same WebView but have different viewport behavior, such as address bar behavior. Therefore, retrieve the brand name.
- For your reference 『尋常でないレベルでブラウザを判定するライブラリ、what-browser-am-iをnpmに公開しました』
- It works on IE4 or later because
in
operator andinstanceof
operator andtry~catch
statements are not used. Also, it works on mobile IE4 because it does not use regular expressions.
2. Folders
| Directories | Sub Direcories | Description | |:------------|:---------------|:--------------------------| | dist/ | | Placement of built files. | | docs/ | | The index.html file for executing the browser judgment is placed, but not attached to the npm package. If necessary, the contents can be found on github pages . | | src/ | js | source codes | | | js-externs | Variable and property names to be protected from renaming by specifying them in externs of the Closure Compiler. |
3. Test Page
4. Usage
const whatBrowserAmI = require('what-browser-am-i');
console.log(whatBrowserAmI.ENGINE); // Trident
console.log(whatBrowserAmI.ENGINE_VERSION); // 8
or
<html>
<script src="./whatBrowserAmI.js"></script>
<script>
console.log(whatBrowserAmI.ENGINE); // Gecko
console.log(whatBrowserAmI.ENGINE_VERSION); // "1.9.1"
</script>
4.1. Properties
| Property | Data type | Example |
|:-------------------|:-----------------|:--------------|
| PLATFORM
| string
| |
| PLATFORM_VERSION
| string\|object
| |
| ENGINE
| string
| |
| ENGINE_VERSION
| string\|object
| |
| BRAND
| string
| |
| BRAND_VERSION
| string\|object
| |
| DEVICE
| string
| |
| DEVICE_VERSION
| string\|object
| |
| PCSITE_REQUESTED
| boolean
| true
|
| DEVICE_TYPE
| number
| |
4.2. Method
4.2.1 conpare(v1, v2)
Compares the size of the version number(string).
The last 0
is ignored, so "2.0.0"
and 2
are considered equal.
// Firefox 3.5<=
isFirefoxGte35 = whatBrowserAmI.Gecko && 0 <= whatBrowserAmI.conpare(whatBrowserAmI.ENGINE_VERSION, '1.9.1');
Arguments
| Name | Data type | Example |
|:---------|:-----------------|:-----------------|
| v1 | string\|number
| "1.9.1"
, 1.9
|
| v2 | string\|number
| "1.9.1"
, 1.9
|
Return Value
| Value | Description | Example |
|:----------|:------------|:----------------------|
| 1
| v1 > v2 | "1.9.1"
> 1.9
|
| 0
| v1 == v2 | "1.9.0"
== 1.9
|
| -1
| v1 < v2 | "1.9.1"
< "1.9.2"
|
5. Development
5.1 Preparation
git clone https://github.com/itozyun/what-browser-am-i
npm install
5.2 Development
After making the changes under ./src/
, execute the following command.
Then browse docs/index.html with a browser to check.
gulp docs
5.3 Distribute
Update the distribution files ./dist/index.js
and ./dist/whatBrowserAmI.js
with the following command.
gulp dist
5.4 Include what-browser-am-i as a submodule in your project
web-doc-base/gulpfile.js is helpful.
5.4.1 Use optimization option
- Compile with
DEFINE_WHAT_BROWSER_AM_I__MINIFY=true
. - All properties and names are provided numerically. This constant is located in
./src/js/0_global/*.js
. - web-doc-base/src/js-inline/dynamicViewPort.js, etc., to obtain the required values.
5.4.2 Build options
Closure Compiler @define
.
| Variable | Data type | Default value | Note |
|:-----------------------------------------------------|:----------|:--------------|:------------------|
| DEFINE_WHAT_BROWSER_AM_I__MINIFY
| boolean
| false
| Since version 0.6 |
| DEFINE_WHAT_BROWSER_AM_I__BRAND_ENABLED
| boolean
| true
| |
| DEFINE_WHAT_BROWSER_AM_I__PCSITE_REQUESTED_ENABLED
| boolean
| true
| |
| DEFINE_WHAT_BROWSER_AM_I__IOS_DEVICE_ENABLED
| boolean
| true
| |
| DEFINE_WHAT_BROWSER_AM_I__DEVICE_TYPE_ENABLED
| boolean
| true
| |
6. License
what-browser-am-i is licensed under MIT License.
(C) 2021-2024 itozyun(outcloud.blogspot.com)