Giter Club home page Giter Club logo

egjs-agent's Introduction

egjs-agent

npm version Build Status Coverage Status Support TypeScript

Extracts browser and operating system information from the user agent string or user agent object(userAgentData).

Documents

Download and Installation

Download dist files from repo directly or install it via npm.

Installation with npm

The following command shows how to install egjs-agent using npm.

$ npm install @egjs/agent

For development

You can download the files for development

Prepare for Client Hints and User-Agent Reduction!

Chrome was planned to freeze userAgent to improve user privacy, and it is being applied as an experimental feature in 84+.

Not only Chrome, but other browsers will come someday.

It is still an experimental feature until Chrome(Chromium) 86.

If you want to test, enable the flag below.

chrome://flags/#enable-experimental-web-platform-features chrome://flags/#freeze-user-agent

This reduced format will be available for testing via chrome://flags/#reduce-user-agent in Chrome 93. chrome://flags/#reduce-user-agent

User-Agent Reduction Proposed Rollout Plan

Phase 4: Chrome 101 Ship reduced Chrome MINOR.BUILD.PATCH version numbers (“0.0.0”). Once rolled-out, the reduced UA string would apply to all page loads on desktop and mobile OSes that do not opt into the reverse Origin Trial.

Phase 5: Chrome 107 Begin roll-out of reduced Desktop UA string and related JS APIs (navigator.userAgent, navigator.appVersion, navigator.platform). Once rolled-out, the reduced UA string would apply to all page loads on desktop OSes that do not opt into the reverse Origin Trial.

Phase 6: Chrome 110 Begin roll-out of reduced Android Mobile (and Tablet) UA string and related JS APIs. Once rolled-out, the reduced UA string would apply to all page loads on Android that do not opt into the reverse Origin Trial.

Reduction Completion Phase 7: Chrome 113 reverse Origin Trial ends and all page loads receive the reduced UA string and related JS APIs.

In the future

  1. the following attribute values will not appear correctly.
    • navigator.userAgent
    • navigator.appVersion
    • navigator.platform
    • navigator.productSub
    • navigator.vendor
  2. You should use navigator.userAgentData instead of navigator.userAgent.
    • Browser version only shows major.
    • OS name, OS version, Browser full version should be fetched asynchronously.
    • The only OS name that you can check synchronously are iOS and Android.

Possible (You can know exactly)

  • Check browser name, major version
  • Check the full version under Chrome 101
  • Check mobile
  • Check OS name
  • Check Webkit, Chromium
  • Check old OS, OS Version (Chrome 84 support range or less)
    • < Android 5.0
    • < Mac OS X 10.10
    • < Windows 7
    • < iOS Unknown
import getAgent from "@egjs/agent";

const agent = getAgent();

// Check iOS
agent.os.name === "ios"
agent.os.majorVersion === 9
// Check Android
agent.os.name === "android"
agent.os.majorVersion === 4
parseFloat(agent.os.version) <= 4.4
// Check browser name
agent.browser.name === "safari"
// Check webkit
agent.browser.webkit
// Check chromium
agent.browser.chromium

If you want to use only the method using navigator.userAgent

import { getLegacyAgent } from "@egjs/agent";

const agent = getLegacyAgent();
// Check iOS
agent.os.name === "ios"
agent.os.majorVersion === 9
// Check Android
agent.os.name === "android"
agent.os.majorVersion === 4
parseFloat(agent.os.version) <= 4.4
// Check browser name
agent.browser.name === "safari"
// Check webkit
agent.browser.webkit
// Check chromium
agent.browser.chromium

Not Possible (If synchronous)

  • Check OS version.
  • Check Browser full version.
import getAgent from "@egjs/agent";
const agent = getAgent();

// If the full version is 10.5, it is displayed as 10.
agent.browser.version
// "unknown"
agent.os.name
// -1
agent.os.majorVersion

