ua-browser 1.0.2 → 1.2.0
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/dist/index.cjs +314 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +106 -10
- package/dist/index.d.ts +106 -10
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +307 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -1
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.0
|
|
7
|
+
version: "1.2.0"};
|
|
8
8
|
|
|
9
9
|
// src/constants/browsers.ts
|
|
10
10
|
var BROWSER_DEFS = [
|
|
@@ -22,14 +22,9 @@ var BROWSER_DEFS = [
|
|
|
22
22
|
{ name: "Samsung Internet", priority: 92, detect: /SamsungBrowser/, versionPattern: /SamsungBrowser\/([\d.]+)/ },
|
|
23
23
|
{ name: "DuckDuckGo", priority: 94, detect: /DuckDuckGo\//, versionPattern: /DuckDuckGo\/([\d.]+)/ },
|
|
24
24
|
{ name: "Puffin", priority: 96, detect: /Puffin\//, versionPattern: /Puffin\/([\d.]+)/ },
|
|
25
|
-
{ name: "Arora", priority: 100, detect: /Arora/, versionPattern: /Arora\/([\d.]+)/ },
|
|
26
|
-
{ name: "Lunascape", priority: 110, detect: /Lunascape/, versionPattern: /Lunascape[\s]([\d.]+)/ },
|
|
27
|
-
{ name: "QupZilla", priority: 120, detect: /QupZilla/, versionPattern: /QupZilla[\s]([\d.]+)/ },
|
|
28
25
|
{ name: "Coc Coc", priority: 130, detect: /coc_coc_browser/, versionPattern: /coc_coc_browser\/([\d.]+)/ },
|
|
29
26
|
{ name: "Kindle", priority: 140, detect: /(Kindle|Silk\/)/, versionPattern: /Version\/([\d.]+)/ },
|
|
30
|
-
{ name: "Iceweasel", priority: 150, detect: /Iceweasel/, versionPattern: /Iceweasel\/([\d.]+)/ },
|
|
31
27
|
{ name: "Konqueror", priority: 160, detect: /Konqueror/, versionPattern: /Konqueror\/([\d.]+)/ },
|
|
32
|
-
{ name: "Iceape", priority: 170, detect: /Iceape/, versionPattern: /Iceape\/([\d.]+)/ },
|
|
33
28
|
{ name: "SeaMonkey", priority: 180, detect: /SeaMonkey/, versionPattern: /SeaMonkey\/([\d.]+)/ },
|
|
34
29
|
{ name: "Epiphany", priority: 190, detect: /Epiphany/, versionPattern: /Epiphany\/([\d.]+)/ },
|
|
35
30
|
{ name: "Maxthon", priority: 200, detect: /Maxthon/, versionPattern: /Maxthon\/([\d.]+)/ },
|
|
@@ -114,7 +109,14 @@ var BROWSER_DEFS = [
|
|
|
114
109
|
{ name: "Suning", priority: 560, detect: /SNEBUY-APP/, versionPattern: /SNEBUY-APP([\d.]+)/ },
|
|
115
110
|
{ name: "iQiYi", priority: 570, detect: /IqiyiApp/, versionPattern: /IqiyiVersion\/([\d.]+)/ },
|
|
116
111
|
{ name: "DingTalk", priority: 580, detect: /DingTalk/, versionPattern: /DingTalk\/([\d.]+)/ },
|
|
117
|
-
{ name: "Douyin", priority: 590, detect: /aweme/, versionPattern: /app_version\/([\d.]+)/ }
|
|
112
|
+
{ name: "Douyin", priority: 590, detect: /aweme/, versionPattern: /app_version\/([\d.]+)/ },
|
|
113
|
+
{ name: "Bilibili", priority: 592, detect: /BiliBili\//, versionPattern: /BiliBili\/([\d.]+)/ },
|
|
114
|
+
{ name: "Kuaishou", priority: 594, detect: /Kwai\//, versionPattern: /Kwai\/([\d.]+)/ },
|
|
115
|
+
{ name: "Xiaohongshu", priority: 596, detect: /Xiaohongshu\//, versionPattern: /Xiaohongshu\/([\d.]+)/ },
|
|
116
|
+
{ name: "Feishu", priority: 597, detect: /(Lark|Feishu)\//, versionPattern: [/Lark\/([\d.]+)/, /Feishu\/([\d.]+)/] },
|
|
117
|
+
{ name: "Toutiao", priority: 598, detect: /NewsArticle\//, versionPattern: /NewsArticle\/([\d.]+)/ },
|
|
118
|
+
{ name: "JD", priority: 599, detect: /jdpingou\//, versionPattern: /jdpingou\/([\d.]+)/ },
|
|
119
|
+
{ name: "Meituan", priority: 600, detect: /MeituanHybrid\//, versionPattern: /MeituanHybrid\/([\d.]+)/ }
|
|
118
120
|
];
|
|
119
121
|
|
|
120
122
|
// src/utils/extract.ts
|
|
@@ -166,7 +168,10 @@ var ENGINE_DEFS = [
|
|
|
166
168
|
{ name: "Trident", detect: /(Trident|NET CLR)/ },
|
|
167
169
|
{ name: "Presto", detect: /Presto/ },
|
|
168
170
|
{ name: "Gecko", detect: /Gecko\// },
|
|
169
|
-
{ name: "WebKit", detect: /AppleWebKit/ }
|
|
171
|
+
{ name: "WebKit", detect: /AppleWebKit/ },
|
|
172
|
+
// ArkWeb is HarmonyOS Next's rendering engine; only present in UAs that explicitly contain the
|
|
173
|
+
// token. It must come last so it overrides the WebKit entry that also matches those UAs.
|
|
174
|
+
{ name: "ArkWeb", detect: /ArkWeb/ }
|
|
170
175
|
];
|
|
171
176
|
|
|
172
177
|
// src/detectors/engine.ts
|
|
@@ -209,13 +214,16 @@ var OS_DEFS = [
|
|
|
209
214
|
{ name: "MacOS", detect: /Macintosh/, versionPattern: /Mac OS X -?([\d_.]+)/ },
|
|
210
215
|
{ name: "Android", detect: /(Android|Adr)/, versionPattern: /(?:Android|Adr) ([\d.]+)/ },
|
|
211
216
|
// HarmonyOS must come after Android: HarmonyOS UAs include "Android", so Android matches
|
|
212
|
-
// first, then HarmonyOS overrides it.
|
|
217
|
+
// first, then HarmonyOS overrides it. versionPattern tries direct extraction first (5.0+
|
|
218
|
+
// pure HarmonyOS UAs don't have Android token), then falls back to Android version + lookup.
|
|
213
219
|
{
|
|
214
220
|
name: "HarmonyOS",
|
|
215
221
|
detect: /HarmonyOS/,
|
|
216
|
-
versionPattern: /Android ([\d.]+)[;)]
|
|
217
|
-
versionLookup: { "10": "2" }
|
|
222
|
+
versionPattern: [/HarmonyOS[\s/]([\d.]+)/, /Android ([\d.]+)[;)]/],
|
|
223
|
+
versionLookup: { "10": "2", "11": "3", "12": "3", "13": "4" }
|
|
218
224
|
},
|
|
225
|
+
// OpenHarmony (open-source base) must come after HarmonyOS to override any earlier match.
|
|
226
|
+
{ name: "OpenHarmony", detect: /OpenHarmony/, versionPattern: /OpenHarmony[\s/]([\d.]+)/ },
|
|
219
227
|
{ name: "KaiOS", detect: /KAIOS/, versionPattern: /KAIOS\/([\d.]+)/ },
|
|
220
228
|
// Windows must come before Windows Phone: Windows Phone UAs contain "Windows", so Windows
|
|
221
229
|
// matches first, then Windows Phone overrides it.
|
|
@@ -249,7 +257,7 @@ function detectOs(ua, windowsVersion) {
|
|
|
249
257
|
if (!matchedDef) return { os: "unknown", osVersion: "unknown" };
|
|
250
258
|
let osVersion = "unknown";
|
|
251
259
|
if (matchedDef.versionPattern) {
|
|
252
|
-
const raw = extractVersion(ua, matchedDef.versionPattern);
|
|
260
|
+
const raw = Array.isArray(matchedDef.versionPattern) ? extractVersionFromPatterns(ua, matchedDef.versionPattern) : extractVersion(ua, matchedDef.versionPattern);
|
|
253
261
|
if (raw !== null) {
|
|
254
262
|
const normalised = raw.replace(/_/g, ".");
|
|
255
263
|
if (matchedDef.versionLookup) {
|
|
@@ -259,6 +267,8 @@ function detectOs(ua, windowsVersion) {
|
|
|
259
267
|
} else if (matchedDef.name === "Windows") {
|
|
260
268
|
const n = parseInt(normalised, 10);
|
|
261
269
|
osVersion = isNaN(n) ? "unknown" : n.toString();
|
|
270
|
+
} else {
|
|
271
|
+
osVersion = normalised;
|
|
262
272
|
}
|
|
263
273
|
} else {
|
|
264
274
|
osVersion = normalised;
|
|
@@ -350,7 +360,33 @@ var ARCH_DEFS = [
|
|
|
350
360
|
];
|
|
351
361
|
|
|
352
362
|
// src/detectors/arch.ts
|
|
353
|
-
function detectArch(ua) {
|
|
363
|
+
function detectArch(ua, ctx) {
|
|
364
|
+
if (ctx == null ? void 0 : ctx.highEntropyData) {
|
|
365
|
+
const { architecture, bitness } = ctx.highEntropyData;
|
|
366
|
+
if (architecture === "arm") {
|
|
367
|
+
return bitness === "64" ? "arm64" : "arm";
|
|
368
|
+
}
|
|
369
|
+
if (architecture === "x86") {
|
|
370
|
+
return bitness === "64" ? "x86_64" : "x86";
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const renderer = ctx == null ? void 0 : ctx.webglRenderer;
|
|
374
|
+
if (renderer) {
|
|
375
|
+
if (/Apple\s+(M\d|A\d{1,2}[A-Z]?)\b/i.test(renderer) || /APPLE M\d/i.test(renderer)) {
|
|
376
|
+
return "arm64";
|
|
377
|
+
}
|
|
378
|
+
if (/\b(Intel|AMD|NVIDIA|Radeon)\b/i.test(renderer)) {
|
|
379
|
+
return "x86_64";
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
const platform = ctx == null ? void 0 : ctx.platform;
|
|
383
|
+
if (platform) {
|
|
384
|
+
if (/iPhone|iPad|iPod/.test(platform)) return "arm64";
|
|
385
|
+
if (/arm64|aarch64/i.test(platform)) return "arm64";
|
|
386
|
+
if (/arm/i.test(platform)) return "arm";
|
|
387
|
+
if (/Win64|WOW64|x86_64/i.test(platform)) return "x86_64";
|
|
388
|
+
if (/Win32|i686/i.test(platform)) return "x86";
|
|
389
|
+
}
|
|
354
390
|
for (const def of ARCH_DEFS) {
|
|
355
391
|
if (def.detect.test(ua)) {
|
|
356
392
|
return def.name;
|
|
@@ -365,6 +401,13 @@ function detectHeadless(ua) {
|
|
|
365
401
|
return HEADLESS_PATTERN.test(ua);
|
|
366
402
|
}
|
|
367
403
|
|
|
404
|
+
// src/detectors/webview.ts
|
|
405
|
+
function isWebview(ua) {
|
|
406
|
+
if (/; wv/.test(ua)) return true;
|
|
407
|
+
if (/like Mac OS X/.test(ua) && !/Version\//.test(ua) && !/Safari\//.test(ua)) return true;
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
|
|
368
411
|
// src/utils/navigator.ts
|
|
369
412
|
function getNavContext() {
|
|
370
413
|
if (typeof navigator === "undefined") {
|
|
@@ -389,17 +432,19 @@ function getLanguage(nav) {
|
|
|
389
432
|
|
|
390
433
|
// src/parse.ts
|
|
391
434
|
function parseUA(ua, options = {}) {
|
|
392
|
-
var _a, _b, _c, _d, _e;
|
|
393
|
-
const
|
|
435
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
436
|
+
const effectiveNav = (_a = options.ctx) != null ? _a : options.nav;
|
|
437
|
+
const effectiveWindowsVersion = (_c = (_b = options.ctx) == null ? void 0 : _b.windowsVersion) != null ? _c : options.windowsVersion;
|
|
394
438
|
const { browser: rawBrowser, version: rawVersion } = detectBrowser(ua);
|
|
395
|
-
const { os, osVersion: rawOsVersion } = detectOs(ua,
|
|
439
|
+
const { os, osVersion: rawOsVersion } = detectOs(ua, effectiveWindowsVersion);
|
|
396
440
|
let osVersion = rawOsVersion;
|
|
397
|
-
const device = detectDevice(ua,
|
|
398
|
-
const arch = detectArch(ua);
|
|
441
|
+
const device = detectDevice(ua, effectiveNav);
|
|
442
|
+
const arch = detectArch(ua, options.ctx);
|
|
443
|
+
const nav = effectiveNav;
|
|
399
444
|
const { isBot, botName } = detectBot(ua);
|
|
400
445
|
const isHeadless = detectHeadless(ua);
|
|
401
446
|
const language = nav ? getLanguage(nav) : "unknown";
|
|
402
|
-
const platform = (
|
|
447
|
+
const platform = (_d = nav == null ? void 0 : nav.platform) != null ? _d : "unknown";
|
|
403
448
|
let browser = rawBrowser;
|
|
404
449
|
let version = rawVersion;
|
|
405
450
|
if (nav) {
|
|
@@ -421,7 +466,7 @@ function parseUA(ua, options = {}) {
|
|
|
421
466
|
}
|
|
422
467
|
}
|
|
423
468
|
if (is360) {
|
|
424
|
-
const saveDataEnabled = ((
|
|
469
|
+
const saveDataEnabled = ((_e = nav.connection) == null ? void 0 : _e.saveData) === true;
|
|
425
470
|
if (getMimeType(nav, "application/gameplugin") || !saveDataEnabled) {
|
|
426
471
|
browser = "360SE";
|
|
427
472
|
} else {
|
|
@@ -434,8 +479,8 @@ function parseUA(ua, options = {}) {
|
|
|
434
479
|
}
|
|
435
480
|
if (browser === "Baidu" && /(Opera|OPR|OPT)/.test(ua)) {
|
|
436
481
|
browser = "Opera";
|
|
437
|
-
const opVer = (
|
|
438
|
-
version = (
|
|
482
|
+
const opVer = (_g = (_f = /OPR\/([\d.]+)/.exec(ua)) != null ? _f : /OPT\/([\d.]+)/.exec(ua)) != null ? _g : /Opera\/([\d.]+)/.exec(ua);
|
|
483
|
+
version = (_h = opVer == null ? void 0 : opVer[1]) != null ? _h : "unknown";
|
|
439
484
|
}
|
|
440
485
|
if (browser === "Chrome" && /\S+Browser\//.test(ua)) {
|
|
441
486
|
const m = /(\S+Browser)\/([\d.]+)/.exec(ua);
|
|
@@ -460,6 +505,46 @@ function parseUA(ua, options = {}) {
|
|
|
460
505
|
} catch (e) {
|
|
461
506
|
}
|
|
462
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
|
+
}
|
|
463
548
|
if (os === "iOS" && browser === "Safari") {
|
|
464
549
|
const m = /Version\/([\d.]+)/.exec(ua);
|
|
465
550
|
if (m && parseInt(m[1], 10) > parseInt(osVersion, 10)) {
|
|
@@ -475,7 +560,7 @@ function parseUA(ua, options = {}) {
|
|
|
475
560
|
osVersion,
|
|
476
561
|
device,
|
|
477
562
|
arch,
|
|
478
|
-
isWebview:
|
|
563
|
+
isWebview: isWebview(ua),
|
|
479
564
|
isHeadless,
|
|
480
565
|
isBot,
|
|
481
566
|
botName,
|
|
@@ -499,9 +584,165 @@ async function getWindowsVersion(nav) {
|
|
|
499
584
|
}
|
|
500
585
|
}
|
|
501
586
|
|
|
587
|
+
// src/utils/env-context.ts
|
|
588
|
+
var OS_FONTS = [
|
|
589
|
+
".AppleSystemUIFont",
|
|
590
|
+
"Segoe UI",
|
|
591
|
+
"Noto Color Emoji",
|
|
592
|
+
"Ubuntu",
|
|
593
|
+
"HarmonyOS Sans"
|
|
594
|
+
];
|
|
595
|
+
function probeFonts() {
|
|
596
|
+
try {
|
|
597
|
+
const canvas = document.createElement("canvas");
|
|
598
|
+
const ctx = canvas.getContext("2d");
|
|
599
|
+
if (!ctx) return {};
|
|
600
|
+
const TEST = "mmmmmmmmmmlli";
|
|
601
|
+
ctx.font = "72px monospace";
|
|
602
|
+
const baseline = ctx.measureText(TEST).width;
|
|
603
|
+
const result = {};
|
|
604
|
+
for (const font of OS_FONTS) {
|
|
605
|
+
ctx.font = `72px '${font}', monospace`;
|
|
606
|
+
result[font] = ctx.measureText(TEST).width !== baseline;
|
|
607
|
+
}
|
|
608
|
+
return result;
|
|
609
|
+
} catch (e) {
|
|
610
|
+
return {};
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
function getWebGLInfo() {
|
|
614
|
+
var _a;
|
|
615
|
+
try {
|
|
616
|
+
const canvas = document.createElement("canvas");
|
|
617
|
+
const gl = (_a = canvas.getContext("webgl")) != null ? _a : canvas.getContext("experimental-webgl");
|
|
618
|
+
if (!gl) return {};
|
|
619
|
+
const ext = gl.getExtension("WEBGL_debug_renderer_info");
|
|
620
|
+
if (!ext) return {};
|
|
621
|
+
return {
|
|
622
|
+
renderer: gl.getParameter(ext.UNMASKED_RENDERER_WEBGL),
|
|
623
|
+
vendor: gl.getParameter(ext.UNMASKED_VENDOR_WEBGL)
|
|
624
|
+
};
|
|
625
|
+
} catch (e) {
|
|
626
|
+
return {};
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
function getPointerType() {
|
|
630
|
+
try {
|
|
631
|
+
if (window.matchMedia("(pointer: coarse)").matches) return "coarse";
|
|
632
|
+
if (window.matchMedia("(pointer: fine)").matches) return "fine";
|
|
633
|
+
if (window.matchMedia("(pointer: none)").matches) return "none";
|
|
634
|
+
} catch (e) {
|
|
635
|
+
}
|
|
636
|
+
return void 0;
|
|
637
|
+
}
|
|
638
|
+
function getHoverCapability() {
|
|
639
|
+
try {
|
|
640
|
+
return window.matchMedia("(hover: hover)").matches;
|
|
641
|
+
} catch (e) {
|
|
642
|
+
return void 0;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
function deriveWindowsVersion(platformVersion) {
|
|
646
|
+
var _a;
|
|
647
|
+
if (!platformVersion) return null;
|
|
648
|
+
const major = parseInt((_a = platformVersion.split(".")[0]) != null ? _a : "0", 10);
|
|
649
|
+
return isNaN(major) ? null : major >= 13 ? "11" : "10";
|
|
650
|
+
}
|
|
651
|
+
async function getEnvContext() {
|
|
652
|
+
const base = getNavContext();
|
|
653
|
+
const ctx = { ...base };
|
|
654
|
+
if (typeof navigator !== "undefined") {
|
|
655
|
+
ctx.hardwareConcurrency = navigator.hardwareConcurrency;
|
|
656
|
+
ctx.deviceMemory = navigator.deviceMemory;
|
|
657
|
+
}
|
|
658
|
+
if (typeof window !== "undefined") {
|
|
659
|
+
ctx.devicePixelRatio = window.devicePixelRatio;
|
|
660
|
+
ctx.pointerType = getPointerType();
|
|
661
|
+
ctx.hoverCapability = getHoverCapability();
|
|
662
|
+
ctx.fontProbes = probeFonts();
|
|
663
|
+
const { renderer, vendor } = getWebGLInfo();
|
|
664
|
+
if (renderer !== void 0) ctx.webglRenderer = renderer;
|
|
665
|
+
if (vendor !== void 0) ctx.webglVendor = vendor;
|
|
666
|
+
}
|
|
667
|
+
if (base.userAgentData) {
|
|
668
|
+
try {
|
|
669
|
+
const data = await base.userAgentData.getHighEntropyValues([
|
|
670
|
+
"architecture",
|
|
671
|
+
"bitness",
|
|
672
|
+
"model",
|
|
673
|
+
"platformVersion",
|
|
674
|
+
"fullVersionList"
|
|
675
|
+
]);
|
|
676
|
+
ctx.highEntropyData = {
|
|
677
|
+
architecture: data["architecture"],
|
|
678
|
+
bitness: data["bitness"],
|
|
679
|
+
model: data["model"],
|
|
680
|
+
platformVersion: data["platformVersion"],
|
|
681
|
+
fullVersionList: data["fullVersionList"]
|
|
682
|
+
};
|
|
683
|
+
if (base.userAgentData.platform === "Windows") {
|
|
684
|
+
ctx.windowsVersion = deriveWindowsVersion(data["platformVersion"]);
|
|
685
|
+
}
|
|
686
|
+
} catch (e) {
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
return ctx;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// src/parse-headers.ts
|
|
693
|
+
var ACCEPT_CH = [
|
|
694
|
+
"Sec-CH-UA-Arch",
|
|
695
|
+
"Sec-CH-UA-Bitness",
|
|
696
|
+
"Sec-CH-UA-Platform-Version",
|
|
697
|
+
"Sec-CH-UA-Model",
|
|
698
|
+
"Sec-CH-UA-Full-Version-List"
|
|
699
|
+
].join(", ");
|
|
700
|
+
function unquote(value) {
|
|
701
|
+
if (value == null) return void 0;
|
|
702
|
+
return value.replace(/^"|"$/g, "").trim() || void 0;
|
|
703
|
+
}
|
|
704
|
+
function deriveWindowsVersion2(platformVersion) {
|
|
705
|
+
var _a;
|
|
706
|
+
if (!platformVersion) return null;
|
|
707
|
+
const major = parseInt((_a = platformVersion.split(".")[0]) != null ? _a : "0", 10);
|
|
708
|
+
return isNaN(major) ? null : major >= 13 ? "11" : "10";
|
|
709
|
+
}
|
|
710
|
+
function parseHeaders(headers) {
|
|
711
|
+
var _a, _b;
|
|
712
|
+
const normalised = {};
|
|
713
|
+
for (const key of Object.keys(headers)) {
|
|
714
|
+
normalised[key.toLowerCase()] = headers[key];
|
|
715
|
+
}
|
|
716
|
+
const get = (name) => {
|
|
717
|
+
const v = normalised[name.toLowerCase()];
|
|
718
|
+
return Array.isArray(v) ? v[0] : v;
|
|
719
|
+
};
|
|
720
|
+
const ua = (_a = get("user-agent")) != null ? _a : "";
|
|
721
|
+
const architecture = unquote(get("sec-ch-ua-arch"));
|
|
722
|
+
const bitness = unquote(get("sec-ch-ua-bitness"));
|
|
723
|
+
const model = unquote(get("sec-ch-ua-model"));
|
|
724
|
+
const platformVersion = unquote(get("sec-ch-ua-platform-version"));
|
|
725
|
+
const platform = (_b = unquote(get("sec-ch-ua-platform"))) != null ? _b : "";
|
|
726
|
+
const highEntropyData = {};
|
|
727
|
+
if (architecture !== void 0) highEntropyData.architecture = architecture;
|
|
728
|
+
if (bitness !== void 0) highEntropyData.bitness = bitness;
|
|
729
|
+
if (model !== void 0) highEntropyData.model = model;
|
|
730
|
+
if (platformVersion !== void 0) highEntropyData.platformVersion = platformVersion;
|
|
731
|
+
const isMobile = get("sec-ch-ua-mobile") === "?1";
|
|
732
|
+
const windowsVersion = platform === "Windows" ? deriveWindowsVersion2(platformVersion) : null;
|
|
733
|
+
const ctx = {
|
|
734
|
+
userAgent: ua,
|
|
735
|
+
platform,
|
|
736
|
+
language: "",
|
|
737
|
+
maxTouchPoints: isMobile ? 1 : 0,
|
|
738
|
+
highEntropyData: Object.keys(highEntropyData).length > 0 ? highEntropyData : void 0,
|
|
739
|
+
windowsVersion
|
|
740
|
+
};
|
|
741
|
+
return parseUA(ua, { ctx });
|
|
742
|
+
}
|
|
743
|
+
|
|
502
744
|
// src/index.ts
|
|
503
745
|
var { version: VERSION } = package_default;
|
|
504
|
-
var isWebview = (ua) => /; wv/.test(ua);
|
|
505
746
|
var isWechatMiniapp = () => {
|
|
506
747
|
try {
|
|
507
748
|
return typeof __wxjs_environment !== "undefined" && __wxjs_environment === "miniprogram";
|
|
@@ -509,26 +750,75 @@ var isWechatMiniapp = () => {
|
|
|
509
750
|
return false;
|
|
510
751
|
}
|
|
511
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
|
+
};
|
|
512
789
|
function uaBrowser(ua) {
|
|
513
790
|
const nav = getNavContext();
|
|
514
791
|
return parseUA(ua != null ? ua : nav.userAgent, { nav });
|
|
515
792
|
}
|
|
516
793
|
uaBrowser.isWebview = isWebview;
|
|
517
794
|
uaBrowser.isWechatMiniapp = isWechatMiniapp;
|
|
795
|
+
uaBrowser.isAlipayMiniapp = isAlipayMiniapp;
|
|
796
|
+
uaBrowser.isBaiduMiniapp = isBaiduMiniapp;
|
|
797
|
+
uaBrowser.isDouyinMiniapp = isDouyinMiniapp;
|
|
798
|
+
uaBrowser.isQQMiniapp = isQQMiniapp;
|
|
799
|
+
uaBrowser.isKuaishouMiniapp = isKuaishouMiniapp;
|
|
518
800
|
uaBrowser.getLanguage = () => getLanguage(getNavContext());
|
|
519
801
|
uaBrowser.VERSION = VERSION;
|
|
520
802
|
var src_default = uaBrowser;
|
|
521
803
|
|
|
804
|
+
exports.ACCEPT_CH = ACCEPT_CH;
|
|
522
805
|
exports.VERSION = VERSION;
|
|
523
806
|
exports.default = src_default;
|
|
524
807
|
exports.detectArch = detectArch;
|
|
525
808
|
exports.detectBot = detectBot;
|
|
526
809
|
exports.detectHeadless = detectHeadless;
|
|
810
|
+
exports.getEnvContext = getEnvContext;
|
|
527
811
|
exports.getLanguage = getLanguage;
|
|
528
812
|
exports.getNavContext = getNavContext;
|
|
529
813
|
exports.getWindowsVersion = getWindowsVersion;
|
|
814
|
+
exports.isAlipayMiniapp = isAlipayMiniapp;
|
|
815
|
+
exports.isBaiduMiniapp = isBaiduMiniapp;
|
|
816
|
+
exports.isDouyinMiniapp = isDouyinMiniapp;
|
|
817
|
+
exports.isKuaishouMiniapp = isKuaishouMiniapp;
|
|
818
|
+
exports.isQQMiniapp = isQQMiniapp;
|
|
530
819
|
exports.isWebview = isWebview;
|
|
531
820
|
exports.isWechatMiniapp = isWechatMiniapp;
|
|
821
|
+
exports.parseHeaders = parseHeaders;
|
|
532
822
|
exports.parseUA = parseUA;
|
|
533
823
|
//# sourceMappingURL=index.cjs.map
|
|
534
824
|
//# sourceMappingURL=index.cjs.map
|