1
0
mirror of https://github.com/lancedikson/bowser synced 2024-09-28 22:30:44 +00:00
lancedikson_bowser/src/parser-browsers.js

716 lines
16 KiB
JavaScript
Raw Normal View History

/**
* Browsers' descriptors
*
* The idea of descriptors is simple. You should know about them two simple things:
* 1. Every descriptor has a method or property called `test` and a `describe` method.
* 2. Order of descriptors is important.
*
* More details:
* 1. Method or property `test` serves as a way to detect whether the UA string
* matches some certain browser or not. The `describe` method helps to make a result
* object with params that show some browser-specific things: name, version, etc.
* 2. Order of descriptors is important because a Parser goes through them one by one
* in course. For example, if you insert Chrome's descriptor as the first one,
* more then a half of browsers will be described as Chrome, because they will pass
* the Chrome descriptor's test.
*
* Descriptor's `test` could be a property with an array of RegExps, where every RegExp
* will be applied to a UA string to test it whether it matches or not.
* If a descriptor has two or more regexps in the `test` array it tests them one by one
* with a logical sum operation. Parser stops if it has found any RegExp that matches the UA.
*
* Or `test` could be a method. In that case it gets a Parser instance and should
* return true/false to get the Parser know if this browser descriptor matches the UA or not.
*/
import Utils from './utils.js';
2017-04-04 20:03:47 +00:00
const commonVersionIdentifier = /version\/(\d+(\.?_?\d+)+)/i;
2017-04-04 20:03:47 +00:00
const browsersList = [
/* Googlebot */
{
test: [/googlebot/i],
describe(ua) {
const browser = {
name: 'Googlebot',
};
const version = Utils.getFirstMatch(/googlebot\/(\d+(\.\d+))/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
if (version) {
browser.version = version;
}
return browser;
},
},
2017-12-20 20:34:29 +00:00
/* Opera < 13.0 */
2017-04-04 20:03:47 +00:00
{
test: [/opera/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Opera',
};
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:opera)[\s/](\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
2017-12-20 20:34:29 +00:00
/* Opera > 13.0 */
2017-04-04 20:03:47 +00:00
{
2018-09-14 14:44:17 +00:00
test: [/opr\/|opios/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Opera',
};
const version = Utils.getFirstMatch(/(?:opr|opios)[\s/](\S+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/SamsungBrowser/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Samsung Internet for Android',
};
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:SamsungBrowser)[\s/](\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/Whale/i],
describe(ua) {
const browser = {
name: 'NAVER Whale Browser',
};
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:whale)[\s/](\d+(?:\.\d+)+)/i, ua);
if (version) {
browser.version = version;
}
return browser;
},
},
{
test: [/PaleMoon/i],
describe(ua) {
const browser = {
name: 'Pale Moon',
};
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:PaleMoon)[\s/](\d+(?:\.\d+)+)/i, ua);
if (version) {
browser.version = version;
}
return browser;
},
},
{
test: [/MZBrowser/i],
describe(ua) {
const browser = {
name: 'MZ Browser',
};
const version = Utils.getFirstMatch(/(?:MZBrowser)[\s/](\d+(?:\.\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
if (version) {
browser.version = version;
}
return browser;
},
},
{
test: [/focus/i],
describe(ua) {
const browser = {
name: 'Focus',
};
const version = Utils.getFirstMatch(/(?:focus)[\s/](\d+(?:\.\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
if (version) {
browser.version = version;
}
return browser;
},
},
2018-09-09 12:07:40 +00:00
{
test: [/swing/i],
describe(ua) {
const browser = {
name: 'Swing',
};
const version = Utils.getFirstMatch(/(?:swing)[\s/](\d+(?:\.\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2018-09-09 12:07:40 +00:00
if (version) {
browser.version = version;
}
return browser;
},
},
2017-04-04 20:03:47 +00:00
{
test: [/coast/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Opera Coast',
};
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:coast)[\s/](\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/opt\/\d+(?:.?_?\d+)+/i],
describe(ua) {
const browser = {
name: 'Opera Touch',
};
const version = Utils.getFirstMatch(/(?:opt)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
if (version) {
browser.version = version;
}
return browser;
},
},
2017-04-04 20:03:47 +00:00
{
test: [/yabrowser/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Yandex Browser',
};
const version = Utils.getFirstMatch(/(?:yabrowser)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/ucbrowser/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'UC Browser',
};
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:ucbrowser)[\s/](\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
2018-08-29 21:44:50 +00:00
test: [/Maxthon|mxios/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Maxthon',
};
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:Maxthon|mxios)[\s/](\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/epiphany/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Epiphany',
};
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:epiphany)[\s/](\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/puffin/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Puffin',
};
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:puffin)[\s/](\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/sleipnir/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Sleipnir',
};
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:sleipnir)[\s/](\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/k-meleon/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'K-Meleon',
};
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:k-meleon)[\s/](\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
2018-10-14 15:25:45 +00:00
{
test: [/micromessenger/i],
describe(ua) {
const browser = {
name: 'WeChat',
};
const version = Utils.getFirstMatch(/(?:micromessenger)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2019-09-18 08:34:14 +00:00
if (version) {
browser.version = version;
}
return browser;
},
},
{
test: [/qqbrowser/i],
describe(ua) {
const browser = {
name: (/qqbrowserlite/i).test(ua) ? 'QQ Browser Lite' : 'QQ Browser',
};
const version = Utils.getFirstMatch(/(?:qqbrowserlite|qqbrowser)[/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2018-10-14 15:25:45 +00:00
if (version) {
browser.version = version;
}
return browser;
},
},
2017-04-04 20:03:47 +00:00
{
test: [/msie|trident/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Internet Explorer',
};
const version = Utils.getFirstMatch(/(?:msie |rv:)(\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/\sedg\//i],
describe(ua) {
const browser = {
name: 'Microsoft Edge',
};
const version = Utils.getFirstMatch(/\sedg\/(\d+(\.?_?\d+)+)/i, ua);
if (version) {
browser.version = version;
}
return browser;
},
},
2017-04-04 20:03:47 +00:00
{
2017-12-20 20:34:29 +00:00
test: [/edg([ea]|ios)/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Microsoft Edge',
};
2017-12-20 20:34:29 +00:00
const version = Utils.getSecondMatch(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
2017-04-04 20:03:47 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/vivaldi/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Vivaldi',
};
const version = Utils.getFirstMatch(/vivaldi\/(\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
2017-04-04 20:03:47 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/seamonkey/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'SeaMonkey',
};
const version = Utils.getFirstMatch(/seamonkey\/(\d+(\.?_?\d+)+)/i, ua);
if (version) {
browser.version = version;
2017-04-04 20:03:47 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
2017-08-20 15:22:28 +00:00
test: [/sailfish/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Sailfish',
};
2017-08-20 15:22:28 +00:00
const version = Utils.getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i, ua);
if (version) {
browser.version = version;
2017-04-04 20:03:47 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/silk/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Amazon Silk',
};
const version = Utils.getFirstMatch(/silk\/(\d+(\.?_?\d+)+)/i, ua);
if (version) {
browser.version = version;
2017-04-04 20:03:47 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/phantom/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'PhantomJS',
};
const version = Utils.getFirstMatch(/phantomjs\/(\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
2017-04-04 20:03:47 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/slimerjs/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'SlimerJS',
};
const version = Utils.getFirstMatch(/slimerjs\/(\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
2017-04-04 20:03:47 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/blackberry|\bbb\d+/i, /rim\stablet/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'BlackBerry',
};
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/blackberry[\d]+\/(\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
2017-04-04 20:03:47 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
test: [/(web|hpw)[o0]s/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'WebOS Browser',
};
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/w(?:eb)?[o0]sbrowser\/(\d+(\.?_?\d+)+)/i, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
2017-04-04 20:03:47 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
{
2017-04-09 14:13:00 +00:00
test: [/bada/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Bada',
};
const version = Utils.getFirstMatch(/dolfin\/(\d+(\.?_?\d+)+)/i, ua);
2017-04-09 14:13:00 +00:00
if (version) {
browser.version = version;
2017-04-09 14:13:00 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-09 14:13:00 +00:00
},
{
test: [/tizen/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Tizen',
};
const version = Utils.getFirstMatch(/(?:tizen\s?)?browser\/(\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2017-04-09 14:13:00 +00:00
if (version) {
browser.version = version;
2017-04-09 14:13:00 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-09 14:13:00 +00:00
},
{
test: [/qupzilla/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'QupZilla',
};
const version = Utils.getFirstMatch(/(?:qupzilla)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2017-04-09 14:13:00 +00:00
if (version) {
browser.version = version;
2017-04-09 14:13:00 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-09 14:13:00 +00:00
},
2017-08-20 15:22:28 +00:00
{
test: [/firefox|iceweasel|fxios/i],
2017-08-20 15:22:28 +00:00
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Firefox',
2017-08-20 15:22:28 +00:00
};
const version = Utils.getFirstMatch(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i, ua);
2017-08-20 15:22:28 +00:00
if (version) {
browser.version = version;
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-08-20 15:22:28 +00:00
},
2019-12-04 12:55:36 +00:00
{
test: [/electron/i],
describe(ua) {
const browser = {
name: 'Electron',
};
const version = Utils.getFirstMatch(/(?:electron)\/(\d+(\.?_?\d+)+)/i, ua);
if (version) {
browser.version = version;
}
return browser;
},
},
{
test: [/MiuiBrowser/i],
describe(ua) {
const browser = {
name: 'Miui',
};
const version = Utils.getFirstMatch(/(?:MiuiBrowser)[\s/](\d+(\.?_?\d+)+)/i, ua);
if (version) {
browser.version = version;
}
return browser;
},
},
2017-04-09 14:13:00 +00:00
{
test: [/chromium/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Chromium',
};
const version = Utils.getFirstMatch(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2017-04-09 14:13:00 +00:00
if (version) {
browser.version = version;
2017-04-09 14:13:00 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-09 14:13:00 +00:00
},
{
test: [/chrome|crios|crmo/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Chrome',
};
const version = Utils.getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i, ua);
2017-04-09 14:13:00 +00:00
if (version) {
browser.version = version;
2017-04-09 14:13:00 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-09 14:13:00 +00:00
},
{
test: [/GSA/i],
describe(ua) {
const browser = {
name: 'Google Search',
};
const version = Utils.getFirstMatch(/(?:GSA)\/(\d+(\.?_?\d+)+)/i, ua);
if (version) {
browser.version = version;
}
return browser;
},
},
2017-04-09 19:09:47 +00:00
/* Android Browser */
2017-04-09 14:13:00 +00:00
{
test(parser) {
2017-08-20 15:22:28 +00:00
const notLikeAndroid = !parser.test(/like android/i);
2017-04-09 19:09:47 +00:00
const butAndroid = parser.test(/android/i);
return notLikeAndroid && butAndroid;
2017-04-09 14:13:00 +00:00
},
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Android Browser',
};
const version = Utils.getFirstMatch(commonVersionIdentifier, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
2017-04-04 20:03:47 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-04 20:03:47 +00:00
},
2017-04-09 19:09:47 +00:00
2019-02-06 08:47:28 +00:00
/* PlayStation 4 */
{
test: [/playstation 4/i],
describe(ua) {
const browser = {
name: 'PlayStation 4',
};
2019-03-06 12:27:35 +00:00
const version = Utils.getFirstMatch(commonVersionIdentifier, ua);
2019-02-06 08:47:28 +00:00
if (version) {
browser.version = version;
}
return browser;
},
},
2017-04-09 19:09:47 +00:00
/* Safari */
2017-04-04 20:03:47 +00:00
{
2017-04-09 19:09:47 +00:00
test: [/safari|applewebkit/i],
describe(ua) {
const browser = {
2017-12-20 21:29:06 +00:00
name: 'Safari',
};
const version = Utils.getFirstMatch(commonVersionIdentifier, ua);
2017-04-04 20:03:47 +00:00
if (version) {
browser.version = version;
2017-04-09 19:09:47 +00:00
}
return browser;
2017-12-20 21:29:06 +00:00
},
2017-04-09 19:09:47 +00:00
},
/* Something else */
{
test: [/.*/i],
describe(ua) {
2019-04-23 09:28:11 +00:00
/* Here we try to make sure that there are explicit details about the device
* in order to decide what regexp exactly we want to apply
* (as there is a specific decision based on that conclusion)
*/
const regexpWithoutDeviceSpec = /^(.*)\/(.*) /;
const regexpWithDeviceSpec = /^(.*)\/(.*)[ \t]\((.*)/;
const hasDeviceSpec = ua.search('\\(') !== -1;
2019-04-23 09:40:04 +00:00
const regexp = hasDeviceSpec ? regexpWithDeviceSpec : regexpWithoutDeviceSpec;
2017-04-09 19:09:47 +00:00
return {
2019-04-05 17:18:39 +00:00
name: Utils.getFirstMatch(regexp, ua),
version: Utils.getSecondMatch(regexp, ua),
2017-04-09 19:09:47 +00:00
};
2017-12-20 21:29:06 +00:00
},
},
2017-04-04 20:03:47 +00:00
];
2017-04-09 14:13:00 +00:00
export default browsersList;