Possible (If asynchronous)

  • You can get accurate agent information.
  • Check OS version.
  • Check Browser full version.
import { getAccurateAgent } from "@egjs/agent";

// Use Promise
getAccurateAgent().then(agent => {
    // Check OS version
    agent.os.version

    // Check Browser full verion
    agent.browser.version
});

// Use Callback
getAccurateAgent(agent => {});

If you dare to use synchrous, you have to choose.

  • If you're checking a version (ex. 93.0.1234.56) lower than Chrome 101 to fix the bug, there shouldn't be a problem.
  • However, if you need to check the minor or patch version of version 101 or higher, you have to check it asynchronously.
  • You can check the OS name, but if you want to check the OS version, consider switching to asynchronous before reduction is applied.

Supported Browsers

The following are the supported browsers.

Internet Explorer Chrome Firefox Safari iOS Android
7+ latest latest latest 3+ 2.1+

Client Hints Support

Chromium (Chrome, Edge, Whale) Gecko (Firefox) Webkit (Safari)
84+ (Experimental) Unknown Unknown

How to start developing egjs-agent?

For anyone interested to develop egjs-agent, follow the instructions below.

Development Environment

1. Clone the repository

Clone the egjs-agent repository and install the dependency modules.

# Clone the repository.
$ git clone https://github.com/naver/egjs-agent.git

2. Install dependencies

npm is supported.

# Install the dependency modules.
$ npm install

3. Build

Use npm script to build eg.agent

# Run rollup
$ npm start

# Build
$ npm run build

# Generate jsdoc
$ npm run jsdoc

Two folders will be created after complete build is completed.

  • dist folder: Includes the agent.js and agent.min.js files.
  • doc folder: Includes API documentation. The home page for the documentation is doc/index.html.

Linting

To keep the same code style, we adopted ESLint to maintain our code quality. Setup your editor for check or run below command for linting.

$ npm run lint

Test

Once you created a branch and done with development, you must perform a test running npm run test command before you push code to a remote repository.

$ npm run test

Running a npm run test command will start Jest.

Bug Report

If you find a bug, please report it to us using the Issues page on GitHub.

License

egjs-agent is released under the MIT license.

Copyright (c) 2015 NAVER Corp.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

egjs-agent's People

Contributors

arkist avatar daybrush avatar happyhj avatar jsong0605 avatar ledgku avatar malangfox avatar sculove avatar taejs avatar tienne avatar woodneck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

egjs-agent's Issues

Incorrect OS name window

Description

os.name return 'window', but it should be 'windows'

Steps to check or reproduce

os.name return 'window'

supports samsung devices

Mozilla/5.0 (Linux; Tizen 2.3; FamilyHub) AppleWebKit/537.3 (KHTML, like Gecko) Version/2.3 Mobile Safari/537.3
Mozilla/5.0 (Linux; Tizen 3.0; FamilyHub) AppleWebKit/537.3 (KHTML, like Gecko) Version/2.3 Mobile Safari/537.3

Support Client Hints

Prepare for Client Hints!

Chrome is currently planning to freeze user agents to improve user privacy.

Not only Chrome, but other browsers will come someday.

It is still an experimental feature until Chrome(Chromium) 86.

If you want to test, enable the flag below.

chrome://flags/#enable-experimental-web-platform-features

chrome://flags/#freeze-user-agent

In Chrome (Chrome 87, Mac, Freeze User-Agent)

  • Before
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4243.0 Safari/537.36
  • After
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.0.0 Safari/537.36

In the future

  1. the following attribute values will not appear correctly.
    • navigator.userAgent
    • navigator.appVersion
    • navigator.platform
    • navigator.productSub
    • navigator.vendor
  2. You should use navigator.userAgentData instead of navigator.userAgent.
    • Browser version only shows major.
    • OS name, OS version, Browser full version should be fetched asynchronously.
    • The only OS name that you can check synchronously are iOS and Android.

