From f2c3d789f1ffda9959fef8425bbb3d4905edd793 Mon Sep 17 00:00:00 2001 From: Cattttttttt <1067812695@qq.com> Date: Thu, 21 Jan 2021 20:48:05 +0800 Subject: [PATCH 1/2] Support Sogou Browser and Some Search Bots --- src/constants.js | 12 +++ src/parser-browsers.js | 64 +++++++++++- src/parser-platforms.js | 20 ++++ test/acceptance/useragentstrings.yml | 146 +++++++++++++++++++++++++++ 4 files changed, 241 insertions(+), 1 deletion(-) diff --git a/src/constants.js b/src/constants.js index f3350325..dd78b6e0 100644 --- a/src/constants.js +++ b/src/constants.js @@ -4,6 +4,10 @@ export const BROWSER_ALIASES_MAP = { 'Amazon Silk': 'amazon_silk', 'Android Browser': 'android', Bada: 'bada', + Baidubot: 'baidubot', + BingAdsbot: 'bingads', + Bingbot: 'bingbot', + BingPreviewbot: 'bingpreview', BlackBerry: 'blackberry', Chrome: 'chrome', Chromium: 'chromium', @@ -32,6 +36,8 @@ export const BROWSER_ALIASES_MAP = { 'Samsung Internet for Android': 'samsung_internet', SeaMonkey: 'seamonkey', Sleipnir: 'sleipnir', + 'Sogou Browser': 'sogou', + 'Sogou Mobile Browser': 'sogoum', Swing: 'swing', Tizen: 'tizen', 'UC Browser': 'uc', @@ -46,6 +52,10 @@ export const BROWSER_MAP = { amazon_silk: 'Amazon Silk', android: 'Android Browser', bada: 'Bada', + baidubot: 'Baidubot', + bingads: 'BingAdsbot', + bingbot: 'Bingbot', + bingpreview: 'BingPreviewbot', blackberry: 'BlackBerry', chrome: 'Chrome', chromium: 'Chromium', @@ -74,6 +84,8 @@ export const BROWSER_MAP = { samsung_internet: 'Samsung Internet for Android', seamonkey: 'SeaMonkey', sleipnir: 'Sleipnir', + sogou: 'Sogou Browser', + sogoum: 'Sogou Mobile Browser', swing: 'Swing', tizen: 'Tizen', uc: 'UC Browser', diff --git a/src/parser-browsers.js b/src/parser-browsers.js index ee7840c5..a7291d17 100644 --- a/src/parser-browsers.js +++ b/src/parser-browsers.js @@ -35,7 +35,7 @@ const browsersList = [ const browser = { name: 'Googlebot', }; - const version = Utils.getFirstMatch(/googlebot\/(\d+(\.\d+))/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua); + const version = Utils.getFirstMatch(/googlebot(?:-image|-news|-video)?\/(\d+(\.\d+))/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua); if (version) { browser.version = version; @@ -44,7 +44,42 @@ const browsersList = [ return browser; }, }, + /* Baidu Search Bot */ + { + test: [/Baiduspider/i], + describe(ua) { + const browser = { + name: 'Baidubot', + }; + const version = Utils.getFirstMatch(/baiduspider(?:-ads|-render|-video|-image|-news|-favo|-cpro)?\/(\d+(\.\d+))/i, ua); + if(version) { + browser.version = version; + } + + return browser; + }, + }, + { + test: [/bingbot|bingpreview|adidxbot/i], + describe(ua) { + const hash = { + bingbot: 'Bingbot', + bingpreview: 'BingPreviewbot', + adidxbot: 'BingAdsbot' + }; + const browser = { + name: hash[ua.match(/bingbot|bingpreview|adidxbot/i)[0].toLowerCase()], + }; + const version = Utils.getFirstMatch(/(?:bingbot|adidxbot|bingpreview)\/(\d+(\.\d+)[a-zA-Z]?)/i, ua); + + if(version) { + browser.version = version; + } + + return browser; + }, + }, /* Opera < 13.0 */ { test: [/opera/i], @@ -108,6 +143,33 @@ const browsersList = [ return browser; }, }, + /* Sogou Browser */ + { + test: [/MetaSr|SogouMobileBrowser/i], + describe(ua) { + const browser = { + name: (/SogouMobileBrowser/i).test(ua) ? 'Sogou Mobile Browser' : 'Sogou Browser', + }; + const version = browser.name === 'Sogou Browser' ? + Utils.getFirstMatch(/Chrome[\s/](\d+)/i, ua) : + Utils.getFirstMatch(/SogouMobileBrowser[\s/](\d+(?:\.\d+)+)/i, ua); + const hash = { + '35': '5.1', + '38': '5.3', + '49': '6.3', + '58': '7.5', + '65': '8.6', + '72': '10.0', + '80': '11.0', + }; + + if(version) { + browser.version = hash[version] || version; + } + + return browser; + }, + }, { test: [/MZBrowser/i], describe(ua) { diff --git a/src/parser-platforms.js b/src/parser-platforms.js index 48b1eb10..517cbf18 100644 --- a/src/parser-platforms.js +++ b/src/parser-platforms.js @@ -18,6 +18,26 @@ export default [ }, }, + { + test: [/baiduspider/i], + describe() { + return { + type: 'bot', + vendor: 'Baidu', + }; + }, + }, + + { + test: [/bingbot|adidxbot|bingpreview/i], + describe() { + return { + type: 'bot', + vendor: 'Bing', + }; + }, + }, + /* Huawei */ { test: [/huawei/i], diff --git a/test/acceptance/useragentstrings.yml b/test/acceptance/useragentstrings.yml index 6c9fb1a3..464d095d 100644 --- a/test/acceptance/useragentstrings.yml +++ b/test/acceptance/useragentstrings.yml @@ -3054,3 +3054,149 @@ type: "mobile" engine: name: "Blink" + Sogou Browser: + - + ua: "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0" + spec: + browser: + name: "Sogou Browser" + version: "7.5" + os: + name: "Windows" + version: "NT 10.0" + versionName: "10" + platform: + type: "desktop" + engine: + name: "Blink" + - + ua: "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36 SE 2.X MetaSr 1.0" + spec: + browser: + name: "Sogou Browser" + version: "11.0" + os: + name: "Windows" + version: "NT 10.0" + versionName: "10" + platform: + type: "desktop" + engine: + name: "Blink" + - + ua: "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36 SE 2.X MetaSr 1.0" + spec: + browser: + name: "Sogou Browser" + version: "10.0" + os: + name: "Windows" + version: "NT 10.0" + versionName: "10" + platform: + type: "desktop" + engine: + name: "Blink" + - + ua: "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3314.0 Safari/537.36 SE 2.X MetaSr 1.0" + spec: + browser: + name: "Sogou Browser" + version: "8.6" + os: + name: "Windows" + version: "NT 10.0" + versionName: "10" + platform: + type: "desktop" + engine: + name: "Blink" + Sogou Mobile Browser: + - + ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4_8 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 SogouMobileBrowser/5.22.1" + spec: + browser: + name: "Sogou Mobile Browser" + version: "5.22.1" + os: + name: "iOS" + version: "12.4.8" + platform: + type: "mobile" + vendor: "Apple" + model: "iPhone" + engine: + name: "WebKit" + version: "605.1.15" + Baidubot: + - + ua: "Mozilla/5.0 (Linux;u;Android 4.2.2;zh-cn;) AppleWebKit/534.46 (KHTML,like Gecko) Version/5.1 Mobile Safari/10600.6.3 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)" + spec: + browser: + name: "Baidubot" + version: "2.0" + os: + name: "Android" + version: "4.2.2" + versionName: "Jelly Bean" + platform: + type: "bot" + vendor: "Baidu" + engine: + name: "WebKit" + version: "534.46" + - + ua: "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)" + spec: + browser: + name: "Baidubot" + version: "2.0" + os: {} + platform: + type: "bot" + vendor: "Baidu" + engine: {} + Bingbot: + - + ua: "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)" + spec: + browser: + name: "Bingbot" + version: "2.0" + os: {} + platform: + type: "bot" + vendor: "Bing" + engine: {} + BingAdsbot: + - + ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 (compatible; adidxbot/2.0; +http://www.bing.com/bingbot.htm)" + spec: + browser: + name: "BingAdsbot" + version: "2.0" + os: + name: "iOS" + version: "7.0" + platform: + type: "bot" + vendor: "Bing" + engine: + name: "WebKit" + version: "537.51.1" + BingPreviewbot: + - + ua: "Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 530) like Gecko BingPreview/1.0b" + spec: + browser: + name: "BingPreviewbot" + version: "1.0b" + os: + name: "Windows Phone" + version: "8.1" + platform: + type: "bot" + vendor: "Bing" + engine: + name: "Trident" + version: "7.0" \ No newline at end of file From 107c9c7411c595a92efed3ff8dc0e28e7ed1d80d Mon Sep 17 00:00:00 2001 From: Cattttttttt <1067812695@qq.com> Date: Thu, 21 Jan 2021 21:03:00 +0800 Subject: [PATCH 2/2] Support Sogou Browser and Some Search Bots --- src/parser-browsers.js | 30 +++++++++++++++--------------- src/parser-platforms.js | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/parser-browsers.js b/src/parser-browsers.js index a7291d17..3bf51992 100644 --- a/src/parser-browsers.js +++ b/src/parser-browsers.js @@ -53,7 +53,7 @@ const browsersList = [ }; const version = Utils.getFirstMatch(/baiduspider(?:-ads|-render|-video|-image|-news|-favo|-cpro)?\/(\d+(\.\d+))/i, ua); - if(version) { + if (version) { browser.version = version; } @@ -66,14 +66,14 @@ const browsersList = [ const hash = { bingbot: 'Bingbot', bingpreview: 'BingPreviewbot', - adidxbot: 'BingAdsbot' + adidxbot: 'BingAdsbot', }; const browser = { name: hash[ua.match(/bingbot|bingpreview|adidxbot/i)[0].toLowerCase()], }; const version = Utils.getFirstMatch(/(?:bingbot|adidxbot|bingpreview)\/(\d+(\.\d+)[a-zA-Z]?)/i, ua); - if(version) { + if (version) { browser.version = version; } @@ -150,21 +150,21 @@ const browsersList = [ const browser = { name: (/SogouMobileBrowser/i).test(ua) ? 'Sogou Mobile Browser' : 'Sogou Browser', }; - const version = browser.name === 'Sogou Browser' ? - Utils.getFirstMatch(/Chrome[\s/](\d+)/i, ua) : - Utils.getFirstMatch(/SogouMobileBrowser[\s/](\d+(?:\.\d+)+)/i, ua); + const version = browser.name === 'Sogou Browser' + ? Utils.getFirstMatch(/Chrome[\s/](\d+)/i, ua) + : Utils.getFirstMatch(/SogouMobileBrowser[\s/](\d+(?:\.\d+)+)/i, ua); const hash = { - '35': '5.1', - '38': '5.3', - '49': '6.3', - '58': '7.5', - '65': '8.6', - '72': '10.0', - '80': '11.0', + 35: '5.1', + 38: '5.3', + 49: '6.3', + 58: '7.5', + 65: '8.6', + 72: '10.0', + 80: '11.0', }; - if(version) { - browser.version = hash[version] || version; + if (version) { + browser.version = hash[version] || (browser.name !== 'Sogou Browser' && version); } return browser; diff --git a/src/parser-platforms.js b/src/parser-platforms.js index 517cbf18..3542ab7c 100644 --- a/src/parser-platforms.js +++ b/src/parser-platforms.js @@ -23,7 +23,7 @@ export default [ describe() { return { type: 'bot', - vendor: 'Baidu', + vendor: 'Baidu', }; }, },