JavaScript – Detect and Get The Current Version of Microsoft Edge (Chromium)
Microsoft announced the next version of Edge browser with a big change that it is developed based on Chromium.
In this article, we will show you how to detect Microsoft Edge and get the current version of it using JavaScript. In fact, we want to get the current version of all browsers user is using to serve special tasks, for example, fixing issues causing by browser, statistical purposes, or notify message to the user, etc.
To detect whether or not a browser is Microsoft Edge as well as get the current version of it, we simply look at User-Agent data (navigator.userAgent
) and then extract the version from it.
This is Chromium-based Microsoft Edge’s User-Agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3851.0 Safari/537.36 Edg/77.0.228.0
Here is the implementation code in JavaScript. Click on the “Run Example” button to see how it works:
function isMicrosoftEdgeBrowser(userAgent) {
if ((userAgent.indexOf('chrome') !== -1)
&& (userAgent.indexOf('edg') !== -1)) {
return true;
}
return false;
}
function getMicrosoftEdgeBrowserVersion() {
var version = null;
var userAgent = navigator.userAgent.toLowerCase();
if (isMicrosoftEdgeBrowser(userAgent)) {
var matches = userAgent.match(/edg\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/);
if (matches) {
version = matches[1];
}
}
return version;
}
Use the function:
var edgeVersion = getMicrosoftEdgeBrowserVersion();
console.log(edgeVersion); // 77.0.228.0