ua-browser 0.1.9 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +139 -169
- package/README.zh-CN.md +176 -0
- package/dist/index.cjs +521 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +139 -0
- package/dist/index.d.ts +125 -126
- package/dist/index.min.js +3 -1
- package/dist/index.min.js.map +1 -0
- package/dist/index.mjs +507 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +41 -36
- package/dist/index.cjs.js +0 -517
- package/dist/index.esm.mjs +0 -515
- package/index.js +0 -7
package/README.md
CHANGED
|
@@ -1,206 +1,176 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ua-browser
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/ua-browser)
|
|
4
|
+
[](https://www.npmjs.com/package/ua-browser)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
Detect browser, OS, device type, rendering engine, CPU architecture, bots, and headless browsers from User Agent strings. Zero dependencies. Works in both browser and Node.js environments.
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
**[📖 Documentation](https://yangtianxia.github.io/ua-browser/)** · **[🎮 Playground](https://yangtianxia.github.io/ua-browser/playground)** · **[中文](./README.zh-CN.md)**
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
npm i ua-browser
|
|
11
|
-
```
|
|
12
|
+
## Features
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
- **Comprehensive detection** — browser, OS, engine, device type (Mobile / Tablet / TV / PC), CPU arch, bots, headless browsers
|
|
15
|
+
- **AI bot recognition** — built-in support for GPTBot, ClaudeBot, PerplexityBot, CCBot and more
|
|
16
|
+
- **Zero dependencies** — no runtime dependencies, tiny bundle size after gzip
|
|
17
|
+
- **Pure function** — `parseUA()` has no global state, works seamlessly with SSR / Node.js
|
|
18
|
+
- **TypeScript** — full type definitions with precise literal union types (`BrowserName`, `OsName`, etc.)
|
|
19
|
+
- **Tree-shakeable** — import only what you need
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
14
22
|
|
|
15
23
|
```sh
|
|
24
|
+
npm i ua-browser
|
|
25
|
+
# pnpm
|
|
16
26
|
pnpm add ua-browser
|
|
27
|
+
# yarn
|
|
28
|
+
yarn add ua-browser
|
|
17
29
|
```
|
|
18
30
|
|
|
19
|
-
|
|
31
|
+
## Quick Start
|
|
20
32
|
|
|
21
|
-
```
|
|
22
|
-
|
|
33
|
+
```typescript
|
|
34
|
+
import uaBrowser from 'ua-browser'
|
|
35
|
+
|
|
36
|
+
const info = uaBrowser()
|
|
37
|
+
|
|
38
|
+
console.log(info)
|
|
39
|
+
// {
|
|
40
|
+
// browser: 'Chrome',
|
|
41
|
+
// version: '124.0.0.0',
|
|
42
|
+
// engine: 'Blink',
|
|
43
|
+
// os: 'Windows',
|
|
44
|
+
// osVersion: '10',
|
|
45
|
+
// device: 'PC',
|
|
46
|
+
// arch: 'x86_64',
|
|
47
|
+
// isWebview: false,
|
|
48
|
+
// isHeadless: false,
|
|
49
|
+
// isBot: false,
|
|
50
|
+
// botName: 'unknown',
|
|
51
|
+
// language: 'en-US',
|
|
52
|
+
// platform: 'Win32'
|
|
53
|
+
// }
|
|
23
54
|
```
|
|
24
55
|
|
|
25
|
-
|
|
56
|
+
> Pass a custom UA string: `uaBrowser('Mozilla/5.0 ...')`
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
### Browser
|
|
26
61
|
|
|
27
62
|
```typescript
|
|
28
|
-
import
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
engine: string;
|
|
35
|
-
browser: string;
|
|
36
|
-
os: string;
|
|
37
|
-
device: string;
|
|
38
|
-
isWebview: boolean;
|
|
39
|
-
language: string;
|
|
40
|
-
platfrom: string;
|
|
63
|
+
import uaBrowser from 'ua-browser'
|
|
64
|
+
|
|
65
|
+
const { browser, os, device } = uaBrowser()
|
|
66
|
+
|
|
67
|
+
if (device === 'Mobile') {
|
|
68
|
+
// redirect to mobile version
|
|
41
69
|
}
|
|
42
70
|
|
|
43
|
-
|
|
44
|
-
|
|
71
|
+
if (browser === 'Wechat') {
|
|
72
|
+
// WeChat in-app browser logic
|
|
73
|
+
}
|
|
74
|
+
```
|
|
45
75
|
|
|
46
|
-
|
|
47
|
-
uaBrowser.isWechatMiniapp(): boolean
|
|
76
|
+
### Node.js / SSR
|
|
48
77
|
|
|
49
|
-
|
|
50
|
-
|
|
78
|
+
Use the pure `parseUA` function with the UA string from the request header:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { parseUA } from 'ua-browser'
|
|
51
82
|
|
|
52
|
-
|
|
53
|
-
|
|
83
|
+
const ua = req.headers['user-agent'] ?? ''
|
|
84
|
+
const { browser, os, isBot } = parseUA(ua)
|
|
85
|
+
|
|
86
|
+
if (isBot) {
|
|
87
|
+
// block or allow crawlers
|
|
88
|
+
}
|
|
54
89
|
```
|
|
55
90
|
|
|
56
|
-
|
|
91
|
+
### CDN
|
|
57
92
|
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
| 'Edge'
|
|
64
|
-
| 'Firefox'
|
|
65
|
-
| 'Firefox Focus'
|
|
66
|
-
| 'Chromium'
|
|
67
|
-
| 'Opera'
|
|
68
|
-
| 'Vivaldi'
|
|
69
|
-
| 'Yandex'
|
|
70
|
-
| 'Arora'
|
|
71
|
-
| 'Lunascape'
|
|
72
|
-
| 'QupZilla'
|
|
73
|
-
| 'Coc Coc'
|
|
74
|
-
| 'Kindle'
|
|
75
|
-
| 'Iceweasel'
|
|
76
|
-
| 'Konqueror'
|
|
77
|
-
| 'Iceape'
|
|
78
|
-
| 'SeaMonkey'
|
|
79
|
-
| 'Epiphany'
|
|
80
|
-
| '360'
|
|
81
|
-
| '360EE'
|
|
82
|
-
| '360SE'
|
|
83
|
-
| 'UC'
|
|
84
|
-
| 'QQBrowser'
|
|
85
|
-
| 'QQ'
|
|
86
|
-
| 'Baidu'
|
|
87
|
-
| 'Maxthon'
|
|
88
|
-
| 'Sogou'
|
|
89
|
-
| 'Liebao'
|
|
90
|
-
| '2345Explorer'
|
|
91
|
-
| '115Browser'
|
|
92
|
-
| 'TheWorld'
|
|
93
|
-
| 'XiaoMi'
|
|
94
|
-
| 'Quark'
|
|
95
|
-
| 'Qiyu'
|
|
96
|
-
| 'Wechat'
|
|
97
|
-
| 'WechatWork'
|
|
98
|
-
| 'Taobao'
|
|
99
|
-
| 'Alipay'
|
|
100
|
-
| 'Weibo'
|
|
101
|
-
| 'Douban'
|
|
102
|
-
| 'Suning'
|
|
103
|
-
| 'iQiYi'
|
|
104
|
-
| 'DingTalk'
|
|
105
|
-
| 'Huawei'
|
|
106
|
-
| 'Vivo'
|
|
107
|
-
| 'Firefox Nightly'
|
|
108
|
-
| 'Wechat Miniapp'
|
|
93
|
+
```html
|
|
94
|
+
<script src="https://cdn.jsdelivr.net/npm/ua-browser/dist/index.min.js"></script>
|
|
95
|
+
<script>
|
|
96
|
+
const { browser, os } = uaBrowser()
|
|
97
|
+
</script>
|
|
109
98
|
```
|
|
110
99
|
|
|
111
|
-
|
|
100
|
+
### Accurate Windows 10 / 11 Detection
|
|
101
|
+
|
|
102
|
+
Windows 10 and 11 share the same UA string. Use the Client Hints API to distinguish them:
|
|
112
103
|
|
|
113
104
|
```typescript
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
| 'EdgeHTML'
|
|
105
|
+
import { parseUA, getWindowsVersion, getNavContext } from 'ua-browser'
|
|
106
|
+
|
|
107
|
+
const nav = getNavContext()
|
|
108
|
+
const windowsVersion = await getWindowsVersion(nav)
|
|
109
|
+
const result = parseUA(navigator.userAgent, { nav, windowsVersion })
|
|
110
|
+
|
|
111
|
+
console.log(result.osVersion) // '10' or '11'
|
|
122
112
|
```
|
|
123
113
|
|
|
124
|
-
##
|
|
114
|
+
## API
|
|
115
|
+
|
|
116
|
+
### Default export `uaBrowser(ua?)`
|
|
117
|
+
|
|
118
|
+
Automatically injects the `navigator` context (language, platform, MIME types, etc.) in browser environments.
|
|
125
119
|
|
|
126
120
|
```typescript
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
| 'Android'
|
|
132
|
-
| 'HarmonyOS'
|
|
133
|
-
| 'Ubuntu'
|
|
134
|
-
| 'FreeBSD'
|
|
135
|
-
| 'Debian'
|
|
136
|
-
| 'Windows Phone'
|
|
137
|
-
| 'BlackBerry'
|
|
138
|
-
| 'MeeGo'
|
|
139
|
-
| 'Symbian'
|
|
140
|
-
| 'iOS'
|
|
141
|
-
| 'Chrome OS'
|
|
142
|
-
| 'WebOS'
|
|
121
|
+
import uaBrowser from 'ua-browser'
|
|
122
|
+
|
|
123
|
+
uaBrowser() // reads navigator.userAgent automatically
|
|
124
|
+
uaBrowser(customUA) // custom UA string, still injects browser context
|
|
143
125
|
```
|
|
144
126
|
|
|
145
|
-
|
|
127
|
+
### Named exports (tree-shakeable)
|
|
146
128
|
|
|
147
129
|
```typescript
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
130
|
+
import {
|
|
131
|
+
parseUA, // pure function, ideal for SSR / Node.js
|
|
132
|
+
getNavContext, // read current browser navigator context
|
|
133
|
+
getWindowsVersion, // async: accurately distinguish Windows 10 / 11
|
|
134
|
+
getLanguage, // extract browser language from NavContext
|
|
135
|
+
isWebview, // detect Android Webview (UA contains "; wv")
|
|
136
|
+
isWechatMiniapp, // detect WeChat Mini Program environment
|
|
137
|
+
detectBot, // standalone bot detection
|
|
138
|
+
detectArch, // standalone CPU architecture detection
|
|
139
|
+
detectHeadless, // standalone headless browser detection
|
|
140
|
+
VERSION, // current library version
|
|
141
|
+
} from 'ua-browser'
|
|
152
142
|
```
|
|
153
143
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
|
157
|
-
| :-- | :-- |
|
|
158
|
-
|
|
|
159
|
-
|
|
|
160
|
-
|
|
|
161
|
-
|
|
|
162
|
-
|
|
|
163
|
-
|
|
|
164
|
-
|
|
|
165
|
-
|
|
|
166
|
-
|
|
|
167
|
-
|
|
|
168
|
-
|
|
|
169
|
-
|
|
|
170
|
-
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
| 猎豹浏览器 | `Liebao` |
|
|
188
|
-
| 2345浏览器 | `2345Explorer` |
|
|
189
|
-
| 115浏览器 | `115Browser` |
|
|
190
|
-
| 世界之窗浏览器 | `TheWorld` |
|
|
191
|
-
| 小米浏览器 | `XiaoMi` |
|
|
192
|
-
| 夸克浏览器 | `Quark` |
|
|
193
|
-
| 旗鱼浏览器 | `Qiyu` |
|
|
194
|
-
| 微信手机客户端 | `Wechat` |
|
|
195
|
-
| 企业微信客户端 | `WechatWork` |
|
|
196
|
-
| 淘宝手机客户端 | `Taobao` |
|
|
197
|
-
| 支付宝手机客户端 | `Alipay` |
|
|
198
|
-
| 微博手机客户端 | `Weibo` |
|
|
199
|
-
| 豆瓣手机客户端 | `Douban` |
|
|
200
|
-
| 苏宁易购手机客户端 | `Suning` |
|
|
201
|
-
| 爱奇艺手机客户端 | `iQiYi` |
|
|
202
|
-
| 钉钉手机客户端 | `DingTalk` |
|
|
203
|
-
| 华为浏览器 | `Huawei` |
|
|
204
|
-
| Vivo浏览器 | `Vivo` |
|
|
205
|
-
| Firefox 下一代网络浏览器Nightly | `Firefox Nightly` |
|
|
206
|
-
| 微信小程序 | `Wechat Miniapp` |
|
|
144
|
+
### Return value `EnvOption`
|
|
145
|
+
|
|
146
|
+
| Field | Type | Description |
|
|
147
|
+
| :-- | :-- | :-- |
|
|
148
|
+
| `browser` | `BrowserName` | Browser name |
|
|
149
|
+
| `version` | `string` | Browser version |
|
|
150
|
+
| `engine` | `EngineName` | Rendering engine |
|
|
151
|
+
| `os` | `OsName` | Operating system |
|
|
152
|
+
| `osVersion` | `string` | OS version |
|
|
153
|
+
| `device` | `DeviceName` | Device type: `Mobile` \| `Tablet` \| `TV` \| `PC` |
|
|
154
|
+
| `arch` | `ArchName` | CPU architecture |
|
|
155
|
+
| `isWebview` | `boolean` | Whether running in Android Webview |
|
|
156
|
+
| `isHeadless` | `boolean` | Whether running in a headless / automated browser |
|
|
157
|
+
| `isBot` | `boolean` | Whether the UA belongs to a bot / crawler |
|
|
158
|
+
| `botName` | `BotName` | Bot name |
|
|
159
|
+
| `language` | `string` | Browser language, e.g. `en-US` |
|
|
160
|
+
| `platform` | `string` | Platform identifier, e.g. `Win32` |
|
|
161
|
+
|
|
162
|
+
> All fields return `'unknown'` when undetected — never an empty string or `null`.
|
|
163
|
+
|
|
164
|
+
## Supported
|
|
165
|
+
|
|
166
|
+
Over 60 browsers, 17 operating systems, and 19 bot rules built in. See the **[full support list](https://yangtianxia.github.io/ua-browser/guide/support-list)**.
|
|
167
|
+
|
|
168
|
+
Highlights:
|
|
169
|
+
- **Browsers** — Chrome, Safari, Firefox, Edge, Samsung Internet, UC, WeChat, DingTalk, TikTok and more
|
|
170
|
+
- **OS** — Windows, macOS, Android, iOS, HarmonyOS, Tizen, KaiOS and more
|
|
171
|
+
- **AI bots** — GPTBot, ClaudeBot, PerplexityBot, CCBot and more
|
|
172
|
+
- **Devices** — Mobile, Tablet, TV (Samsung Smart TV, HbbTV), PC
|
|
173
|
+
|
|
174
|
+
## License
|
|
175
|
+
|
|
176
|
+
[MIT](./LICENSE) © yangtianxia
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# ua-browser
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/ua-browser)
|
|
4
|
+
[](https://www.npmjs.com/package/ua-browser)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
|
|
8
|
+
通过 User Agent 检测浏览器、操作系统、设备类型、渲染内核、CPU 架构、爬虫及无头浏览器。零依赖,支持浏览器与 Node.js 双环境。
|
|
9
|
+
|
|
10
|
+
**[📖 文档](https://yangtianxia.github.io/ua-browser/)** · **[🎮 Playground](https://yangtianxia.github.io/ua-browser/playground)** · **[English](./README.md)**
|
|
11
|
+
|
|
12
|
+
## 特性
|
|
13
|
+
|
|
14
|
+
- **全面检测** — 浏览器、OS、渲染内核、设备类型(Mobile / Tablet / TV / PC)、CPU 架构、爬虫、无头浏览器
|
|
15
|
+
- **AI 爬虫识别** — 内置 GPTBot、ClaudeBot、PerplexityBot 等主流 AI 抓取机器人
|
|
16
|
+
- **零依赖** — 无任何运行时依赖,gzip 后体积极小
|
|
17
|
+
- **纯函数** — `parseUA()` 无全局状态,天然支持 SSR / Node.js
|
|
18
|
+
- **TypeScript** — 完整类型定义,`BrowserName`、`OsName` 等均为精确字面量联合类型
|
|
19
|
+
- **Tree-shakeable** — 所有功能按需导入,不引入多余代码
|
|
20
|
+
|
|
21
|
+
## 安装
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm i ua-browser
|
|
25
|
+
# pnpm
|
|
26
|
+
pnpm add ua-browser
|
|
27
|
+
# yarn
|
|
28
|
+
yarn add ua-browser
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 快速上手
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import uaBrowser from 'ua-browser'
|
|
35
|
+
|
|
36
|
+
const info = uaBrowser()
|
|
37
|
+
|
|
38
|
+
console.log(info)
|
|
39
|
+
// {
|
|
40
|
+
// browser: 'Chrome',
|
|
41
|
+
// version: '124.0.0.0',
|
|
42
|
+
// engine: 'Blink',
|
|
43
|
+
// os: 'Windows',
|
|
44
|
+
// osVersion: '10',
|
|
45
|
+
// device: 'PC',
|
|
46
|
+
// arch: 'x86_64',
|
|
47
|
+
// isWebview: false,
|
|
48
|
+
// isHeadless: false,
|
|
49
|
+
// isBot: false,
|
|
50
|
+
// botName: 'unknown',
|
|
51
|
+
// language: 'zh-CN',
|
|
52
|
+
// platform: 'Win32'
|
|
53
|
+
// }
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
> 传入自定义 UA 字符串:`uaBrowser('Mozilla/5.0 ...')`
|
|
57
|
+
|
|
58
|
+
## 使用
|
|
59
|
+
|
|
60
|
+
### 浏览器环境
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import uaBrowser from 'ua-browser'
|
|
64
|
+
|
|
65
|
+
const { browser, os, device } = uaBrowser()
|
|
66
|
+
|
|
67
|
+
if (device === 'Mobile') {
|
|
68
|
+
// 跳转移动版
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (browser === 'Wechat') {
|
|
72
|
+
// 微信内置浏览器逻辑
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Node.js / SSR
|
|
77
|
+
|
|
78
|
+
使用 `parseUA` 纯函数,传入请求头中的 UA 字符串:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { parseUA } from 'ua-browser'
|
|
82
|
+
|
|
83
|
+
const ua = req.headers['user-agent'] ?? ''
|
|
84
|
+
const { browser, os, isBot } = parseUA(ua)
|
|
85
|
+
|
|
86
|
+
if (isBot) {
|
|
87
|
+
// 拦截或放行爬虫
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### CDN
|
|
92
|
+
|
|
93
|
+
```html
|
|
94
|
+
<script src="https://cdn.jsdelivr.net/npm/ua-browser/dist/index.min.js"></script>
|
|
95
|
+
<script>
|
|
96
|
+
const { browser, os } = uaBrowser()
|
|
97
|
+
</script>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 精确区分 Windows 10 / 11
|
|
101
|
+
|
|
102
|
+
Windows 10 和 11 的 UA 字符串相同,需借助 Client Hints API 异步获取:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { parseUA, getWindowsVersion, getNavContext } from 'ua-browser'
|
|
106
|
+
|
|
107
|
+
const nav = getNavContext()
|
|
108
|
+
const windowsVersion = await getWindowsVersion(nav)
|
|
109
|
+
const result = parseUA(navigator.userAgent, { nav, windowsVersion })
|
|
110
|
+
|
|
111
|
+
console.log(result.osVersion) // '10' 或 '11'
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## API
|
|
115
|
+
|
|
116
|
+
### 默认导出 `uaBrowser(ua?)`
|
|
117
|
+
|
|
118
|
+
在浏览器环境中自动注入 `navigator` 上下文(语言、平台、MIME 类型等)。
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import uaBrowser from 'ua-browser'
|
|
122
|
+
|
|
123
|
+
uaBrowser() // 自动读取 navigator.userAgent
|
|
124
|
+
uaBrowser(customUA) // 传入自定义 UA,仍注入当前浏览器上下文
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 命名导出(按需引入)
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import {
|
|
131
|
+
parseUA, // 纯函数,适合 SSR / Node.js
|
|
132
|
+
getNavContext, // 读取当前浏览器 navigator 上下文
|
|
133
|
+
getWindowsVersion, // 异步精确区分 Windows 10 / 11
|
|
134
|
+
getLanguage, // 从 NavContext 获取浏览器语言
|
|
135
|
+
isWebview, // 检测 Android Webview(UA 含 "; wv")
|
|
136
|
+
isWechatMiniapp, // 检测微信小程序运行环境
|
|
137
|
+
detectBot, // 独立爬虫检测
|
|
138
|
+
detectArch, // 独立 CPU 架构检测
|
|
139
|
+
detectHeadless, // 独立无头浏览器检测
|
|
140
|
+
VERSION, // 当前版本号
|
|
141
|
+
} from 'ua-browser'
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### 返回值 `EnvOption`
|
|
145
|
+
|
|
146
|
+
| 字段 | 类型 | 说明 |
|
|
147
|
+
| :-- | :-- | :-- |
|
|
148
|
+
| `browser` | `BrowserName` | 浏览器名称 |
|
|
149
|
+
| `version` | `string` | 浏览器版本 |
|
|
150
|
+
| `engine` | `EngineName` | 渲染内核 |
|
|
151
|
+
| `os` | `OsName` | 操作系统 |
|
|
152
|
+
| `osVersion` | `string` | 系统版本 |
|
|
153
|
+
| `device` | `DeviceName` | 设备类型:`Mobile` \| `Tablet` \| `TV` \| `PC` |
|
|
154
|
+
| `arch` | `ArchName` | CPU 架构 |
|
|
155
|
+
| `isWebview` | `boolean` | 是否为 Android Webview |
|
|
156
|
+
| `isHeadless` | `boolean` | 是否为无头 / 自动化浏览器 |
|
|
157
|
+
| `isBot` | `boolean` | 是否为爬虫 / 机器人 |
|
|
158
|
+
| `botName` | `BotName` | 爬虫名称 |
|
|
159
|
+
| `language` | `string` | 浏览器语言,如 `zh-CN` |
|
|
160
|
+
| `platform` | `string` | 平台标识,如 `Win32` |
|
|
161
|
+
|
|
162
|
+
> 所有字段在无法识别时统一返回 `'unknown'`,不返回空字符串或 `null`。
|
|
163
|
+
|
|
164
|
+
## 支持范围
|
|
165
|
+
|
|
166
|
+
内置超过 60 种浏览器、17 种操作系统、19 种爬虫规则,详见 **[内置支持列表](https://yangtianxia.github.io/ua-browser/guide/support-list)**。
|
|
167
|
+
|
|
168
|
+
部分覆盖:
|
|
169
|
+
- **浏览器** — Chrome、Safari、Firefox、Edge、Samsung Internet、UC、微信、钉钉、抖音等
|
|
170
|
+
- **操作系统** — Windows、macOS、Android、iOS、HarmonyOS、Tizen、KaiOS 等
|
|
171
|
+
- **AI 爬虫** — GPTBot、ClaudeBot、PerplexityBot、CCBot 等
|
|
172
|
+
- **设备** — Mobile、Tablet、TV(含三星 Smart TV、HbbTV 标准)、PC
|
|
173
|
+
|
|
174
|
+
## License
|
|
175
|
+
|
|
176
|
+
[MIT](./LICENSE) © yangtianxia
|