@@ -80,16 +80,43 @@ const listenScrollToTopButton = () => {
8080 } ) ;
8181} ;
8282
83- const detectEnviromentAndSetDownloadOptions = ( ) => {
83+ const detectEnviromentAndSetDownloadOptions = async ( ) => {
8484 const userAgent = navigator . userAgent ;
85+ const userAgentData = navigator . userAgentData ;
8586 const osMatch = userAgent . match ( / ( W i n | M a c | L i n u x ) / ) ;
86-
8787 const os = ( osMatch && osMatch [ 1 ] ) || '' ;
8888
89- const arch =
90- userAgent . match ( / x 8 6 _ 6 4 | W i n 6 4 | W O W 6 4 / ) || navigator . cpuClass === 'x64'
91- ? 'x64'
92- : 'x86' ;
89+ // detects the architecture through regular ways on user agents that
90+ // expose the architecture and platform information
91+ // @note this is not available on Windows11 anymore
92+ // @see https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11
93+ let arch = userAgent . match ( / x 8 6 _ 6 4 | W i n 6 4 | W O W 6 4 / ) ? 'x64' : 'x86' ;
94+
95+ // detects the platform through a legacy property on navigator
96+ // available only on firefox
97+ // @see https://developer.mozilla.org/en-US/docs/Web/API/Navigator/oscpu
98+ if ( navigator . oscpu && navigator . oscpu . length ) {
99+ arch = navigator . oscpu . match ( / x 8 6 _ 6 4 | W i n 6 4 | W O W 6 4 / ) ? 'x64' : 'x86' ;
100+ }
101+
102+ // detects the platform through a legacy property on navigator
103+ // only available on internet explorer
104+ if ( navigator . cpuClass && navigator . cpuClass . length ) {
105+ arch = navigator . cpuClass === 'x64' ? 'x64' : 'x86' ;
106+ }
107+
108+ // detects the architecture and other platform data on the navigator
109+ // available only on Chromium-based browsers
110+ // @see https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/getHighEntropyValues
111+ if ( userAgentData && userAgentData . getHighEntropyValues ) {
112+ // note that getHighEntropyValues returns an object
113+ const platform = await userAgentData . getHighEntropyValues ( [ 'bitness' ] ) ;
114+
115+ if ( platform && platform . bitness ) {
116+ // note that platform.bitness returns a string
117+ arch = platform . bitness === '64' ? 'x64' : 'x86' ;
118+ }
119+ }
93120
94121 const buttons = document . querySelectorAll ( '.home-downloadbutton' ) ;
95122 const downloadHead = document . querySelector ( '#home-downloadhead' ) ;
0 commit comments