Search code examples
javascripthtmlgoogle-chromebrowser-detection

JavaScript: How to find out if the user browser is Chrome?


I need some function returning a boolean value to check if the browser is Chrome.

How do I create such functionality?


Solution

  • Update: Please see Jonathan's answer for an updated way to handle this. The answer below may still work, but it could likely trigger some false positives in other browsers.

    var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
    

    However, as mentioned User Agents can be spoofed so it is always best to use feature-detection (e.g. Modernizer) when handling these issues, as other answers mention.