Search code examples
javascriptlinuxgoogle-chromewindownavigator

How to detect whether Chrome is installed on Linux via JavaScript?


I have a bug in my app, that appears only on the Chrome installed on Linux. Everything works fine in all other browsers and on android, but on Linux Chrome I have a bug. How to get around this? I can detect chrome via window.chrome but if I check window.navigator.platform.slice(0, 5) == 'Linux' it will returns true also on Android, and I do not want it. What to do?


Solution

  • You can simply add an extra check to see if the user is on android with the following code:

    var isAndroid = navigator.userAgent.toLowerCase().indexOf("android") > -1; 
    var isLinux = navigator.platform.slice(0, 5) == 'Linux';
                  
    if(!isAndroid) { 
      console.log("Device is NOT Android Phone"); 
      if(isLinux) {
        /* This code will run on Linux but not on Android devices */
      }
    }