I am trying to implement a function to detect chrome browser and then execute a particular function on the fly. We have a webpage where document links are displayed and on click on it, the document is downloaded.
the requirement is to enable the kiosk machines which uses chrome browser to open a document in a new tab as the download and opening the document is restricted in Kiosk machines.
to determine whether the browser is chrome, i have used below approaches.
using userAgent -- below approach returns true for other browsers as well
this.isChromeBrowser = (/(?!.*chrome).*/i).test(navigator.userAgent);
using window.chrome, below code was working when i implemented, but now it is giving issues and it returns false for chrome browser. (window.chrome.webstore & runtime are undefined).
this.isChromeBrowser = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);
- i am thinking of using implementation 1 along with window.navigator.vendor
this.isChromeBrowser = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
or
this.isChromeBrowser = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor) && window.chrome;
Need some inputs on which would be a better solution to use. i am more inclined towards implementation 3, as we would be checking the useragent as well as the vendor.
============ update : the implementation and extensive explanation is already provided in the below link. this give my answer.