enhance: getHighEntropyValuesが使用できなかった場合のフォールバックを追加
This commit is contained in:
parent
21fb769f95
commit
ec4fc20ce4
|
@ -2,6 +2,11 @@
|
|||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import type * as Bowser_TR from 'bowser';
|
||||
|
||||
type Bowser_TypeReferenceOnly = typeof Bowser_TR;
|
||||
|
||||
let Bowser: Bowser_TypeReferenceOnly | null = null;
|
||||
|
||||
export type UserEnvironment = {
|
||||
os: string;
|
||||
|
@ -13,6 +18,7 @@ export type UserEnvironment = {
|
|||
|
||||
export async function getUserEnvironment(): Promise<UserEnvironment> {
|
||||
if ('userAgentData' in navigator && navigator.userAgentData != null) {
|
||||
try {
|
||||
const uaData: any = await navigator.userAgentData.getHighEntropyValues([
|
||||
'fullVersionList',
|
||||
'platformVersion',
|
||||
|
@ -40,8 +46,18 @@ export async function getUserEnvironment(): Promise<UserEnvironment> {
|
|||
screenHeight: window.innerHeight,
|
||||
viaGetHighEntropyValues: true,
|
||||
};
|
||||
} catch {
|
||||
return getViaUa();
|
||||
}
|
||||
} else {
|
||||
const Bowser = (await import('bowser')).default;
|
||||
return getViaUa();
|
||||
}
|
||||
}
|
||||
|
||||
async function getViaUa(): Promise<UserEnvironment> {
|
||||
if (Bowser == null) {
|
||||
Bowser = (await import('bowser')).default;
|
||||
}
|
||||
const parsed = Bowser.parse(navigator.userAgent);
|
||||
return {
|
||||
os: `${parsed.os.name ?? 'Unknown'} ${parsed.os.version ?? ''} ${parsed.os.versionName ? `(${parsed.os.versionName})` : ''}`.trim(),
|
||||
|
@ -50,5 +66,4 @@ export async function getUserEnvironment(): Promise<UserEnvironment> {
|
|||
screenHeight: window.innerHeight,
|
||||
viaGetHighEntropyValues: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue