Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Sogou Browser and Some Search Bots #463

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
64 changes: 63 additions & 1 deletion src/parser-browsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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],
Expand Down Expand Up @@ -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] || (browser.name !== 'Sogou Browser' && version);
}

return browser;
},
},
{
test: [/MZBrowser/i],
describe(ua) {
Expand Down
20 changes: 20 additions & 0 deletions src/parser-platforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
146 changes: 146 additions & 0 deletions test/acceptance/useragentstrings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"