()
| 51 | * @see https://developer.mozilla.org/en-US/docs/Web/API/User-Agent_Client_Hints_API |
| 52 | */ |
| 53 | export default async function getUserAgentData(): Promise<StableUserAgentData | undefined> { |
| 54 | const uaData = (navigator as unknown as { userAgentData?: NavigatorUAData }).userAgentData |
| 55 | |
| 56 | if (!uaData) { |
| 57 | return undefined |
| 58 | } |
| 59 | |
| 60 | const filteredBrands = uaData.brands.filter(({ brand }) => !isGreaseBrand(brand)).map(({ brand }) => brand) |
| 61 | |
| 62 | const brands = filteredBrands.length > 1 ? filteredBrands.filter((b) => b !== 'Chromium') : filteredBrands |
| 63 | |
| 64 | const result: StableUserAgentData = { |
| 65 | brands, |
| 66 | mobile: uaData.mobile, |
| 67 | platform: uaData.platform, |
| 68 | } |
| 69 | |
| 70 | if (uaData.getHighEntropyValues) { |
| 71 | try { |
| 72 | const highEntropy = await uaData.getHighEntropyValues(['architecture', 'bitness', 'model', 'platformVersion']) |
| 73 | result.architecture = highEntropy.architecture |
| 74 | result.bitness = highEntropy.bitness |
| 75 | result.model = highEntropy.model |
| 76 | result.platformVersion = highEntropy.platformVersion |
| 77 | } catch (error) { |
| 78 | if (error instanceof DOMException && error.name === 'NotAllowedError') { |
| 79 | result.highEntropyStatus = HighEntropyStatus.NotAllowed |
| 80 | } else { |
| 81 | throw error |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | return result |
| 87 | } |
no test coverage detected
searching dependent graphs…