Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@egjs/agent
Advanced tools
Extracts browser and operating system information from the user agent string or user agent object(userAgentData).
@egjs/agent is a JavaScript library that provides detailed information about the user's environment, including the browser, operating system, and device. It helps developers tailor their applications based on the user's environment.
Detect Browser Information
This feature allows you to detect the browser information of the user, such as the name and version of the browser.
const agent = new eg.Agent();
console.log(agent.browser);
Detect OS Information
This feature allows you to detect the operating system information of the user, including the name and version of the OS.
const agent = new eg.Agent();
console.log(agent.os);
Detect Device Information
This feature allows you to detect the device information of the user, such as whether the device is a mobile, tablet, or desktop.
const agent = new eg.Agent();
console.log(agent.device);
ua-parser-js is a JavaScript library that parses User-Agent strings to identify the browser, engine, OS, CPU, and device type/model. It provides similar functionalities to @egjs/agent but with a focus on parsing the User-Agent string.
platform is a JavaScript library that provides information about the platform (operating system, browser, and device) on which the code is running. It offers similar capabilities to @egjs/agent but with a different API and additional details about the platform.
bowser is a JavaScript library that detects the browser and its version, as well as the operating system and its version. It is similar to @egjs/agent but focuses more on browser detection and compatibility.
Extracts browser and operating system information from the user agent string or user agent object(userAgentData).
Download dist files from repo directly or install it via npm.
The following command shows how to install egjs-agent using npm.
$ npm install @egjs/agent
You can download the files for development
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
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.
navigator.userAgentData
instead of navigator.userAgent
.
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
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
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
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 => {});
The following are the supported browsers.
Internet Explorer | Chrome | Firefox | Safari | iOS | Android |
---|---|---|---|---|---|
7+ | latest | latest | latest | 3+ | 2.1+ |
Chromium (Chrome, Edge, Whale) | Gecko (Firefox) | Webkit (Safari) |
---|---|---|
84+ (Experimental) | Unknown | Unknown |
For anyone interested to develop egjs-agent, follow the instructions below.
Clone the egjs-agent repository and install the dependency modules.
# Clone the repository.
$ git clone https://github.com/naver/egjs-agent.git
npm
is supported.
# Install the dependency modules.
$ npm install
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.
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
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.
If you find a bug, please report it to us using the Issues page on GitHub.
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.
FAQs
Extracts browser and operating system information from the user agent string or user agent object(userAgentData).
The npm package @egjs/agent receives a total of 96,562 weekly downloads. As such, @egjs/agent popularity was classified as popular.
We found that @egjs/agent demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 10 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.