Created
May 3, 2026 23:34
-
-
Save milksense/37f23df479c2f51f9d19d7249043d519 to your computer and use it in GitHub Desktop.
Detect Windows ARM64 using the UA Client Hints API (navigator.userAgentData)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Detect Windows ARM64 using the UA Client Hints API (navigator.userAgentData). | |
| // The legacy navigator.userAgent string is unreliable for distinguishing ARM64 | |
| // from x64 on Windows — Chrome and Edge on ARM64 report "x64" because they | |
| // run x86-emulated, so the UA string says "Win64; x64" on both architectures. | |
| // getHighEntropyValues() provides the real hardware architecture. | |
| async function detectWindowsTarget() { | |
| try { | |
| if (navigator.userAgentData) { | |
| var hints = await navigator.userAgentData.getHighEntropyValues( | |
| ["platform", "architecture", "bitness"] | |
| ); | |
| if (hints.platform === "Windows" | |
| && hints.architecture === "arm" | |
| && hints.bitness === "64") { | |
| return "aarch64-pc-windows-msvc"; | |
| } | |
| } | |
| } catch (_) { | |
| // userAgentData unavailable, denied, or threw — fall through to default | |
| } | |
| return "x86_64-pc-windows-msvc"; | |
| } | |
| async function setupDownloadLink() { | |
| var mainBtn = document.getElementById("download-main"); | |
| var altEl = document.getElementById("alt-download"); | |
| if (!mainBtn) return; | |
| var target = await detectWindowsTarget(); | |
| if (target !== "aarch64-pc-windows-msvc") return; // x64 is already the default | |
| // Swap: main button → ARM64, secondary link → x64 | |
| var arm64Url = mainBtn.getAttribute("data-arm64-url"); | |
| var x64Url = mainBtn.getAttribute("data-x64-url"); | |
| if (!arm64Url) return; | |
| mainBtn.href = arm64Url; | |
| mainBtn.textContent = "Download for Windows (ARM64)"; | |
| if (altEl && x64Url) { | |
| var link = document.createElement("a"); | |
| link.href = x64Url; | |
| link.download = ""; | |
| link.textContent = "Windows x64"; | |
| altEl.textContent = "Also available: "; | |
| altEl.appendChild(link); | |
| } | |
| } | |
| setupDownloadLink(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment