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