From 296dd005f254eb5ffb4fdcacfdc248412227d29e Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Fri, 21 Nov 2014 15:10:35 +0800 Subject: [PATCH] Add support for IE Mobile 11 Closes #71 --- platform.js | 49 ++++++++++++++++++++++++++++------------- test/test.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 94 insertions(+), 17 deletions(-) diff --git a/platform.js b/platform.js index e4c8ed1..440b33c 100644 --- a/platform.js +++ b/platform.js @@ -335,12 +335,12 @@ /* Detectable layout engines (order is important) */ var layout = getLayout([ + 'Trident', { 'label': 'WebKit', 'pattern': 'AppleWebKit' }, 'iCab', 'Presto', 'NetFront', 'Tasman', - 'Trident', 'KHTML', 'Gecko' ]); @@ -384,6 +384,7 @@ 'Chrome', { 'label': 'Chrome Mobile', 'pattern': '(?:CriOS|CrMo)' }, { 'label': 'Firefox', 'pattern': '(?:Firefox|Minefield)' }, + { 'label': 'IE', 'pattern': 'IEMobile' }, { 'label': 'IE', 'pattern': 'MSIE' }, 'Safari' ]); @@ -397,6 +398,7 @@ { 'label': 'Galaxy S3', 'pattern': 'GT-I9300' }, { 'label': 'Galaxy S4', 'pattern': 'GT-I9500' }, 'Google TV', + 'Lumia', 'iPad', 'iPod', 'iPhone', @@ -430,13 +432,14 @@ 'Microsoft': { 'Xbox': 1, 'Xbox One': 1 }, 'Motorola': { 'Xoom': 1 }, 'Nintendo': { 'Wii U': 1, 'Wii': 1 }, - 'Nokia': {}, + 'Nokia': { 'Lumia': 1 }, 'Samsung': { 'Galaxy S': 1, 'Galaxy S2': 1, 'Galaxy S3': 1, 'Galaxy S4': 1 }, 'Sony': { 'PlayStation 4': 1, 'PlayStation 3': 1, 'PlayStation Vita': 1 } }); /* Detectable OSes (order is important) */ var os = getOS([ + 'Windows Phone ', 'Android', 'CentOS', 'Debian', @@ -644,11 +647,15 @@ if (!product) { product = data[1]; } + } + // detect IE Mobile 11 which identifies as different browsers + else if (layout == 'Trident' && !/\bWindows\b/.test(os)) { + } // detect non-Opera versions (order is important) if (!version) { version = getVersion([ - '(?:Cloud9|CriOS|CrMo|Iron|Opera ?Mini|OPiOS|OPR|Raven|Silk(?!/[\\d.]+$))', + '(?:Cloud9|CriOS|CrMo|IEMobile|Iron|Opera ?Mini|OPiOS|OPR|Raven|Silk(?!/[\\d.]+$))', 'Version', qualify(name), '(?:Firefox|Minefield|NetFront)' @@ -657,23 +664,41 @@ // detect stubborn layout engines if (layout == 'iCab' && parseFloat(version) > 3) { layout = ['WebKit']; - } else if ((data = + } else if ( + layout != 'Trident' && + (data = /\bOpera\b/.test(name) && (/\bOPR\b/.test(ua) ? 'Blink' : 'Presto') || /\b(?:Midori|Nook|Safari)\b/i.test(ua) && 'WebKit' || !layout && /\bMSIE\b/i.test(ua) && (os == 'Mac OS' ? 'Tasman' : 'Trident') - )) { + ) + ) { layout = [data]; } // detect NetFront on PlayStation else if (/\bPlayStation\b(?! Vita\b)/i.test(name) && layout == 'WebKit') { layout = ['NetFront']; } + // detect Windows Phone 7 desktop mode + if (name == 'IE' && (data = (/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(ua) || 0)[1])) { + name += ' Mobile'; + os = 'Windows Phone ' + (/\+$/.test(data) ? data : data + '.x'); + description.unshift('desktop mode'); + } + // detect Windows Phone 8+ desktop mode + else if (/\bWPDesktop\b/i.test(ua)) { + name = 'IE Mobile'; + os = 'Windows Phone 8+'; + description.unshift('desktop mode'); + version || (version = (/\brv:([\d.]+)/.exec(ua) || 0)[1]); + } // detect IE 11 and above - if (name != 'IE' && layout == 'Trident' && (data = /\brv:([\d.]+)/.exec(ua))) { - if (name) { - description.push('identifying as ' + name + (version ? ' ' + version : '')); + else if (name != 'IE' && layout == 'Trident' && (data = /\brv:([\d.]+)/.exec(ua))) { + if (!/\bWPDesktop\b/i.test(ua)) { + if (name) { + description.push('identifying as ' + name + (version ? ' ' + version : '')); + } + name = 'IE'; } - name = 'IE'; version = data[1]; } // leverage environment features @@ -760,12 +785,6 @@ description.unshift('accelerated'); } } - // detect Windows Phone desktop mode - else if (name == 'IE' && (data = (/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(ua) || 0)[1])) { - name += ' Mobile'; - os = 'Windows Phone ' + data + '.x'; - description.unshift('desktop mode'); - } // detect Xbox 360 and Xbox One else if (/\bXbox\b/i.test(product)) { os = null; diff --git a/test/test.js b/test/test.js index 1f4639b..aac9ac9 100644 --- a/test/test.js +++ b/test/test.js @@ -1195,7 +1195,7 @@ 'version': '9.0' }, - 'IE Mobile 10.0 on Nokia (Windows Phone 8.0)': { + 'IE Mobile 10.0 on Nokia Lumia 920 (Windows Phone 8.0)': { 'ua': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)', 'external': null, 'layout': 'Trident', @@ -1203,10 +1203,68 @@ 'mode': 10, 'name': 'IE Mobile', 'os': 'Windows Phone 8.0', - 'product': 'Nokia', + 'product': 'Lumia 920', 'version': '10.0' }, + 'IE Mobile 10.0 (desktop mode) on Windows Phone 8+': { + 'ua': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; ARM; Touch; WPDesktop)', + 'external': null, + 'layout': 'Trident', + 'mode': 10, + 'name': 'IE Mobile', + 'os': 'Windows Phone 8+', + 'version': '10.0' + }, + + 'IE Mobile 11.0 on Nokia Lumia 920 (Windows Phone 8.1)': { + 'ua': 'Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 920) like Gecko', + 'external': null, + 'layout': 'Trident', + 'manufacturer': 'Nokia', + 'mode': 11, + 'name': 'IE Mobile', + 'os': 'Windows Phone 8.1', + 'product': 'Lumia 920', + 'version': '11.0' + }, + + 'IE Mobile 11.0 (desktop mode) on Nokia Lumia 920 (Windows Phone 8+)': { + 'ua': 'Mozilla/5.0 (Windows NT 6.2; ARM; Trident/7.0; Touch; rv:11.0; WPDesktop; NOKIA; Lumia 920) like Gecko', + 'external': null, + 'layout': 'Trident', + 'manufacturer': 'Nokia', + 'mode': 11, + 'name': 'IE Mobile', + 'os': 'Windows Phone 8+', + 'product': 'Lumia 920', + 'version': '11.0' + }, + + 'IE Mobile 11.0#{ }on Nokia Lumia 920 (Windows Phone 8.1)': { + 'ua': 'Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 920) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537', + 'external': null, + 'layout': 'Trident', + 'manufacturer': 'Nokia', + 'mode': 11, + 'name': 'IE Mobile', + 'os': 'Windows Phone 8.1', + 'product': 'Lumia 920', + 'version': '11.0' + }, + + 'IE Mobile 11.0#{ }(desktop mode) on Nokia Lumia 920 (Windows Phone 8+)': { + 'ua': 'Mozilla/5.0 (Windows NT 6.2; ARM; Trident/7.0; Touch; rv:11.0; WPDesktop; Lumia 920) like Gecko', + 'external': null, + 'layout': 'Trident', + 'manufacturer': 'Nokia', + 'mode': 11, + 'name': 'IE Mobile', + 'os': 'Windows Phone 8+', + 'product': 'Lumia 920', + 'version': '11.0' + }, + 'SRWare Iron 0.2.152.0 on Windows Server 2008 / Vista': { 'ua': 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Iron/0.2.152.0 Safari/41562480.525', 'layout': 'WebKit',