1
0
mirror of https://github.com/lancedikson/bowser synced 2024-10-27 20:34:22 +00:00

Merge pull request #85 from jdalton/msedge

Add support for Microsoft Edge.
This commit is contained in:
Dustin Diaz 2015-05-21 10:38:35 -07:00
commit bb35c3ddaf
3 changed files with 39 additions and 8 deletions

View File

@ -16,6 +16,7 @@ if (bowser.msie && bowser.version <= 6) {
* `chrome`[`webkit`] * `chrome`[`webkit`]
* `firefox`[`gecko`] * `firefox`[`gecko`]
* `msie` * `msie`
* `msedge`
* Android native browser as `android`[`webkit`] * Android native browser as `android`[`webkit`]
* iOS native browser as `ios`[`webkit`] * iOS native browser as `ios`[`webkit`]
* `opera`[`webkit` if >12] * `opera`[`webkit` if >12]

View File

@ -24,6 +24,7 @@
var iosdevice = getFirstMatch(/(ipod|iphone|ipad)/i).toLowerCase() var iosdevice = getFirstMatch(/(ipod|iphone|ipad)/i).toLowerCase()
, likeAndroid = /like android/i.test(ua) , likeAndroid = /like android/i.test(ua)
, android = !likeAndroid && /android/i.test(ua) , android = !likeAndroid && /android/i.test(ua)
, edgeVersion = getFirstMatch(/edge\/(\d+(\.\d+)?)/i)
, versionIdentifier = getFirstMatch(/version\/(\d+(\.\d+)?)/i) , versionIdentifier = getFirstMatch(/version\/(\d+(\.\d+)?)/i)
, tablet = /tablet/i.test(ua) , tablet = /tablet/i.test(ua)
, mobile = !tablet && /[^-]mobi/i.test(ua) , mobile = !tablet && /[^-]mobi/i.test(ua)
@ -40,8 +41,14 @@
result = { result = {
name: 'Windows Phone' name: 'Windows Phone'
, windowsphone: t , windowsphone: t
, msie: t }
, version: getFirstMatch(/iemobile\/(\d+(\.\d+)?)/i) if (edgeVersion) {
result.msedge = t
result.version = edgeVersion
}
else {
result.msie = t
result.version = getFirstMatch(/iemobile\/(\d+(\.\d+)?)/i)
} }
} }
else if (/msie|trident/i.test(ua)) { else if (/msie|trident/i.test(ua)) {
@ -51,6 +58,13 @@
, version: getFirstMatch(/(?:msie |rv:)(\d+(\.\d+)?)/i) , version: getFirstMatch(/(?:msie |rv:)(\d+(\.\d+)?)/i)
} }
} }
else if (/chrome.+? edge/i.test(ua)) {
result = {
name: 'Microsoft Edge'
, msedge: t
, version: edgeVersion
}
}
else if (/chrome|crios|crmo/i.test(ua)) { else if (/chrome|crios|crmo/i.test(ua)) {
result = { result = {
name: 'Chrome' name: 'Chrome'
@ -155,7 +169,7 @@
} }
// set webkit or gecko flag for browsers based on these engines // set webkit or gecko flag for browsers based on these engines
if (/(apple)?webkit/i.test(ua)) { if (!result.msedge && /(apple)?webkit/i.test(ua)) {
result.name = result.name || "Webkit" result.name = result.name || "Webkit"
result.webkit = t result.webkit = t
if (!result.version && versionIdentifier) { if (!result.version && versionIdentifier) {
@ -168,7 +182,7 @@
} }
// set OS flags for platforms that have multiple browsers // set OS flags for platforms that have multiple browsers
if (android || result.silk) { if (!result.msedge && (android || result.silk)) {
result.android = t result.android = t
} else if (iosdevice) { } else if (iosdevice) {
result[iosdevice] = t result[iosdevice] = t
@ -177,13 +191,13 @@
// OS version extraction // OS version extraction
var osVersion = ''; var osVersion = '';
if (iosdevice) { if (result.windowsphone) {
osVersion = getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i);
} else if (iosdevice) {
osVersion = getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i); osVersion = getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i);
osVersion = osVersion.replace(/[_\s]/g, '.'); osVersion = osVersion.replace(/[_\s]/g, '.');
} else if (android) { } else if (android) {
osVersion = getFirstMatch(/android[ \/-](\d+(\.\d+)*)/i); osVersion = getFirstMatch(/android[ \/-](\d+(\.\d+)*)/i);
} else if (result.windowsphone) {
osVersion = getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i);
} else if (result.webos) { } else if (result.webos) {
osVersion = getFirstMatch(/(?:web|hpw)os\/(\d+(\.\d+)*)/i); osVersion = getFirstMatch(/(?:web|hpw)os\/(\d+(\.\d+)*)/i);
} else if (result.blackberry) { } else if (result.blackberry) {
@ -207,7 +221,8 @@
// Graded Browser Support // Graded Browser Support
// http://developer.yahoo.com/yui/articles/gbs // http://developer.yahoo.com/yui/articles/gbs
if ((result.msie && result.version >= 10) || if (result.msedge ||
(result.msie && result.version >= 10) ||
(result.chrome && result.version >= 20) || (result.chrome && result.version >= 20) ||
(result.firefox && result.version >= 20.0) || (result.firefox && result.version >= 20.0) ||
(result.safari && result.version >= 6) || (result.safari && result.version >= 6) ||

View File

@ -358,6 +358,13 @@ module.exports.useragents = {
, c: true , c: true
} }
} }
, 'Microsoft Edge': {
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0': {
msedge: true
, version: '12.0'
, a: true
}
}
, Firefox: { , Firefox: {
'Mozilla/5.0 (Mobile; rv:26.0) Gecko/26.0 Firefox/26.0': { 'Mozilla/5.0 (Mobile; rv:26.0) Gecko/26.0 Firefox/26.0': {
gecko: true gecko: true
@ -735,6 +742,14 @@ module.exports.useragents = {
, mobile: true , mobile: true
, c: true , c: true
} }
, 'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; DEVICE INFO) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Mobile Safari/537.36 Edge/12.0': {
windowsphone: true
, osversion: '10.0'
, msedge: true
, version: '12.0'
, mobile: true
, a: true
}
} }
, WebOS: { , WebOS: {
'Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.5; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/234.83 Safari/534.6 TouchPad/1.0': { 'Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.5; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/234.83 Safari/534.6 TouchPad/1.0': {