'how to detect specific versions of browser

I wanted to check if browser is supported or not, I wanted to check the specific browser with browser versions,

How to check if Safari (12.1+) or not ? How to check if Edge (80+) or not ?

I have a function written wanted to modify that to achieve the same..

function isBrowserSupported() {
    let userAgent = navigator.userAgent;
    // let webrtcDetectedBrowser;
    // need to check if should check OS also
    let isBrowserSupported = false;
    if (userAgent.match(/chrome|chromium|crios/i) || (userAgent.match(/firefox|fxios/i)) || (userAgent.match(/safari/i)) || (userAgent.match(/edg/i))) {
        isBrowserSupported = true;
    } 
    return isBrowserSupported;
}

isBrowserSupported() should return true when browser is:

Chrome (MacOS/Windows/Android)
Firefox (MacOS/Windows)
Edge (80+)(Windows)
Safari (12.1+) ((MacOS/iPadOS/iOS)

navigator.userAgent return's this -

> navigator.userAgent
< "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15"


Solution 1:[1]

i hope navigator.userAgentData will solve your problem. you can use navigator.platform for finding platform

console.log(navigator.userAgentData)
console.log(navigator.platform)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anirudhsanthosh