ua-browser 1.2.0 โ†’ 1.3.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 CHANGED
@@ -5,13 +5,15 @@
5
5
  [![license](https://img.shields.io/npm/l/ua-browser)](./LICENSE)
6
6
  [![TypeScript](https://img.shields.io/badge/TypeScript-ready-3178c6)](https://www.typescriptlang.org/)
7
7
 
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.
8
+ Detect browser, OS, device type, rendering engine, CPU architecture, bots, headless browsers, and Mini Programs from User Agent strings. Zero dependencies. Works in both browser and Node.js environments.
9
9
 
10
10
  **[๐Ÿ“– Documentation](https://yangtianxia.github.io/ua-browser/)** ยท **[๐ŸŽฎ Playground](https://yangtianxia.github.io/ua-browser/playground)** ยท **[ไธญๆ–‡](./README.zh-CN.md)**
11
11
 
12
12
  ## Features
13
13
 
14
- - **Comprehensive detection** โ€” browser, OS, engine, device type (Mobile / Tablet / TV / PC), CPU arch, bots, headless browsers
14
+ - **Comprehensive UA detection** โ€” browser, OS, engine, device type (Mobile / Tablet / TV / PC), CPU arch, bots, headless browsers
15
+ - **Multi-signal arch detection** โ€” `getEnvContext()` collects Client Hints, WebGL renderer, and font probes to accurately distinguish Apple Silicon from Intel Mac
16
+ - **SSR Client Hints** โ€” `parseHeaders()` + `ACCEPT_CH` for precise server-side detection (CPU arch, platform) in Chrome / Edge 90+
15
17
  - **AI bot recognition** โ€” built-in support for GPTBot, ClaudeBot, PerplexityBot, CCBot and more
16
18
  - **Zero dependencies** โ€” no runtime dependencies, tiny bundle size after gzip
17
19
  - **Pure function** โ€” `parseUA()` has no global state, works seamlessly with SSR / Node.js
@@ -67,16 +69,10 @@ const { browser, os, device } = uaBrowser()
67
69
  if (device === 'Mobile') {
68
70
  // redirect to mobile version
69
71
  }
70
-
71
- if (browser === 'Wechat') {
72
- // WeChat in-app browser logic
73
- }
74
72
  ```
75
73
 
76
74
  ### Node.js / SSR
77
75
 
78
- Use the pure `parseUA` function with the UA string from the request header:
79
-
80
76
  ```typescript
81
77
  import { parseUA } from 'ua-browser'
82
78
 
@@ -97,6 +93,34 @@ if (isBot) {
97
93
  </script>
98
94
  ```
99
95
 
96
+ ### Multi-signal Architecture Detection
97
+
98
+ `getEnvContext()` collects Client Hints, WebGL renderer, and other browser signals in one async call โ€” enough to distinguish Apple Silicon from Intel Mac:
99
+
100
+ ```typescript
101
+ import { getEnvContext, parseUA } from 'ua-browser'
102
+
103
+ const ctx = await getEnvContext()
104
+ const result = parseUA(navigator.userAgent, { ctx })
105
+
106
+ console.log(result.arch) // 'arm64' or 'x86_64'
107
+ ```
108
+
109
+ ### SSR Client Hints
110
+
111
+ Set the `ACCEPT_CH` response header so Chrome / Edge 90+ browsers send Client Hints on subsequent requests, then use `parseHeaders` for precise server-side detection:
112
+
113
+ ```typescript
114
+ import { parseHeaders, ACCEPT_CH } from 'ua-browser'
115
+
116
+ // First response โ€” tell the browser to send Client Hints
117
+ res.setHeader('Accept-CH', ACCEPT_CH)
118
+
119
+ // Subsequent requests โ€” accurate arch / OS detection
120
+ const result = parseHeaders(req.headers)
121
+ console.log(result.arch) // 'x86_64' (from Sec-CH-UA-Arch)
122
+ ```
123
+
100
124
  ### Accurate Windows 10 / 11 Detection
101
125
 
102
126
  Windows 10 and 11 share the same UA string. Use the Client Hints API to distinguish them:
@@ -118,8 +142,6 @@ console.log(result.osVersion) // '10' or '11'
118
142
  Automatically injects the `navigator` context (language, platform, MIME types, etc.) in browser environments.
119
143
 
120
144
  ```typescript
121
- import uaBrowser from 'ua-browser'
122
-
123
145
  uaBrowser() // reads navigator.userAgent automatically
124
146
  uaBrowser(customUA) // custom UA string, still injects browser context
125
147
  ```
@@ -128,16 +150,18 @@ uaBrowser(customUA) // custom UA string, still injects browser context
128
150
 
129
151
  ```typescript
130
152
  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
153
+ parseUA, // pure function, ideal for SSR / Node.js
154
+ getNavContext, // read current browser navigator context
155
+ getWindowsVersion, // async: accurately distinguish Windows 10 / 11
156
+ getLanguage, // extract browser language from NavContext
157
+ getEnvContext, // collect all browser signals (Client Hints, WebGL, etc.)
158
+ parseHeaders, // parse UA and Client Hints from HTTP headers (SSR)
159
+ ACCEPT_CH, // response header constant to request Client Hints
160
+ isWebview, // detect Android Webview / iOS WKWebView
161
+ detectBot, // standalone bot detection
162
+ detectArch, // standalone CPU architecture detection
163
+ detectHeadless, // standalone headless browser detection
164
+ VERSION, // current library version
141
165
  } from 'ua-browser'
142
166
  ```
143
167
 
@@ -152,7 +176,7 @@ import {
152
176
  | `osVersion` | `string` | OS version |
153
177
  | `device` | `DeviceName` | Device type: `Mobile` \| `Tablet` \| `TV` \| `PC` |
154
178
  | `arch` | `ArchName` | CPU architecture |
155
- | `isWebview` | `boolean` | Whether running in Android Webview |
179
+ | `isWebview` | `boolean` | Whether running in Android Webview or iOS WKWebView |
156
180
  | `isHeadless` | `boolean` | Whether running in a headless / automated browser |
157
181
  | `isBot` | `boolean` | Whether the UA belongs to a bot / crawler |
158
182
  | `botName` | `BotName` | Bot name |
@@ -163,11 +187,11 @@ import {
163
187
 
164
188
  ## Supported
165
189
 
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)**.
190
+ Over 70 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
191
 
168
192
  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
193
+ - **Browsers** โ€” Chrome, Safari, Firefox, Edge, Samsung Internet, UC, WeChat, DingTalk, TikTok, Bilibili, Kuaishou, Xiaohongshu, Feishu and more
194
+ - **OS** โ€” Windows, macOS, Android, iOS, HarmonyOS, OpenHarmony, Tizen, KaiOS and more
171
195
  - **AI bots** โ€” GPTBot, ClaudeBot, PerplexityBot, CCBot and more
172
196
  - **Devices** โ€” Mobile, Tablet, TV (Samsung Smart TV, HbbTV), PC
173
197
 
package/README.zh-CN.md CHANGED
@@ -5,14 +5,16 @@
5
5
  [![license](https://img.shields.io/npm/l/ua-browser)](./LICENSE)
6
6
  [![TypeScript](https://img.shields.io/badge/TypeScript-ready-3178c6)](https://www.typescriptlang.org/)
7
7
 
8
- ้€š่ฟ‡ User Agent ๆฃ€ๆต‹ๆต่งˆๅ™จใ€ๆ“ไฝœ็ณป็ปŸใ€่ฎพๅค‡็ฑปๅž‹ใ€ๆธฒๆŸ“ๅ†…ๆ ธใ€CPU ๆžถๆž„ใ€็ˆฌ่™ซๅŠๆ— ๅคดๆต่งˆๅ™จใ€‚้›ถไพ่ต–๏ผŒๆ”ฏๆŒๆต่งˆๅ™จไธŽ Node.js ๅŒ็Žฏๅขƒใ€‚
8
+ ้€š่ฟ‡ User Agent ๆฃ€ๆต‹ๆต่งˆๅ™จใ€ๆ“ไฝœ็ณป็ปŸใ€่ฎพๅค‡็ฑปๅž‹ใ€ๆธฒๆŸ“ๅ†…ๆ ธใ€CPU ๆžถๆž„ใ€็ˆฌ่™ซใ€ๆ— ๅคดๆต่งˆๅ™จๅŠๅฐ็จ‹ๅบ่ฟ่กŒ็Žฏๅขƒใ€‚้›ถไพ่ต–๏ผŒๆ”ฏๆŒๆต่งˆๅ™จไธŽ Node.js ๅŒ็Žฏๅขƒใ€‚
9
9
 
10
10
  **[๐Ÿ“– ๆ–‡ๆกฃ](https://yangtianxia.github.io/ua-browser/)** ยท **[๐ŸŽฎ Playground](https://yangtianxia.github.io/ua-browser/playground)** ยท **[English](./README.md)**
11
11
 
12
12
  ## ็‰นๆ€ง
13
13
 
14
- - **ๅ…จ้ขๆฃ€ๆต‹** โ€” ๆต่งˆๅ™จใ€OSใ€ๆธฒๆŸ“ๅ†…ๆ ธใ€่ฎพๅค‡็ฑปๅž‹๏ผˆMobile / Tablet / TV / PC๏ผ‰ใ€CPU ๆžถๆž„ใ€็ˆฌ่™ซใ€ๆ— ๅคดๆต่งˆๅ™จ
15
- - **AI ็ˆฌ่™ซ่ฏ†ๅˆซ** โ€” ๅ†…็ฝฎ GPTBotใ€ClaudeBotใ€PerplexityBot ็ญ‰ไธปๆต AI ๆŠ“ๅ–ๆœบๅ™จไบบ
14
+ - **ๅ…จ้ข UA ๆฃ€ๆต‹** โ€” ๆต่งˆๅ™จใ€OSใ€ๆธฒๆŸ“ๅ†…ๆ ธใ€่ฎพๅค‡็ฑปๅž‹๏ผˆMobile / Tablet / TV / PC๏ผ‰ใ€CPU ๆžถๆž„ใ€็ˆฌ่™ซใ€ๆ— ๅคดๆต่งˆๅ™จ
15
+ - **ๅคšไฟกๅทๆžถๆž„ๆฃ€ๆต‹** โ€” `getEnvContext()` ้‡‡้›† Client Hintsใ€WebGL ๆธฒๆŸ“ๅ™จใ€ๅญ—ไฝ“ๆŽข้’ˆ๏ผŒ็ฒพ็กฎๅŒบๅˆ† Apple Silicon ไธŽ Intel Mac
16
+ - **SSR Client Hints** โ€” `parseHeaders()` + `ACCEPT_CH`๏ผŒๅœจ Chrome / Edge 90+ ไธญๅฎž็ŽฐๆœๅŠก็ซฏ็ฒพๅ‡†ๆฃ€ๆต‹๏ผˆCPU ๆžถๆž„ใ€ๅนณๅฐ็ญ‰๏ผ‰
17
+ - **AI ็ˆฌ่™ซ่ฏ†ๅˆซ** โ€” ๅ†…็ฝฎ GPTBotใ€ClaudeBotใ€PerplexityBotใ€CCBot ็ญ‰ไธปๆต AI ๆŠ“ๅ–ๆœบๅ™จไบบ
16
18
  - **้›ถไพ่ต–** โ€” ๆ— ไปปไฝ•่ฟ่กŒๆ—ถไพ่ต–๏ผŒgzip ๅŽไฝ“็งฏๆžๅฐ
17
19
  - **็บฏๅ‡ฝๆ•ฐ** โ€” `parseUA()` ๆ— ๅ…จๅฑ€็Šถๆ€๏ผŒๅคฉ็„ถๆ”ฏๆŒ SSR / Node.js
18
20
  - **TypeScript** โ€” ๅฎŒๆ•ด็ฑปๅž‹ๅฎšไน‰๏ผŒ`BrowserName`ใ€`OsName` ็ญ‰ๅ‡ไธบ็ฒพ็กฎๅญ—้ข้‡่”ๅˆ็ฑปๅž‹
@@ -67,16 +69,10 @@ const { browser, os, device } = uaBrowser()
67
69
  if (device === 'Mobile') {
68
70
  // ่ทณ่ฝฌ็งปๅŠจ็‰ˆ
69
71
  }
70
-
71
- if (browser === 'Wechat') {
72
- // ๅพฎไฟกๅ†…็ฝฎๆต่งˆๅ™จ้€ป่พ‘
73
- }
74
72
  ```
75
73
 
76
74
  ### Node.js / SSR
77
75
 
78
- ไฝฟ็”จ `parseUA` ็บฏๅ‡ฝๆ•ฐ๏ผŒไผ ๅ…ฅ่ฏทๆฑ‚ๅคดไธญ็š„ UA ๅญ—็ฌฆไธฒ๏ผš
79
-
80
76
  ```typescript
81
77
  import { parseUA } from 'ua-browser'
82
78
 
@@ -97,6 +93,34 @@ if (isBot) {
97
93
  </script>
98
94
  ```
99
95
 
96
+ ### ๅคšไฟกๅทๆžถๆž„ๆฃ€ๆต‹
97
+
98
+ `getEnvContext()` ไธ€ๆฌกๆ€ง้‡‡้›† Client Hintsใ€WebGL ๆธฒๆŸ“ๅ™จ็ญ‰ๅคš็ปดไฟกๅท๏ผŒๅฏๅŒบๅˆ† Apple Silicon ไธŽ Intel Mac๏ผš
99
+
100
+ ```typescript
101
+ import { getEnvContext, parseUA } from 'ua-browser'
102
+
103
+ const ctx = await getEnvContext()
104
+ const result = parseUA(navigator.userAgent, { ctx })
105
+
106
+ console.log(result.arch) // 'arm64' ๆˆ– 'x86_64'
107
+ ```
108
+
109
+ ### SSR Client Hints
110
+
111
+ ้€š่ฟ‡ๅ“ๅบ”ๅคดๅ‘Š็Ÿฅ Chrome / Edge 90+ ไธŠๆŠฅ Client Hints๏ผŒๅ†็”จ `parseHeaders` ๅœจๆœๅŠก็ซฏ็ฒพๅ‡†่งฃๆž๏ผš
112
+
113
+ ```typescript
114
+ import { parseHeaders, ACCEPT_CH } from 'ua-browser'
115
+
116
+ // ็ฌฌไธ€ๆฌกๅ“ๅบ”ๆ—ถๅ†™ๅ…ฅ Accept-CH
117
+ res.setHeader('Accept-CH', ACCEPT_CH)
118
+
119
+ // ๅŽ็ปญ่ฏทๆฑ‚ๆบๅธฆ Client Hints ๅŽ๏ผŒ็ฒพๅ‡†่ฏ†ๅˆซๆžถๆž„็ญ‰ไฟกๆฏ
120
+ const result = parseHeaders(req.headers)
121
+ console.log(result.arch) // 'x86_64'๏ผˆๆฅ่‡ช Sec-CH-UA-Arch๏ผ‰
122
+ ```
123
+
100
124
  ### ็ฒพ็กฎๅŒบๅˆ† Windows 10 / 11
101
125
 
102
126
  Windows 10 ๅ’Œ 11 ็š„ UA ๅญ—็ฌฆไธฒ็›ธๅŒ๏ผŒ้œ€ๅ€ŸๅŠฉ Client Hints API ๅผ‚ๆญฅ่Žทๅ–๏ผš
@@ -118,8 +142,6 @@ console.log(result.osVersion) // '10' ๆˆ– '11'
118
142
  ๅœจๆต่งˆๅ™จ็Žฏๅขƒไธญ่‡ชๅŠจๆณจๅ…ฅ `navigator` ไธŠไธ‹ๆ–‡๏ผˆ่ฏญ่จ€ใ€ๅนณๅฐใ€MIME ็ฑปๅž‹็ญ‰๏ผ‰ใ€‚
119
143
 
120
144
  ```typescript
121
- import uaBrowser from 'ua-browser'
122
-
123
145
  uaBrowser() // ่‡ชๅŠจ่ฏปๅ– navigator.userAgent
124
146
  uaBrowser(customUA) // ไผ ๅ…ฅ่‡ชๅฎšไน‰ UA๏ผŒไปๆณจๅ…ฅๅฝ“ๅ‰ๆต่งˆๅ™จไธŠไธ‹ๆ–‡
125
147
  ```
@@ -128,16 +150,18 @@ uaBrowser(customUA) // ไผ ๅ…ฅ่‡ชๅฎšไน‰ UA๏ผŒไปๆณจๅ…ฅๅฝ“ๅ‰ๆต่งˆๅ™จไธŠไธ‹ๆ–‡
128
150
 
129
151
  ```typescript
130
152
  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, // ๅฝ“ๅ‰็‰ˆๆœฌๅท
153
+ parseUA, // ็บฏๅ‡ฝๆ•ฐ๏ผŒ้€‚ๅˆ SSR / Node.js
154
+ getNavContext, // ่ฏปๅ–ๅฝ“ๅ‰ๆต่งˆๅ™จ navigator ไธŠไธ‹ๆ–‡
155
+ getWindowsVersion, // ๅผ‚ๆญฅ็ฒพ็กฎๅŒบๅˆ† Windows 10 / 11
156
+ getLanguage, // ไปŽ NavContext ่Žทๅ–ๆต่งˆๅ™จ่ฏญ่จ€
157
+ getEnvContext, // ้‡‡้›†ๆ‰€ๆœ‰ๆต่งˆๅ™จ็Žฏๅขƒไฟกๅท๏ผˆClient Hintsใ€WebGL ็ญ‰๏ผ‰
158
+ parseHeaders, // ไปŽ HTTP ่ฏทๆฑ‚ๅคด่งฃๆž UA ๅŠ Client Hints๏ผˆSSR๏ผ‰
159
+ ACCEPT_CH, // ๅ“ๅบ”ๅคดๅธธ้‡๏ผŒๅ‘Š็Ÿฅๆต่งˆๅ™จไธŠๆŠฅ Client Hints
160
+ isWebview, // ๆฃ€ๆต‹ Android Webview / iOS WKWebView
161
+ detectBot, // ็‹ฌ็ซ‹็ˆฌ่™ซๆฃ€ๆต‹
162
+ detectArch, // ็‹ฌ็ซ‹ CPU ๆžถๆž„ๆฃ€ๆต‹
163
+ detectHeadless, // ็‹ฌ็ซ‹ๆ— ๅคดๆต่งˆๅ™จๆฃ€ๆต‹
164
+ VERSION, // ๅฝ“ๅ‰็‰ˆๆœฌๅท
141
165
  } from 'ua-browser'
142
166
  ```
143
167
 
@@ -152,7 +176,7 @@ import {
152
176
  | `osVersion` | `string` | ็ณป็ปŸ็‰ˆๆœฌ |
153
177
  | `device` | `DeviceName` | ่ฎพๅค‡็ฑปๅž‹๏ผš`Mobile` \| `Tablet` \| `TV` \| `PC` |
154
178
  | `arch` | `ArchName` | CPU ๆžถๆž„ |
155
- | `isWebview` | `boolean` | ๆ˜ฏๅฆไธบ Android Webview |
179
+ | `isWebview` | `boolean` | ๆ˜ฏๅฆไธบ Android Webview / iOS WKWebView |
156
180
  | `isHeadless` | `boolean` | ๆ˜ฏๅฆไธบๆ— ๅคด / ่‡ชๅŠจๅŒ–ๆต่งˆๅ™จ |
157
181
  | `isBot` | `boolean` | ๆ˜ฏๅฆไธบ็ˆฌ่™ซ / ๆœบๅ™จไบบ |
158
182
  | `botName` | `BotName` | ็ˆฌ่™ซๅ็งฐ |
@@ -163,11 +187,11 @@ import {
163
187
 
164
188
  ## ๆ”ฏๆŒ่Œƒๅ›ด
165
189
 
166
- ๅ†…็ฝฎ่ถ…่ฟ‡ 60 ็งๆต่งˆๅ™จใ€17 ็งๆ“ไฝœ็ณป็ปŸใ€19 ็ง็ˆฌ่™ซ่ง„ๅˆ™๏ผŒ่ฏฆ่ง **[ๅ†…็ฝฎๆ”ฏๆŒๅˆ—่กจ](https://yangtianxia.github.io/ua-browser/guide/support-list)**ใ€‚
190
+ ๅ†…็ฝฎ่ถ…่ฟ‡ 70 ็งๆต่งˆๅ™จใ€17 ็งๆ“ไฝœ็ณป็ปŸใ€19 ็ง็ˆฌ่™ซ่ง„ๅˆ™๏ผŒ่ฏฆ่ง **[ๅ†…็ฝฎๆ”ฏๆŒๅˆ—่กจ](https://yangtianxia.github.io/ua-browser/guide/support-list)**ใ€‚
167
191
 
168
192
  ้ƒจๅˆ†่ฆ†็›–๏ผš
169
- - **ๆต่งˆๅ™จ** โ€” Chromeใ€Safariใ€Firefoxใ€Edgeใ€Samsung Internetใ€UCใ€ๅพฎไฟกใ€้’‰้’‰ใ€ๆŠ–้Ÿณ็ญ‰
170
- - **ๆ“ไฝœ็ณป็ปŸ** โ€” Windowsใ€macOSใ€Androidใ€iOSใ€HarmonyOSใ€Tizenใ€KaiOS ็ญ‰
193
+ - **ๆต่งˆๅ™จ** โ€” Chromeใ€Safariใ€Firefoxใ€Edgeใ€Samsung Internetใ€UCใ€ๅพฎไฟกใ€้’‰้’‰ใ€ๆŠ–้Ÿณใ€ๅ“”ๅ“ฉๅ“”ๅ“ฉใ€ๅฟซๆ‰‹ใ€ๅฐ็บขไนฆใ€้ฃžไนฆ็ญ‰
194
+ - **ๆ“ไฝœ็ณป็ปŸ** โ€” Windowsใ€macOSใ€Androidใ€iOSใ€HarmonyOSใ€OpenHarmonyใ€Tizenใ€KaiOS ็ญ‰
171
195
  - **AI ็ˆฌ่™ซ** โ€” GPTBotใ€ClaudeBotใ€PerplexityBotใ€CCBot ็ญ‰
172
196
  - **่ฎพๅค‡** โ€” Mobileใ€Tabletใ€TV๏ผˆๅซไธ‰ๆ˜Ÿ Smart TVใ€HbbTV ๆ ‡ๅ‡†๏ผ‰ใ€PC
173
197
 
package/dist/index.cjs CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  // package.json
6
6
  var package_default = {
7
- version: "1.2.0"};
7
+ version: "1.3.1"};
8
8
 
9
9
  // src/constants/browsers.ts
10
10
  var BROWSER_DEFS = [
@@ -432,7 +432,7 @@ function getLanguage(nav) {
432
432
 
433
433
  // src/parse.ts
434
434
  function parseUA(ua, options = {}) {
435
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
435
+ var _a, _b, _c, _d, _e, _f, _g, _h;
436
436
  const effectiveNav = (_a = options.ctx) != null ? _a : options.nav;
437
437
  const effectiveWindowsVersion = (_c = (_b = options.ctx) == null ? void 0 : _b.windowsVersion) != null ? _c : options.windowsVersion;
438
438
  const { browser: rawBrowser, version: rawVersion } = detectBrowser(ua);
@@ -497,54 +497,6 @@ function parseUA(ua, options = {}) {
497
497
  } catch (e) {
498
498
  }
499
499
  }
500
- if (browser === "Wechat") {
501
- try {
502
- if (typeof __wxjs_environment !== "undefined" && __wxjs_environment === "miniprogram") {
503
- browser = "Wechat Miniapp";
504
- }
505
- } catch (e) {
506
- }
507
- }
508
- if (browser === "Alipay") {
509
- try {
510
- if (typeof window !== "undefined" && typeof ((_i = window.my) == null ? void 0 : _i.getSystemInfo) === "function") {
511
- browser = "Alipay Miniapp";
512
- }
513
- } catch (e) {
514
- }
515
- }
516
- if (browser === "Baidu") {
517
- try {
518
- if (typeof swan !== "undefined" && typeof (swan == null ? void 0 : swan.getSystemInfo) === "function") {
519
- browser = "Baidu Miniapp";
520
- }
521
- } catch (e) {
522
- }
523
- }
524
- if (browser === "Douyin") {
525
- try {
526
- if (typeof tt !== "undefined" && typeof (tt == null ? void 0 : tt.getSystemInfo) === "function") {
527
- browser = "Douyin Miniapp";
528
- }
529
- } catch (e) {
530
- }
531
- }
532
- if (browser === "QQ") {
533
- try {
534
- if (typeof qq !== "undefined" && typeof (qq == null ? void 0 : qq.getSystemInfo) === "function") {
535
- browser = "QQ Miniapp";
536
- }
537
- } catch (e) {
538
- }
539
- }
540
- if (browser === "Kuaishou") {
541
- try {
542
- if (typeof ks !== "undefined" && typeof (ks == null ? void 0 : ks.getSystemInfo) === "function") {
543
- browser = "Kuaishou Miniapp";
544
- }
545
- } catch (e) {
546
- }
547
- }
548
500
  if (os === "iOS" && browser === "Safari") {
549
501
  const m = /Version\/([\d.]+)/.exec(ua);
550
502
  if (m && parseInt(m[1], 10) > parseInt(osVersion, 10)) {
@@ -569,21 +521,6 @@ function parseUA(ua, options = {}) {
569
521
  };
570
522
  }
571
523
 
572
- // src/utils/windows-version.ts
573
- async function getWindowsVersion(nav) {
574
- var _a;
575
- if (!nav.userAgentData || nav.userAgentData.platform !== "Windows") {
576
- return null;
577
- }
578
- try {
579
- const data = await nav.userAgentData.getHighEntropyValues(["platformVersion"]);
580
- const major = parseInt(((_a = data["platformVersion"]) == null ? void 0 : _a.split(".")[0]) || "0", 10);
581
- return major >= 13 ? "11" : "10";
582
- } catch (e) {
583
- return null;
584
- }
585
- }
586
-
587
524
  // src/utils/env-context.ts
588
525
  var OS_FONTS = [
589
526
  ".AppleSystemUIFont",
@@ -650,7 +587,16 @@ function deriveWindowsVersion(platformVersion) {
650
587
  }
651
588
  async function getEnvContext() {
652
589
  const base = getNavContext();
653
- const ctx = { ...base };
590
+ const ctx = {
591
+ userAgent: base.userAgent,
592
+ platform: base.platform,
593
+ language: base.language,
594
+ maxTouchPoints: base.maxTouchPoints
595
+ };
596
+ if (base.browserLanguage !== void 0) ctx.browserLanguage = base.browserLanguage;
597
+ if (base.mimeTypes !== void 0) ctx.mimeTypes = base.mimeTypes;
598
+ if (base.connection !== void 0) ctx.connection = base.connection;
599
+ if (base.userAgentData !== void 0) ctx.userAgentData = base.userAgentData;
654
600
  if (typeof navigator !== "undefined") {
655
601
  ctx.hardwareConcurrency = navigator.hardwareConcurrency;
656
602
  ctx.deviceMemory = navigator.deviceMemory;
@@ -689,6 +635,21 @@ async function getEnvContext() {
689
635
  return ctx;
690
636
  }
691
637
 
638
+ // src/utils/windows-version.ts
639
+ async function getWindowsVersion(nav) {
640
+ var _a;
641
+ if (!nav.userAgentData || nav.userAgentData.platform !== "Windows") {
642
+ return null;
643
+ }
644
+ try {
645
+ const data = await nav.userAgentData.getHighEntropyValues(["platformVersion"]);
646
+ const major = parseInt(((_a = data["platformVersion"]) == null ? void 0 : _a.split(".")[0]) || "0", 10);
647
+ return major >= 13 ? "11" : "10";
648
+ } catch (e) {
649
+ return null;
650
+ }
651
+ }
652
+
692
653
  // src/parse-headers.ts
693
654
  var ACCEPT_CH = [
694
655
  "Sec-CH-UA-Arch",
@@ -743,60 +704,15 @@ function parseHeaders(headers) {
743
704
 
744
705
  // src/index.ts
745
706
  var { version: VERSION } = package_default;
746
- var isWechatMiniapp = () => {
747
- try {
748
- return typeof __wxjs_environment !== "undefined" && __wxjs_environment === "miniprogram";
749
- } catch (e) {
750
- return false;
751
- }
752
- };
753
- var isAlipayMiniapp = () => {
754
- var _a;
755
- try {
756
- return typeof window !== "undefined" && typeof ((_a = window.my) == null ? void 0 : _a.getSystemInfo) === "function";
757
- } catch (e) {
758
- return false;
759
- }
760
- };
761
- var isBaiduMiniapp = () => {
762
- try {
763
- return typeof swan !== "undefined" && typeof (swan == null ? void 0 : swan.getSystemInfo) === "function";
764
- } catch (e) {
765
- return false;
766
- }
767
- };
768
- var isDouyinMiniapp = () => {
769
- try {
770
- return typeof tt !== "undefined" && typeof (tt == null ? void 0 : tt.getSystemInfo) === "function";
771
- } catch (e) {
772
- return false;
773
- }
774
- };
775
- var isQQMiniapp = () => {
776
- try {
777
- return typeof qq !== "undefined" && typeof (qq == null ? void 0 : qq.getSystemInfo) === "function";
778
- } catch (e) {
779
- return false;
780
- }
781
- };
782
- var isKuaishouMiniapp = () => {
783
- try {
784
- return typeof ks !== "undefined" && typeof (ks == null ? void 0 : ks.getSystemInfo) === "function";
785
- } catch (e) {
786
- return false;
787
- }
788
- };
789
707
  function uaBrowser(ua) {
790
708
  const nav = getNavContext();
791
709
  return parseUA(ua != null ? ua : nav.userAgent, { nav });
792
710
  }
711
+ uaBrowser.detect = async (ua) => {
712
+ const ctx = await getEnvContext();
713
+ return parseUA(ua != null ? ua : ctx.userAgent, { ctx });
714
+ };
793
715
  uaBrowser.isWebview = isWebview;
794
- uaBrowser.isWechatMiniapp = isWechatMiniapp;
795
- uaBrowser.isAlipayMiniapp = isAlipayMiniapp;
796
- uaBrowser.isBaiduMiniapp = isBaiduMiniapp;
797
- uaBrowser.isDouyinMiniapp = isDouyinMiniapp;
798
- uaBrowser.isQQMiniapp = isQQMiniapp;
799
- uaBrowser.isKuaishouMiniapp = isKuaishouMiniapp;
800
716
  uaBrowser.getLanguage = () => getLanguage(getNavContext());
801
717
  uaBrowser.VERSION = VERSION;
802
718
  var src_default = uaBrowser;
@@ -811,13 +727,7 @@ exports.getEnvContext = getEnvContext;
811
727
  exports.getLanguage = getLanguage;
812
728
  exports.getNavContext = getNavContext;
813
729
  exports.getWindowsVersion = getWindowsVersion;
814
- exports.isAlipayMiniapp = isAlipayMiniapp;
815
- exports.isBaiduMiniapp = isBaiduMiniapp;
816
- exports.isDouyinMiniapp = isDouyinMiniapp;
817
- exports.isKuaishouMiniapp = isKuaishouMiniapp;
818
- exports.isQQMiniapp = isQQMiniapp;
819
730
  exports.isWebview = isWebview;
820
- exports.isWechatMiniapp = isWechatMiniapp;
821
731
  exports.parseHeaders = parseHeaders;
822
732
  exports.parseUA = parseUA;
823
733
  //# sourceMappingURL=index.cjs.map