bowser
bowser copied to clipboard
Detect Chrome version in Electron
Using Electron 10 which contains Chrome/Chromium 84:
User-Agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4129.0 Electron/10.0.0-nightly.20200514 Safari/537.36"
However, reported browser name and version are:
- name: "Electron"
- version: "10.0.0"
which are kindly useless for taking decisions.
Is it possible to obtain Chrome/Chromium related versions instead?
Looks like that is expected behavior: https://github.com/lancedikson/bowser/issues/374
I see. The problem is that the important stuff when in Electron is the Chrome version it includes (78 in Electron 8, 84 in Electron 10, etc). I don't know what "Electron browser" means since the real browser into it is Chrome.
Anyway, I end doing lot of stuff like this in my apps:
if (bowserParser.getBrowserName() === 'Electron') {
const match = navigator.userAgent.match(/(?:(?:Chrome|Chromium))[ /](\w+)/i);
if (!match) {
return undefined;
}
version = match[1];
return version;
}
It would be great if bowser API included a method to get Chrome version from UserAgent.