Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect the installed Chrome version?

I'm developing a Chrome extension and I'm wondering is there a way that I can detect which version of Chrome the user is using?

like image 286
Skizit Avatar asked Feb 04 '11 16:02

Skizit


People also ask

How do I know if Chrome is installed?

To check the Chrome version on Android, open Settings and tap on Apps & notifications or Apps. Next, look through your installed apps (by showing all the apps and/or scrolling), and then tap on Chrome. The Chrome version should be displayed on this page.


2 Answers

Get major version of Chrome as an integer:

function getChromeVersion () {          var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);      return raw ? parseInt(raw[2], 10) : false; } 

I've updated the original answer, so that it does not throw an exception in other browsers, and does not use deprecated features.

You can also set minimum_chrome_version in the manifest to not let users with older versions install it.

like image 148
serg Avatar answered Oct 02 '22 12:10

serg


Here is a version, based on the answer from @serg, that extracts all of the elements of the version number:

function getChromeVersion () {     var pieces = navigator.userAgent.match(/Chrom(?:e|ium)\/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/);     if (pieces == null || pieces.length != 5) {         return undefined;     }     pieces = pieces.map(piece => parseInt(piece, 10));     return {         major: pieces[1],         minor: pieces[2],         build: pieces[3],         patch: pieces[4]     }; } 

The naming of the elements in the object that is returned is based on this convention, though you can of course adapt it to be based on this instead.

like image 20
drmrbrewer Avatar answered Oct 02 '22 13:10

drmrbrewer