( hints: T )
| 60 | * @see https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11 |
| 61 | */ |
| 62 | export const getHighEntropyValues = async <T extends Array<keyof UADataValues>>( |
| 63 | hints: T |
| 64 | ): Promise<{ [K in T[number]]: UADataValues[K] }> => { |
| 65 | let result: UADataValues = EMPTY_UA_DATA; |
| 66 | |
| 67 | // Check if the User-Agent Client Hints API is available |
| 68 | if (typeof navigator?.userAgentData?.getHighEntropyValues === 'function') { |
| 69 | try { |
| 70 | const entropyValues = navigator.userAgentData.getHighEntropyValues(hints); |
| 71 | // Handle both Promise and non-Promise return values |
| 72 | result = await Promise.resolve(entropyValues); |
| 73 | } catch { |
| 74 | // Fallback to empty object if the API call fails |
| 75 | result = EMPTY_UA_DATA; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // Map hints to their values, filtering out empty strings |
| 80 | const mappedResult = hints.map(hint => [ |
| 81 | hint, |
| 82 | hint in result && result[hint] ? result[hint] : undefined, |
| 83 | ]); |
| 84 | |
| 85 | return Object.fromEntries(mappedResult) as { |
| 86 | [K in T[number]]: UADataValues[K]; |
| 87 | }; |
| 88 | }; |
no outgoing calls
no test coverage detected