MCPcopy Create free account
hub / github.com/nodejs/nodejs.org / getHighEntropyValues

Function getHighEntropyValues

apps/site/util/userAgent.ts:62–88  ·  view source on GitHub ↗
(
  hints: T
)

Source from the content-addressed store, hash-verified

60 * @see https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11
61 */
62export 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};

Callers 2

useDetectOSFunction · 0.90
userAgent.test.mjsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected