From c8adc4b4fbee2776854e790cadbd7c157c80720a Mon Sep 17 00:00:00 2001 From: Jason Benedetti Date: Thu, 15 Nov 2018 12:04:50 +0100 Subject: [PATCH] Bugfix on IE and Edge detection Because "window.chrome" can returns an [object Object] with Edge, it is more secure to check it after Edge's exclusion. --- detect-browser.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/detect-browser.js b/detect-browser.js index 2d54a05..84e74e2 100644 --- a/detect-browser.js +++ b/detect-browser.js @@ -31,10 +31,6 @@ function isMobile() { } function getBrowserName() { - if (window.chrome) { - return 'Chrome'; - } - // Opera 8.0+ if ((window.opr && window.opr.addons) || window.opera @@ -55,14 +51,19 @@ function getBrowserName() { } // Internet Explorer 6-11 - if (/* @cc_on!@*/false || document.DOCUMENT_NODE) { + if (/* @cc_on!@*/false || document.documentMode) { return 'Internet Explorer'; } // Edge 20+ - if (window.styleMedia) { + if (!(document.documentMode) && window.StyleMedia) { return 'Microsoft Edge'; } + + // Chrome + if (window.chrome) { + return 'Chrome'; + } } function getOSName() {