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?
Asked
Active
Viewed 5.8k times
63
-
Why do you want to know this? And, because Chrome is open source, you can change this to whatever you'd like before building. – Feb 04 '11 at 16:38
-
Google Search (non instant) on Chrome 9 on first query uses AJAX. It's breaking my extension. – Skizit Feb 04 '11 at 16:39
3 Answers
133
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.
-
How would I make this an int? Need to do a comparison.. e.g `if(Version < 9)` – Skizit Feb 04 '11 at 16:45
-
4It is not recommended to use appVersion. See: https://developer.mozilla.org/en-US/docs/Web/API/NavigatorID.appVersion – Gautham C. Nov 21 '14 at 16:08
-
-
4Actually parseInt(raw[2]) is correct since match returns the full matched string at position 0. – Pape May 11 '16 at 13:40
-
1Why not use `(?:e|ium)` instead of `(e|ium)`. Now you get an extra group cought holding either `e` or `ium`. – Wilt Dec 02 '20 at 11:26
7
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.

drmrbrewer
- 11,491
- 21
- 85
- 181
3
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))

Dr. Lemon Tea
- 549
- 4
- 13
-
Update: edge also chromium, but is not support AVIF for example. So you can also search for `brand === 'Microsoft Edge'` – Dr. Lemon Tea Sep 13 '21 at 14:04