Live video on the AT Protocol
at eli/multistream-fixes 27 lines 1.6 kB view raw
1export function getBrowserName(userAgent: string) { 2 // The order matters here, and this may report false positives for unlisted browsers. 3 4 if (userAgent.includes("Firefox")) { 5 // "Mozilla/5.0 (X11; Linux i686; rv:104.0) Gecko/20100101 Firefox/104.0" 6 return "Firefox"; 7 } else if (userAgent.includes("SamsungBrowser")) { 8 // "Mozilla/5.0 (Linux; Android 9; SAMSUNG SM-G955F Build/PPR1.180610.011) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/9.4 Chrome/67.0.3396.87 Mobile Safari/537.36" 9 return "Samsung Internet"; 10 } else if (userAgent.includes("Opera") || userAgent.includes("OPR")) { 11 // "Mozilla/5.0 (Macintosh; Intel Mac OS X 12_5_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36 OPR/90.0.4480.54" 12 return "Opera"; 13 } else if (userAgent.includes("Edge")) { 14 // "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299" 15 return "Edge (Legacy)"; 16 } else if (userAgent.includes("Edg")) { 17 // "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36 Edg/104.0.1293.70" 18 return "Edge (Chromium)"; 19 } else if (userAgent.includes("Chrome")) { 20 // "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" 21 return "Chrome"; 22 } else if (userAgent.includes("Safari")) { 23 // "Mozilla/5.0 (iPhone; CPU iPhone OS 15_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6 Mobile/15E148 Safari/604.1" 24 return "Safari"; 25 } 26 return "unknown"; 27}