Repository: nodejs/nodejs.dev
Pull request #3163 (2023-01-20 17:01:57)

fix(downloadUrlByOS): windows 64 bit
## Description

Fixes an issue where 64 bit windows would incorrectly download the 32 bit Node.js 

We cannot use `navigator.appVersion` since it no longer contains WOW64 or Win64.

## Related Issues

- Fixes https://github.com/nodejs/nodejs.dev/issues/3162

### Check List

<!--
ATTENTION
Please follow this check list to ensure that you've followed all items before opening this PR
-->

- [x] I have read the [Contributing Guidelines](https://github.com/nodejs/nodejs.dev/blob/main/CONTRIBUTING.md) and made commit messages that follow the guideline.
- [x] I have run `npm run lint:js -- --fix` and/or `npm run lint:md -- --fix` for my JavaScript and/or Markdown changes.
  - This is important as most of the cases your code changes might not be correctly linted
- [x] I have run `npm run test` to check if all tests are passing, and/or `npm run test -- -u` to update snapshots if I created and/or updated React Components.
- [x] I have checked that the build works locally and that `npm run build` work fine.
- [x] I've covered new added functionality with unit tests if necessary.


codecov-commenter: # [Codecov](https://codecov.io/gh/nodejs/nodejs.dev/pull/3163?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
Base: **66.02**% // Head: **66.31**% // Increases project coverage by **`+0.28%`** :tada:
> Coverage data is based on head [(`aaef8fa`)](https://codecov.io/gh/nodejs/nodejs.dev/pull/3163?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) compared to base [(`fd57b87`)](https://codecov.io/gh/nodejs/nodejs.dev/commit/fd57b871c2b1ad2f6fb812ed066dec074d76db22?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).
> Patch has no changes to coverable lines.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #3163      +/-   ##
==========================================
+ Coverage   66.02%   66.31%   +0.28%     
==========================================
  Files         118      145      +27     
  Lines        1351     1698     +347     
  Branches      342      389      +47     
==========================================
+ Hits          892     1126     +234     
- Misses        422      528     +106     
- Partials       37       44       +7     
```


| [Impacted Files](https://codecov.io/gh/nodejs/nodejs.dev/pull/3163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [src/templates/blog.tsx](https://codecov.io/gh/nodejs/nodejs.dev/pull/3163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3RlbXBsYXRlcy9ibG9nLnRzeA==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [util-node/getNodeReleasesData.js](https://codecov.io/gh/nodejs/nodejs.dev/pull/3163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-dXRpbC1ub2RlL2dldE5vZGVSZWxlYXNlc0RhdGEuanM=) | `91.30% <0.00%> (-6.32%)` | :arrow_down: |
| [src/\_\_fixtures\_\_/page.tsx](https://codecov.io/gh/nodejs/nodejs.dev/pull/3163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL19fZml4dHVyZXNfXy9wYWdlLnRzeA==) | `94.11% <0.00%> (-5.89%)` | :arrow_down: |
| [src/pages/index.tsx](https://codecov.io/gh/nodejs/nodejs.dev/pull/3163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3BhZ2VzL2luZGV4LnRzeA==) | `100.00% <0.00%> (ø)` | |
| [src/templates/api.tsx](https://codecov.io/gh/nodejs/nodejs.dev/pull/3163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3RlbXBsYXRlcy9hcGkudHN4) | `0.00% <0.00%> (ø)` | |
| [src/templates/learn.tsx](https://codecov.io/gh/nodejs/nodejs.dev/pull/3163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3RlbXBsYXRlcy9sZWFybi50c3g=) | `100.00% <0.00%> (ø)` | |
| [util-node/createSlug.js](https://codecov.io/gh/nodejs/nodejs.dev/pull/3163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-dXRpbC1ub2RlL2NyZWF0ZVNsdWcuanM=) | `100.00% <0.00%> (ø)` | |
| [util-node/getNvmData.js](https://codecov.io/gh/nodejs/nodejs.dev/pull/3163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-dXRpbC1ub2RlL2dldE52bURhdGEuanM=) | `100.00% <0.00%> (ø)` | |
| [src/hooks/useOnScreen.tsx](https://codecov.io/gh/nodejs/nodejs.dev/pull/3163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL2hvb2tzL3VzZU9uU2NyZWVuLnRzeA==) | `100.00% <0.00%> (ø)` | |
| [src/pages/about/index.tsx](https://codecov.io/gh/nodejs/nodejs.dev/pull/3163?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3BhZ2VzL2Fib3V0L2luZGV4LnRzeA==) | `100.00% <0.00%> (ø)` | |
| ... and [186 more](https://codecov.io/gh/nodejs/nodejs.dev/pull/3163?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/nodejs/nodejs.dev/pull/3163?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).


Patch:
diff --git a/src/hooks/useDetectOs.ts b/src/hooks/useDetectOs.ts
index 704c9b04..b14b8fd3 100644
--- a/src/hooks/useDetectOs.ts
+++ b/src/hooks/useDetectOs.ts
@@ -4,11 +4,27 @@ import downloadUrlByOS from '../util/downloadUrlByOS';
 
 export const useDetectOs = () => {
   const [userOS, setUserOS] = useState<UserOS>(UserOS.UNKNOWN);
+  const [bitness, setBitness] = useState('');
 
-  useEffect(() => setUserOS(detectOS), []);
+  useEffect(() => {
+    setUserOS(detectOS);
+
+    // This is necessary to detect Windows 11 on Edge.
+    // [MDN](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/getHighEntropyValues)
+    // [MSFT](https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11)
+    // @ts-expect-error no types for "userAgentData" because this API is experimental
+    if (typeof navigator.userAgentData?.getHighEntropyValues === 'function') {
+      // @ts-expect-error no types for "userAgentData" because this API is experimental
+      navigator.userAgentData
+        .getHighEntropyValues(['bitness'])
+        .then((ua: { bitness: string }) => setBitness(ua.bitness))
+        .catch();
+    }
+  }, []);
 
   return {
     userOS,
-    getDownloadLink: (version: string) => downloadUrlByOS(userOS, version),
+    getDownloadLink: (version: string) =>
+      downloadUrlByOS(userOS, version, bitness),
   };
 };
diff --git a/src/util/downloadUrlByOS.ts b/src/util/downloadUrlByOS.ts
index 28c1bc1b..66e0b66f 100644
--- a/src/util/downloadUrlByOS.ts
+++ b/src/util/downloadUrlByOS.ts
@@ -2,7 +2,8 @@ import { UserOS } from './detectOS';
 
 export default function downloadUrlByOS(
   userOS: UserOS,
-  version: string
+  version: string,
+  bitness?: string
 ): string {
   const baseURL = `https://nodejs.org/dist/${version}`;
 
@@ -16,6 +17,7 @@ export default function downloadUrlByOS(
 
   if (userOS === UserOS.WIN) {
     if (
+      bitness === '64' ||
       navigator.appVersion.includes('WOW64') ||
       navigator.appVersion.includes('Win64')
     ) {


Test patch:
diff --git a/src/util/__tests__/downloadUrlByOS.test.ts b/src/util/__tests__/downloadUrlByOS.test.ts
index 1a2a00d8..5ee7540f 100644
--- a/src/util/__tests__/downloadUrlByOS.test.ts
+++ b/src/util/__tests__/downloadUrlByOS.test.ts
@@ -39,6 +39,12 @@ describe('downloadUrlByOS', () => {
         'https://nodejs.org/dist/version-mock/node-version-mock-x86.msi'
       );
     });
+
+    it('should return correct url for Windows 11 on Edge', () => {
+      expect(downloadUrlByOS(UserOS.WIN, 'version-mock', '64')).toBe(
+        'https://nodejs.org/dist/version-mock/node-version-mock-x64.msi'
+      );
+    });
   });
 
   it('should return correct url for Mobile', () => {