How to detect the installed Chrome version?

JavascriptGoogle ChromeGoogle Chrome-Extension

Javascript Problem Overview


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?

Javascript Solutions


Solution 1 - Javascript

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.

Solution 2 - Javascript

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.

Solution 3 - Javascript

Alternative modern solution can be just check the navigator.userAgentData.brands

E.g.:

Boolean(navigator.userAgentData?.brands.find(({ brand, version }) => brand === 'Chromium' && parseFloat(version, 10) >= 93))

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSkizitView Question on Stackoverflow
Solution 1 - JavascriptsergView Answer on Stackoverflow
Solution 2 - JavascriptdrmrbrewerView Answer on Stackoverflow
Solution 3 - JavascriptDr. Lemon TeaView Answer on Stackoverflow