mirror of
https://github.com/lancedikson/bowser
synced 2024-10-27 20:34:22 +00:00
refactored detection for firefox/seamonkey/plain gecko to conform to the way other browsers are detected, added version information in case unknown gecko/webkit browser is detected, added detection+tests+docs for sailfish browser
This commit is contained in:
parent
8bcd3bc802
commit
1e7a7279c8
@ -29,6 +29,7 @@ Flags set for detected Browsers[Engines]
|
||||
* Amazon Kindle browser as `silk`[`webkit`]
|
||||
* Bada browser as `bada`[`webkit`]
|
||||
* Tizen browser as `tizen`[`webkit`]
|
||||
* Sailfish browser as `sailfish`[`gecko`]
|
||||
|
||||
For all detected browsers the browser version is set in the `version` field.
|
||||
|
||||
@ -43,6 +44,7 @@ Flags set for detected mobile Operating Systems
|
||||
* `webos` (`touchpad`)
|
||||
* `bada`
|
||||
* `tizen`
|
||||
* `sailfish`
|
||||
|
||||
Android, iOS, Windows Phone, WebOS, Bada, and Tizen will all report the OS version number if it is contained in the UA string in the `osversion` field. iOS is always reported as `ios` and additionally as `iphone`/`ipad`/`ipod`, whichever one matches best. If WebOS device is an HP TouchPad the flag `touchpad` is additionally set.
|
||||
|
||||
|
48
bowser.js
48
bowser.js
@ -68,22 +68,28 @@
|
||||
result.version = versionIdentifier
|
||||
}
|
||||
}
|
||||
else if (/gecko\//i.test(ua)) {
|
||||
else if (/sailfish/i.test(ua)) {
|
||||
result = {
|
||||
name: 'Gecko'
|
||||
, gecko: t
|
||||
name: 'Sailfish'
|
||||
, sailfish: t
|
||||
, version: getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i)
|
||||
}
|
||||
}
|
||||
else if (/seamonkey\//i.test(ua)) {
|
||||
result = {
|
||||
name: 'SeaMonkey'
|
||||
, seamonkey: t
|
||||
, version: getFirstMatch(/seamonkey\/(\d+(\.\d+)?)/i)
|
||||
}
|
||||
}
|
||||
else if (/firefox|iceweasel/i.test(ua)) {
|
||||
result = {
|
||||
name: 'Firefox'
|
||||
, firefox: t
|
||||
, version: getFirstMatch(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)
|
||||
}
|
||||
if (/seamonkey\//i.test(ua)) {
|
||||
result.name = 'SeaMonkey'
|
||||
result.seamonkey = t
|
||||
result.version = getFirstMatch(/seamonkey\/(\d+(\.\d+)?)/i)
|
||||
} else if (/firefox|iceweasel/i.test(ua)) {
|
||||
result.name = 'Firefox'
|
||||
result.firefox = t
|
||||
if (/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) {
|
||||
result.firefoxos = t
|
||||
}
|
||||
if (/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) {
|
||||
result.firefoxos = t
|
||||
}
|
||||
}
|
||||
else if (/silk/i.test(ua)) {
|
||||
@ -144,6 +150,19 @@
|
||||
}
|
||||
else result = {}
|
||||
|
||||
// set webkit or gecko flag for browsers based on these engines
|
||||
if (/(apple)?webkit/i.test(ua)) {
|
||||
result.name = result.name || "Webkit"
|
||||
result.webkit = t
|
||||
if (!result.version && versionIdentifier) {
|
||||
result.version = versionIdentifier
|
||||
}
|
||||
} else if (!result.opera && /gecko\//i.test(ua)) {
|
||||
result.name = result.name || "Gecko"
|
||||
result.gecko = t
|
||||
result.version = result.version || getFirstMatch(/gecko\/(\d+(\.\d+)?)/i)
|
||||
}
|
||||
|
||||
// set OS flags for platforms that have multiple browsers
|
||||
if (android || result.silk) {
|
||||
result.android = t
|
||||
@ -151,9 +170,6 @@
|
||||
result[iosdevice] = t
|
||||
result.ios = t
|
||||
}
|
||||
if (/applewebkit/i.test(ua)) {
|
||||
result.webkit = t
|
||||
}
|
||||
|
||||
// OS version extraction
|
||||
var osVersion = '';
|
||||
|
2
bowser.min.js
vendored
2
bowser.min.js
vendored
@ -3,4 +3,4 @@
|
||||
* https://github.com/ded/bowser
|
||||
* MIT License | (c) Dustin Diaz 2014
|
||||
*/
|
||||
!function(e,t){typeof module!="undefined"&&module.exports?module.exports.browser=t():typeof define=="function"?define(t):this[e]=t()}("bowser",function(){function t(t){function n(e){var n=t.match(e);return n&&n.length>1&&n[1]||""}var r=n(/(ipod|iphone|ipad)/i).toLowerCase(),i=/like android/i.test(t),s=!i&&/android/i.test(t),o=n(/version\/(\d+(\.\d+)?)/i),u=/tablet/i.test(t),a=!u&&/[^-]mobi/i.test(t),f;/opera|opr/i.test(t)?f={name:"Opera",opera:e,version:o||n(/(?:opera|opr)[\s\/](\d+(\.\d+)?)/i)}:/windows phone/i.test(t)?f={name:"Windows Phone",windowsphone:e,msie:e,version:n(/iemobile\/(\d+(\.\d+)?)/i)}:/msie|trident/i.test(t)?f={name:"Internet Explorer",msie:e,version:n(/(?:msie |rv:)(\d+(\.\d+)?)/i)}:/chrome|crios|crmo/i.test(t)?f={name:"Chrome",chrome:e,version:n(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)}:r?(f={name:r=="iphone"?"iPhone":r=="ipad"?"iPad":"iPod"},o&&(f.version=o)):/gecko\//i.test(t)?(f={name:"Gecko",gecko:e,version:n(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)},/seamonkey\//i.test(t)?(f.name="SeaMonkey",f.seamonkey=e,f.version=n(/seamonkey\/(\d+(\.\d+)?)/i)):/firefox|iceweasel/i.test(t)&&(f.name="Firefox",f.firefox=e,/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(t)&&(f.firefoxos=e))):/silk/i.test(t)?f={name:"Amazon Silk",silk:e,version:n(/silk\/(\d+(\.\d+)?)/i)}:s?f={name:"Android",version:o}:/phantom/i.test(t)?f={name:"PhantomJS",phantom:e,version:n(/phantomjs\/(\d+(\.\d+)?)/i)}:/blackberry|\bbb\d+/i.test(t)||/rim\stablet/i.test(t)?f={name:"BlackBerry",blackberry:e,version:o||n(/blackberry[\d]+\/(\d+(\.\d+)?)/i)}:/(web|hpw)os/i.test(t)?(f={name:"WebOS",webos:e,version:o||n(/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i)},/touchpad\//i.test(t)&&(f.touchpad=e)):/bada/i.test(t)?f={name:"Bada",bada:e,version:n(/dolfin\/(\d+(\.\d+)?)/i)}:/tizen/i.test(t)?f={name:"Tizen",tizen:e,version:n(/(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i)||o}:/safari/i.test(t)?f={name:"Safari",safari:e,version:o}:f={},s||f.silk?f.android=e:r&&(f[r]=e,f.ios=e),/applewebkit/i.test(t)&&(f.webkit=e);var l="";r?(l=n(/os (\d+([_\s]\d+)*) like mac os x/i),l=l.replace(/[_\s]/g,".")):s?l=n(/android[ \/-](\d+(\.\d+)*)/i):f.windowsphone?l=n(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i):f.webos?l=n(/(?:web|hpw)os\/(\d+(\.\d+)*)/i):f.blackberry?l=n(/rim\stablet\sos\s(\d+(\.\d+)*)/i):f.bada?l=n(/bada\/(\d+(\.\d+)*)/i):f.tizen&&(l=n(/tizen[\/\s](\d+(\.\d+)*)/i)),l&&(f.osversion=l);var c=l.split(".")[0];if(u||r=="ipad"||s&&(c==3||c==4&&!a)||f.silk)f.tablet=e;else if(a||r=="iphone"||r=="ipod"||s||f.blackberry||f.webos||f.bada)f.mobile=e;return f.msie&&f.version>=9||f.chrome&&f.version>=20||f.firefox&&f.version>=10||f.safari&&f.version>=5||f.opera&&f.version>=10||f.ios&&f.osversion&&f.osversion.split(".")[0]>=6?f.a=e:f.msie&&f.version<9||f.chrome&&f.version<20||f.firefox&&f.version<10||f.safari&&f.version<5||f.opera&&f.version<10||f.ios&&f.osversion&&f.osversion.split(".")[0]<6?f.c=e:f.x=e,f}var e=!0,n=t(typeof navigator!="undefined"?navigator.userAgent:"");return n._detect=t,n})
|
||||
!function(e,t){typeof module!="undefined"&&module.exports?module.exports.browser=t():typeof define=="function"?define(t):this[e]=t()}("bowser",function(){function t(t){function n(e){var n=t.match(e);return n&&n.length>1&&n[1]||""}var r=n(/(ipod|iphone|ipad)/i).toLowerCase(),i=/like android/i.test(t),s=!i&&/android/i.test(t),o=n(/version\/(\d+(\.\d+)?)/i),u=/tablet/i.test(t),a=!u&&/[^-]mobi/i.test(t),f;/opera|opr/i.test(t)?f={name:"Opera",opera:e,version:o||n(/(?:opera|opr)[\s\/](\d+(\.\d+)?)/i)}:/windows phone/i.test(t)?f={name:"Windows Phone",windowsphone:e,msie:e,version:n(/iemobile\/(\d+(\.\d+)?)/i)}:/msie|trident/i.test(t)?f={name:"Internet Explorer",msie:e,version:n(/(?:msie |rv:)(\d+(\.\d+)?)/i)}:/chrome|crios|crmo/i.test(t)?f={name:"Chrome",chrome:e,version:n(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)}:r?(f={name:r=="iphone"?"iPhone":r=="ipad"?"iPad":"iPod"},o&&(f.version=o)):/sailfish/i.test(t)?f={name:"Sailfish",sailfish:e,version:n(/sailfish\s?browser\/(\d+(\.\d+)?)/i)}:/seamonkey\//i.test(t)?f={name:"SeaMonkey",seamonkey:e,version:n(/seamonkey\/(\d+(\.\d+)?)/i)}:/firefox|iceweasel/i.test(t)?(f={name:"Firefox",firefox:e,version:n(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)},/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(t)&&(f.firefoxos=e)):/silk/i.test(t)?f={name:"Amazon Silk",silk:e,version:n(/silk\/(\d+(\.\d+)?)/i)}:s?f={name:"Android",version:o}:/phantom/i.test(t)?f={name:"PhantomJS",phantom:e,version:n(/phantomjs\/(\d+(\.\d+)?)/i)}:/blackberry|\bbb\d+/i.test(t)||/rim\stablet/i.test(t)?f={name:"BlackBerry",blackberry:e,version:o||n(/blackberry[\d]+\/(\d+(\.\d+)?)/i)}:/(web|hpw)os/i.test(t)?(f={name:"WebOS",webos:e,version:o||n(/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i)},/touchpad\//i.test(t)&&(f.touchpad=e)):/bada/i.test(t)?f={name:"Bada",bada:e,version:n(/dolfin\/(\d+(\.\d+)?)/i)}:/tizen/i.test(t)?f={name:"Tizen",tizen:e,version:n(/(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i)||o}:/safari/i.test(t)?f={name:"Safari",safari:e,version:o}:f={},/(apple)?webkit/i.test(t)?(f.name=f.name||"Webkit",f.webkit=e,!f.version&&o&&(f.version=o)):!f.opera&&/gecko\//i.test(t)&&(f.name=f.name||"Gecko",f.gecko=e,f.version=f.version||n(/gecko\/(\d+(\.\d+)?)/i)),s||f.silk?f.android=e:r&&(f[r]=e,f.ios=e);var l="";r?(l=n(/os (\d+([_\s]\d+)*) like mac os x/i),l=l.replace(/[_\s]/g,".")):s?l=n(/android[ \/-](\d+(\.\d+)*)/i):f.windowsphone?l=n(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i):f.webos?l=n(/(?:web|hpw)os\/(\d+(\.\d+)*)/i):f.blackberry?l=n(/rim\stablet\sos\s(\d+(\.\d+)*)/i):f.bada?l=n(/bada\/(\d+(\.\d+)*)/i):f.tizen&&(l=n(/tizen[\/\s](\d+(\.\d+)*)/i)),l&&(f.osversion=l);var c=l.split(".")[0];if(u||r=="ipad"||s&&(c==3||c==4&&!a)||f.silk)f.tablet=e;else if(a||r=="iphone"||r=="ipod"||s||f.blackberry||f.webos||f.bada)f.mobile=e;return f.msie&&f.version>=9||f.chrome&&f.version>=20||f.firefox&&f.version>=10||f.safari&&f.version>=5||f.opera&&f.version>=10||f.ios&&f.osversion&&f.osversion.split(".")[0]>=6?f.a=e:f.msie&&f.version<9||f.chrome&&f.version<20||f.firefox&&f.version<10||f.safari&&f.version<5||f.opera&&f.version<10||f.ios&&f.osversion&&f.osversion.split(".")[0]<6?f.c=e:f.x=e,f}var e=!0,n=t(typeof navigator!="undefined"?navigator.userAgent:"");return n._detect=t,n})
|
@ -62,22 +62,28 @@
|
||||
result.version = versionIdentifier
|
||||
}
|
||||
}
|
||||
else if (/gecko\//i.test(ua)) {
|
||||
else if (/sailfish/i.test(ua)) {
|
||||
result = {
|
||||
name: 'Gecko'
|
||||
, gecko: t
|
||||
name: 'Sailfish'
|
||||
, sailfish: t
|
||||
, version: getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i)
|
||||
}
|
||||
}
|
||||
else if (/seamonkey\//i.test(ua)) {
|
||||
result = {
|
||||
name: 'SeaMonkey'
|
||||
, seamonkey: t
|
||||
, version: getFirstMatch(/seamonkey\/(\d+(\.\d+)?)/i)
|
||||
}
|
||||
}
|
||||
else if (/firefox|iceweasel/i.test(ua)) {
|
||||
result = {
|
||||
name: 'Firefox'
|
||||
, firefox: t
|
||||
, version: getFirstMatch(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)
|
||||
}
|
||||
if (/seamonkey\//i.test(ua)) {
|
||||
result.name = 'SeaMonkey'
|
||||
result.seamonkey = t
|
||||
result.version = getFirstMatch(/seamonkey\/(\d+(\.\d+)?)/i)
|
||||
} else if (/firefox|iceweasel/i.test(ua)) {
|
||||
result.name = 'Firefox'
|
||||
result.firefox = t
|
||||
if (/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) {
|
||||
result.firefoxos = t
|
||||
}
|
||||
if (/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) {
|
||||
result.firefoxos = t
|
||||
}
|
||||
}
|
||||
else if (/silk/i.test(ua)) {
|
||||
@ -138,9 +144,17 @@
|
||||
}
|
||||
else result = {}
|
||||
|
||||
// set webkit flag for webkit-based browsers
|
||||
// set webkit or gecko flag for browsers based on these engines
|
||||
if (/(apple)?webkit/i.test(ua)) {
|
||||
result.name = result.name || "Webkit"
|
||||
result.webkit = t
|
||||
if (!result.version && versionIdentifier) {
|
||||
result.version = versionIdentifier
|
||||
}
|
||||
} else if (!result.opera && /gecko\//i.test(ua)) {
|
||||
result.name = result.name || "Gecko"
|
||||
result.gecko = t
|
||||
result.version = result.version || getFirstMatch(/gecko\/(\d+(\.\d+)?)/i)
|
||||
}
|
||||
|
||||
// set OS flags for platforms that have multiple browsers
|
||||
|
@ -907,6 +907,22 @@ module.exports.useragents = {
|
||||
, x: true
|
||||
}
|
||||
}
|
||||
, Sailfish: {
|
||||
'Mozilla/5.0 (Maemo; Linux; U; Jolla; Sailfish; Mobile; rv:26.0) Gecko/26.0 Firefox/26.0 SailfishBrowser/1.0 like Safari/538.1': {
|
||||
sailfish: true
|
||||
, gecko: true
|
||||
, version: '1.0'
|
||||
, mobile: true
|
||||
, x: true
|
||||
}
|
||||
, 'Mozilla/5.0 (Linux; U; Jolla; Sailfish; Mobile; rv:20.0) Gecko/20.0 Firefox/20.0 Sailfish Browser/1.0 like Safari/535.19': {
|
||||
sailfish: true
|
||||
, gecko: true
|
||||
, version: '1.0'
|
||||
, mobile: true
|
||||
, x: true
|
||||
}
|
||||
}
|
||||
, PhantomJS: {
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.5.0 Safari/534.34': {
|
||||
phantom: true
|
||||
|
Loading…
Reference in New Issue
Block a user