Possible (You can know exactly)

  • Check browser name, major version
  • Check mobile
  • Check iOS, Android
  • Check Webkit, Chromium
  • Check old OS, OS Version (Chrome 84 support range or less)
    • < Android 5.0
    • < Mac OS X 10.10
    • < Windows 7
    • < iOS Unknown
import getAgent from "@egjs/agent";

const agent = getAgent();

// Check iOS
agent.os.name === "ios"
agent.os.majorVersion === 9
// Check Android
agent.os.name === "android"
agent.os.majorVersion === 4
parseFloat(agent.os.version) <= 4.4
// Check browser name
agent.browser.name === "safari"
// Check webkit
agent.browser.webkit
// Check chromium
agent.browser.chromium

Not Possible (If synchronous)

  • Check OS (Mac with browsers except Safari, Windows, Linux), OS version
  • Check Browser full version.
import getAgent from "@egjs/agent";
const agent = getAgent();

// If the full version is 10.5, it is displayed as 10.
agent.browser.version
// "unknown"
agent.os.name
// -1
agent.os.majorVersion

Possible (If asynchronous)

  • You can get accurate agent information.
  • Check OS(Mac, Windows, Linux), OS version
  • Check Browser full version.
import { getAccurateAgent } from "@egjs/agent";

// Use Promise
getAccurateAgent().then(agent => {
    // Check OS, OS version
    agent.os.name
    agent.os.version

    // Check Browser full verion
    agent.browser.version
});

// Use Callback
getAccurateAgent(agent => {});

If you dare to use synchrous, you have to choose.

  • You cannot get the OS name and version other than iOS, Android.
  • You can only get the major version of the browser. However, unless there is a serious bug, you will mainly check the major version.
  • Instead, infer to browser, Webkit, or Chromium.

속성값중 webkit,chromium 에 대한 설명을 알고 싶습니다.

var browserWebkit = $(".browser > .webkit")[0];
var browserChromium = $(".browser > .chromium")[0];

에서 WEBKIT이 뜻하는 것이 무엇일까요?

크롬 테스트 해보니 FALSE가 나오고 삼성 인터넷 브라우저를 보니 true가 뜨는데

삼성 인터넷과 크롬 브라우저가 실제 html태그중 동작 하는 것과 하지 않는 것 이있는 것 같아서요.

위의 속성값이 무엇을 뜻하는지 알고 싶습니다.

겔럭시 폴드 2

삼성 브라우저에서는 모바일로 잘 뜨는데
크롬이나 카카오 인앱 브라우저에서 PC로 인식하네요..

ipad / ios 14버전

Description

iPad에서 os13 이상 인 경우 일부 사용자 들에게 user-agent 에 iPad 문자열이 빠지며 맥북 사용자와 동일한 user-agent 로 표기 되고 있는데 이를 모바일로 인식하기 위해서는 별도 구분값이 있을까요?

Steps to check or reproduce

detect InApp Browser

Need additional detecting of popular in-app browsers

  • naver app(must!!)
  • cacaotalk
  • facebook
  • facebook messanger
  • line

Breaks on IE8

The code contains Array.prototype.some, Array.prototype.forEach, Array.prototype.filter which IE8 not supports. So should add polyfill for those methods.

I would like to know the version of webkit or chromium.

Description

I would like to know the version of webkit or chromium.

I know whether it is webkit or chromium, but I don't know the version information. I would like to know the version of these two engines.

Steps to check or reproduce

'uaFullVersion' is being replaced by 'fullVersionList'

Description

안녕하세요.
MDN Client Hints 문서를 보던 중 Sec-CH-UA-Full-Version(uaFullVersion)이 Deprecated 된 것을 알게 되었습니다.
문서 내용에 따라 Sec-CH-UA-Full-Version-List(fullVersionList)으로 변경이 필요할 것 같습니다.

Steps to check or reproduce

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.