# @egjs/agent 中文文档

规范地址：https://npmcn.com/package/%40egjs/agent/

版本：2\.4\.4
npm 元数据更新时间：2025-10-24T06:49:46.078Z
中文译文更新时间：2026-11-13T09:06:57.363Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40egjs/agent
原文对照：https://npmcn.com/package/%40egjs/agent/?lang=original
项目主页：https://github.com/naver/egjs-agent#readme
源码仓库：https://github.com/naver/egjs-agent

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：177 kB，33 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2017-04-28T02:13:51.758Z
- 最新版本发布：2024-08-23T05:40:18.207Z
- 近 30 天下载量：3106093（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：20（近 12 个月 0 个）

## 中文简介

从用户代理字符串或用户代理对象(userAgentData)中提取浏览器和操作系统信息.

## 安装

```sh
npm install @egjs/agent
```

也可以使用：`pnpm add @egjs/agent`、`yarn add @egjs/agent`、`bun add @egjs/agent`

## README

# 格吉斯 - 代理人

[![npm version](https://img.shields.io/npm/v/@egjs/agent.svg?style=flat-square&color=007acc&label=version)](https://www.npmjs.com/package/@egjs/agent) [![Build Status](https://img.shields.io/travis/naver/egjs-agent.svg?style=flat-square&label=build)](https://travis-ci.org/naver/egjs-agent) [![Coverage Status](https://img.shields.io/coveralls/github/naver/egjs-agent.svg?style=flat-square&label=coverage)](https://coveralls.io/github/naver/egjs-agent?branch=master) ![Support TypeScript](https://img.shields.io/static/v1.svg?label=&message=TypeScript&color=294E80&style=flat-square&logo=typescript)

从用户代理字符串或用户代理对象(userAgentData)中提取浏览器和操作系统信息.

## 文档

-   [启动和演示](https://naver.github.io/egjs-agent/)
-   [API 文档](https://naver.github.io/egjs-agent/release/latest/doc/)
-   [准备客户端提示, 冻结用户代理](https://medium.com/naver-fe-platform/prepare-for-client-hints-freezing-user-agent-9c0ea1ddd02c)

## 下载和安装

从 repo 直接下载 dist 文件或通过 npm 安装它 .

### 安装 npm

以下命令显示如何使用 npm 安装 egjs- agent .

```bash
$ npm install @egjs/agent
```

### 促进发展

您可以下载文件进行开发

-   最新报告: [https://naver.github.io/egjs-agent/release/latest/dist/agent.js 页面存档备份,存于互联网档案馆](https://naver.github.io/egjs-agent/release/latest/dist/agent.js)
-   最近( 分钟) : [https://naver.github.io/egjs-agent/release/latest/dist/agent.min.js 互联网档案馆的存檔,存档日期2014-12-21](https://naver.github.io/egjs-agent/release/latest/dist/agent.min.js)
-   具体版本:https://naver.github.io/egjs-agent/release/\[VERSION\]/dist/agent.js
-   具体版本(min):https://naver.github.io/egjs-agent/release/\[VERSION\]/dist/agent.min.js 页面存档备份,存于互联网档案馆

## 准备客户提示和用户代理删除!

Chrome原计划冻结用户Agent以改善用户隐私,目前正在作为实验功能被应用到84+.

不仅Chrome,其他浏览器总有一天会来.

> 在Chrome(铬)86之前,它仍然是一个实验特征.
> 
> 如果您想要测试, 请启用下面的旗帜 .
> 
> **chrome://flags/#enable-eximental-web-平台-features (中文(简体) )** **chrome://frags/# freeze-user- agent (英语)**
> 
> 这一被缩减的格式将通过Chrome://flags/#reduce-user-agent在Chrome 93进行测试. **chrome://frags/# 减少用户代理**

### 拟议推出计划

```
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.
```

### 将来

1.  以下属性值将不会正确显示.
    -   导航员.user 代理
    -   导航员.appersion
    -   导航.平台
    -   导航员.产品Sub
    -   导航员. vendor
2.  你应该用 `navigator.userAgentData` 改为 `navigator.userAgent`。 。 。 .
    -   浏览器版本只显示主 .
    -   OS名称,OS版本,浏览器完整版本应同步获取.
    -   可以同步检查的唯一OS名称是iOS和Android.

### 可能(你能够确切知道)

-   检查浏览器名称, 主要版本
-   请检查date=中的日期值 (帮助) Chrome 101下的完整版本
-   检查移动
-   检查操作系统名称
-   请检查date=中的日期值 (帮助) Webkit, Chromium
-   检查旧的 OS, OS 版本( Chrome 84 支持范围或更小)
    -   **< Android 5.0 (英语)**
    -   **< 麦克OS X 10.10**
    -   **< 视窗 7**
    -   **< iOS 未知**

```js
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
```

### 如果您只想要使用 navigator.userAgent 的方法

```js
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
```

### 无法( 如果同步)

-   请检查OS版本.
-   请检查浏览器的完整版本.

```js
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
```

### 可能( 如果同步)

-   你可以得到准确的代理信息.
-   请检查OS版本.
-   请检查浏览器的完整版本.

```js
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 => {});
```

### 如果你敢使用同步, 你必须选择.

-   如果检查一个版本(前93.0.1234.56)低于克罗姆101来修复bug,就不应该有问题.
-   然而,如果需要检查101版本或更高版本的次要或补丁版本,则必须同步检查.
-   您可以检查 OS 名称, 但是如果想要检查 OS 版本, 请在应用还原前考虑切换到同步 .

## 支持的浏览器

以下为所支持的浏览器.

| Internet 浏览器 | 颜色 | 火花 | 萨法里 | iOS系统 | 机器人 |
| --- | --- | --- | --- | --- | --- |
| 7个+ | 最新消息 | 最新消息 | 最新消息 | 3个+ | 2.1 + 数据 |

### 客户提示支持

| 铬(铬、边缘、鲸鱼) | 盖克(火狐) | Webkit (萨法里语) |
| --- | --- | --- |
| 84+ (实验) | 未知 | 未知 |

## 如何开始开发egjs代理?

对于有意开发egjs-agent的人,请遵循以下指示.

### 发展环境

#### 1\. 清除储存库

克隆 egjs 代理寄存器并安装依赖模块.

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

#### 2\. 安装依赖关系

`npm` 被支持.

```
# Install the dependency modules.
$ npm install
```

#### 3\. 建设

使用 npm 脚本构建 eg. agent

```bash
# Run rollup
$ npm start

# Build
$ npm run build

# Generate jsdoc
$ npm run jsdoc
```

完整的构建完成后将创建两个文件夹 .

-   **数字** 文件夹:包括 **探员.js** 财务报告和审定财务报表 **探员.min.js** 文档.
-   **医生** 文件夹:包括 API 文档。 文件的主页是: **文件/索引.html**。 。 。 .

### 线性

为了保持同样的代码风格,我们采用了 [ESLint 语录](http://eslint.org/) 保持我们的代码质量. 设置您的编辑器以检查或运行到命令下方的 Linting .

```bash
$ npm run lint
```

### 测试

一旦您创建了分支并完成了开发, 您就必须进行测试运行 `npm run test` 命令,然后将代码推到远程仓库.

```bash
$ npm run test
```

运行中 `npm run test` 命令将开始 [欢乐](https://jestjs.io/)。 。 。 .

## 错误报告

如果你找到窃听器,请用 [问题](https://github.com/naver/egjs-agent/issues) 页面在 GitHub 上.

## 许可证

egjs-agent 将在 [麻省理工学院许可证](http://naver.github.io/egjs/license.txt)。 。 。 .

```
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 是什么？

从用户代理字符串或用户代理对象\(userAgentData\)中提取浏览器和操作系统信息\.

### 如何安装 @egjs/agent？

在项目目录运行 npm install @egjs/agent，或使用 pnpm add / yarn add / bun add。

### @egjs/agent 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @egjs/agent 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @egjs/agent 可以商用吗？

@egjs/agent 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @egjs/agent 的下载量有多少？

根据 npm 官方下载统计，@egjs/agent 在 2026/10/13 – 2026/11/11 这 30 天内被下载 3,106,093 次，日均约 103,536 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @egjs/agent 还在维护吗？

最新版本 2\.4\.4 发布于 2024/08/23（2 年前）；至今共发布 20 个版本，其中过去 12 个月发布了 0 个；首次发布于 2017/04/28。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

