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