1

I want to check if the active browser is Chrome, in TypeScript/JavaScript.

Earlier i have used

var isChrome = !!(<any>window).chrome && !!(<any>window).chrome.webstore;

But that doesn't seem to work anymore. What is the new approach? I do not wish to use UserAgent, due bad experience.

  • What is your use case? Most probably you want feature detection, not browser sniffing. Also please search and try the many other questions about this exact topic. You might want to have a look at the source code of https://github.com/lancedikson/bowser – str Jan 18 '19 at 12:01

3 Answers3

2

Similar question was already answered here, And code should look like:

// Chrome 1 - 71
var isChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);

Thanks, Oliver

Oliver
  • 341
  • 2
  • 4
  • 21
1

You could try using the bowser library for this:

console.log("You are using " + bowser.name + " version: " + bowser.version + " os: " + bowser.osname);

// Check for Chrome 20+
const isChrome = bowser.check({chrome: "20"}, true);
console.log("Chrome: ", isChrome);
<script src="https://cdnjs.cloudflare.com/ajax/libs/bowser/1.9.4/bowser.min.js"></script>
Terry Lennox
  • 29,471
  • 5
  • 28
  • 40
1

try to use the navigator global variable : const isChrome = /chrome/.test( navigator.userAgent.toLowerCase() );

bik
  • 319
  • 1
  • 8