Skip to content

Commit

Permalink
Backport - Improve browser detection: unified name for Baidu (cherry …
Browse files Browse the repository at this point in the history
…picked from commit 9cc274f)
  • Loading branch information
faisalman committed Oct 27, 2023
1 parent 23c5d77 commit c41100e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 34 deletions.
7 changes: 4 additions & 3 deletions src/ua-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,12 @@
], [VERSION, [NAME, OPERA]], [

// Mixed
/\bb[ai]*d(?:uhd|[ub]*[aekoprswx]{5,6})[\/ ]?([\w\.]+)/i // Baidu
], [VERSION, [NAME, 'Baidu']], [
/(kindle)\/([\w\.]+)/i, // Kindle
/(lunascape|maxthon|netfront|jasmine|blazer)[\/ ]?([\w\.]*)/i, // Lunascape/Maxthon/Netfront/Jasmine/Blazer
// Trident based
/(avant|iemobile|slim)\s?(?:browser)?[\/ ]?([\w\.]*)/i, // Avant/IEMobile/SlimBrowser
/(ba?idubrowser)[\/ ]?([\w\.]+)/i, // Baidu Browser
/(avant|iemobile|slim)\s?(?:browser)?[\/ ]?([\w\.]*)/i, // Avant/IEMobile/SlimBrowser
/(?:ms|\()(ie) ([\w\.]+)/i, // Internet Explorer

// Webkit/KHTML based // Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium/PhantomJS/Bowser/QupZilla/Falkon
Expand Down Expand Up @@ -285,7 +286,7 @@
], [[NAME, 'Sogou Mobile'], VERSION], [
/(electron)\/([\w\.]+) safari/i, // Electron-based App
/(tesla)(?: qtcarbrowser|\/(20\d\d\.[-\w\.]+))/i, // Tesla
/m?(qqbrowser|baiduboxapp|2345Explorer)[\/ ]?([\w\.]+)/i // QQBrowser/Baidu App/2345 Browser
/m?(qqbrowser|2345Explorer)[\/ ]?([\w\.]+)/i // QQBrowser/2345 Browser
], [NAME, VERSION], [
/(lbbrowser)/i, // LieBao Browser
/\[(linkedin)app\]/i // LinkedIn App for iOS & Android
Expand Down
92 changes: 61 additions & 31 deletions test/browser-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,71 @@
"ua" : "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; baidubrowser 1.x)",
"expect" :
{
"name" : "baidubrowser",
"name" : "Baidu",
"version" : "1.x",
"major" : "1"
}
},
{
"desc" : "Baidu",
"ua" : "Mozilla/5.0 (Linux; Android 9; Redmi Note 5 Build/PKQ1.180904.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/110.0.5481.153 Mobile Safari/537.36 bdbrowser/6.4.0.4",
"expect" :
{
"name" : "Baidu",
"version" : "6.4.0.4",
"major" : "6"
}
},
{
"desc" : "Baidu",
"ua" : "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.4.9999.1900 Safari/537.31 BDSpark/26.4",
"expect" :
{
"name" : "Baidu",
"version" : "26.4",
"major" : "26"
}
},
{
"desc" : "Baidu",
"ua" : "Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) BaiduHD/5.4.0.0 Mobile/10A406 Safari/8536.25",
"expect" :
{
"name" : "Baidu",
"version" : "5.4.0.0",
"major" : "5"
}
},
{
"desc" : "BaiDu Browser",
"ua" : "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 BIDUBrowser/8.7 Safari/537.36",
"expect" :
{
"name" : "Baidu",
"version" : "8.7",
"major" : "8"
}
},
{
"desc" : "baidu app on iOS",
"ua" : "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16C101 main%2F1.0 baiduboxapp/11.12.0.18 (Baidu; P2 12.1.2)",
"expect" :
{
"name" : "Baidu",
"version" : "11.12.0.18",
"major" : "11"
}
},
{
"desc" : "baidu app on Android",
"ua" : "Mozilla/5.0 (Linux; Android 8.1.0; BKK-AL10 Build/HONORBKK-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/63.0.3239.83 Mobile Safari/537.36 T7/11.11 baiduboxapp/11.11.0.0 (Baidu; P1 8.1.0)",
"expect" :
{
"name" : "Baidu",
"version" : "11.11.0.0",
"major" : "11"
}
},
{
"desc" : "Bolt",
"ua" : "Mozilla/5.0 (X11; 78; CentOS; US-en) AppleWebKit/527+ (KHTML, like Gecko) Bolt/0.862 Version/3.0 Safari/523.15",
Expand Down Expand Up @@ -1648,26 +1708,6 @@
"major" : "6"
}
},
{
"desc" : "baidu app on iOS",
"ua" : "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16C101 main%2F1.0 baiduboxapp/11.12.0.18 (Baidu; P2 12.1.2)",
"expect" :
{
"name" : "baiduboxapp",
"version" : "11.12.0.18",
"major" : "11"
}
},
{
"desc" : "baidu app on Android",
"ua" : "Mozilla/5.0 (Linux; Android 8.1.0; BKK-AL10 Build/HONORBKK-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/63.0.3239.83 Mobile Safari/537.36 T7/11.11 baiduboxapp/11.11.0.0 (Baidu; P1 8.1.0)",
"expect" :
{
"name" : "baiduboxapp",
"version" : "11.11.0.0",
"major" : "11"
}
},
{
"desc" : "WeChat Desktop for Windows Built-in Browser",
"ua" : "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 MicroMessenger/6.5.2.501 NetType/WIFI WindowsWechat QBCore/3.43.901.400 QQBrowser/9.0.2524.400",
Expand Down Expand Up @@ -1736,16 +1776,6 @@
"name" : "LBBROWSER"
}
},
{
"desc" : "BaiDu Browser",
"ua" : "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 BIDUBrowser/8.7 Safari/537.36",
"expect" :
{
"name" : "BIDUBrowser",
"version" : "8.7",
"major" : "8"
}
},
{
"desc" : "2345 Browser",
"ua" : "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.90 Safari/537.36 2345Explorer/9.2.1.17116",
Expand Down

0 comments on commit c41100e

Please sign in to comment.