Last active
September 27, 2020 15:53
-
-
Save amitsingh-007/063668ce5eca1ced7fad508b596fb3f9 to your computer and use it in GitHub Desktop.
Detect if request is from modern browser or not
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace PWAUtils | |
{ | |
public static class BrowserDetection | |
{ | |
static readonly Dictionary<string, string> browserMapping = new Dictionary<string, string> | |
{ | |
//For mobile devices | |
{ "Chrome Mobile", "71" }, | |
{ "Firefox Mobile", "64" }, | |
{ "Samsung Browser", "8.2" }, | |
{ "UC Browser", "12.12" }, | |
{ "Chrome Mobile on iOS", "71" }, | |
{ "Mobile Safari", "10.3" }, | |
//For desktop devices | |
{ "Edge", "79" }, | |
{ "Firefox", "60" }, | |
{ "Chrome", "61" }, | |
{ "Opera", "48" }, | |
{ "Safari", "10.1" }, | |
//Add your browsers here | |
}; | |
public static bool IsModernBrowser(string browserName, string browserVersion) | |
{ | |
if (browserMapping.ContainsKey(browserName)) | |
{ | |
string modernBrowserVersion = browserMapping[browserName]; | |
return browserVersion.CompareTo(modernBrowserVersion) >= 0; | |
} | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment