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

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 1:

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.

Solution 2:

To check if browser is Google Chrome, try this:

// please note, 
// that IE11 now returns undefined again for
// and new Opera 30 outputs true for
// but needs to check if window.opr is not undefined
// and new IE Edge outputs to true now for
// and if not iOS Chrome check
// so use the below updated condition
var isChromium =;
var winNav = window.navigator;
var vendorName = winNav.vendor;
var isOpera = typeof window.opr !== "undefined";
var isIEedge = winNav.userAgent.indexOf("Edge") > -1;
var isIOSChrome = winNav.userAgent.match("CriOS");

if (isIOSChrome) {
   // is Google Chrome on IOS
} else if(
  isChromium !== null &&
  typeof isChromium !== "undefined" &&
  vendorName === "Google Inc." &&
  isOpera === false &&
  isIEedge === false
) {
   // is Google Chrome
} else { 
   // not Google Chrome 

Example of use:

Related:  Why do we pass null to XMLHttpRequest.send?

The reason this works is because if you use the Google Chrome inspector and go to the console tab. Type ‘window’ and press enter. Then you be able to view the DOM properties for the ‘window object’. When you collapse the object you can view all the properties, including the ‘chrome’ property.

You can’t use strictly equals true anymore to check in IE for IE used to return undefined, now it returns true. But guess what, IE11 now returns undefined again. IE11 also returns a empty string "" for window.navigator.vendor.

I hope this helps!


Thank you to Halcyon991 for pointing out below, that the new Opera 18+ also outputs to true for Looks like Opera 18 is based on Chromium 31. So I added a check to make sure the window.navigator.vendor is: "Google Inc" and not is "Opera Software ASA". Also thanks to Ring and Adrien Be for the heads up about Chrome 33 not returning true anymore… now checks if not null. But play close attention to IE11, I added the check back for undefined since IE11 now outputs undefined, like it did when first released.. then after some update builds it outputted to true .. now recent update build is outputting undefined again. Microsoft can’t make up it’s mind!

Related:  Insert text into textarea at cursor position (Javascript)

UPDATE 7/24/2015 – addition for Opera check

Opera 30 was just released. It no longer outputs window.opera. And also outputs to true in the new Opera 30. So you must check if OPR is in the userAgent. I updated my condition above to account for this new change in Opera 30, since it uses same render engine as Google Chrome.

UPDATE 10/13/2015 – addition for IE check

Added check for IE Edge due to it outputting true for .. even though IE11 outputs undefined for Thanks to artfulhacker for letting us know about this!

UPDATE 2/5/2016 – addition for iOS Chrome check

Added check for iOS Chrome check CriOS due to it outputting true for Chrome on iOS. Thanks to xinthose for letting us know about this!

UPDATE 4/18/2018 – change for Opera check

Edited check for Opera, checking window.opr is not undefined since now Chrome 66 has OPR in window.navigator.vendor. Thanks to Frosty Z and Daniel Wallman for reporting this!

Related:  How do you expose a C++ class in the V8 Javascript Engine so it can be created using new?

Solution 3:

even shorter: var is_chrome = /chrome/i.test( navigator.userAgent );

Solution 4:

A much simpler solution is just to use:

var isChrome = !!;

The !! just converts the object to a boolean value. In non-Chrome browsers, this property will be undefined, which is not truthy.

Solution 5:

  isAndroid: /Android/.test(navigator.userAgent),
  isCordova: !!window.cordova,
  isEdge: /Edge/.test(navigator.userAgent),
  isFirefox: /Firefox/.test(navigator.userAgent),
  isChrome: /Google Inc/.test(navigator.vendor),
  isChromeIOS: /CriOS/.test(navigator.userAgent),
  isChromiumBased: !! && !/Edge/.test(navigator.userAgent),
  isIE: /Trident/.test(navigator.userAgent),
  isIOS: /(iPhone|iPad|iPod)/.test(navigator.platform),
  isOpera: /OPR/.test(navigator.userAgent),
  isSafari: /Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent),
  isTouchScreen: ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch,
  isWebComponentsSupported: 'registerElement' in document && 'import' in document.createElement('link') && 'content' in document.createElement('template')
}, null, '  '));

Solution 6:

var is_chrome = /chrome/.test( navigator.userAgent.toLowerCase() );