3

I have code to detect operating system:

            var isPC = isWindows();
            function isWindows(){
                return navigator.platform.indexOf('Win') > -1
            }

            var isMAC = isMac();
            function isMac(){
                return navigator.platform.indexOf('Mac') > -1
            }

            var isLINUX = isLinux();
            function isLinux(){
                return navigator.platform.indexOf('Linux') > -1
            }

but I don't know (can't find) the navigator.platform value for Chrome OS, does anyone know?

PATurmel
  • 77
  • 1
  • 5
  • CrOS according to the following article: https://stackoverflow.com/questions/7385479/how-to-detect-chromium-os-using-javascript – user3051640 Mar 08 '19 at 22:26
  • According to [this post](https://stackoverflow.com/a/19883965), it returns "Linux i686". But that post is not updated since 2015. – Ivar Mar 08 '19 at 22:31
  • @user3051640 That post shows what `navigator.userAgent` (among others) contains. That's not necessarily what `navigator.platform` returns. You might be right, but that's not clear from that post. – Ivar Mar 08 '19 at 22:33
  • so I guess a combination of navigator.platform = "Linux" and navigator.userAgent contains CrOS. – PATurmel Mar 09 '19 at 03:21

1 Answers1

-1

navigator.platform does not return a string that uniquely identifies ChromeOS.

Using the JavaScript console on Google Chrome in my Chromebook (HP Chromebook 11), navigator.platform returns:

navigator.platform "Linux X86_64"

Instead use navigator.userAgent.

navigator.userAgent returns a substring "CrOS X86_64" that is unique to ChromeOS. Sample return value from the JavaScript console on Google Chrome for my HP Chromebook 11 is below.

navigator.userAgent "Mozilla/5.x (X11; CrOS X86_64 13904.97.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.167 Safari/537.36"

Steve Pao
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 27 '21 at 22:19