Browser detection in JavaScript? [duplicate]

navigator.saysWho = (() => { const { userAgent } = navigator let match = userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [] let temp if (/trident/i.test(match[1])) { temp = /\brv[ :]+(\d+)/g.exec(userAgent) || [] return `IE ${temp[1] || ”}` } if (match[1] === ‘Chrome’) { temp = userAgent.match(/\b(OPR|Edge)\/(\d+)/) if (temp !== null) { return temp.slice(1).join(‘ ‘).replace(‘OPR’, ‘Opera’) } temp = userAgent.match(/\b(Edg)\/(\d+)/) … Read more

How to detect Safari, Chrome, IE, Firefox and Opera browser?

Googling for browser reliable detection often results in checking the User agent string. This method is not reliable, because it’s trivial to spoof this value. I’ve written a method to detect browsers by duck-typing. Only use the browser detection method if it’s truly necessary, such as showing browser-specific instructions to install an extension. Use feature … Read more