diff --git a/.npmignore b/.npmignore index ae6d218..f402445 100644 --- a/.npmignore +++ b/.npmignore @@ -2,6 +2,8 @@ examples test .travis.yml .prettierrc +tsconfig.json +tslint.json src !index.js !index.d.ts diff --git a/package.json b/package.json index f197728..f2a289e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "detect-browser", - "version": "4.1.0", + "version": "4.3.0", "description": "Unpack a browser type and version from the useragent string", "main": "index.js", "scripts": { diff --git a/src/index.ts b/src/index.ts index 34aacc9..d03cec5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,6 +35,7 @@ type Browser = | 'kakaotalk' | 'samsung' | 'silk' + | 'miui' | 'chrome' | 'phantomjs' | 'crios' @@ -95,6 +96,7 @@ const userAgentRules: UserAgentRule[] = [ ['kakaotalk', /KAKAOTALK\s([0-9\.]+)/], ['samsung', /SamsungBrowser\/([0-9\.]+)/], ['silk', /\bSilk\/([0-9._-]+)\b/], + ['miui', /MiuiBrowser\/([0-9\.]+)$/], ['chrome', /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/], ['phantomjs', /PhantomJS\/([0-9\.]+)(:?\s|$)/], ['crios', /CriOS\/([0-9\.]+)(:?\s|$)/], @@ -113,6 +115,7 @@ const userAgentRules: UserAgentRule[] = [ ['facebook', /FBAV\/([0-9\.]+)/], ['instagram', /Instagram\s([0-9\.]+)/], ['ios-webview', /AppleWebKit\/([0-9\.]+).*Mobile/], + ['ios-webview', /AppleWebKit\/([0-9\.]+).*Gecko\)$/], ['searchbot', SEARCHBOX_UA_REGEX], ]; const operatingSystemRules: OperatingSystemRule[] = [ diff --git a/test/logic.js b/test/logic.js index 680cff2..cad41b5 100644 --- a/test/logic.js +++ b/test/logic.js @@ -16,6 +16,11 @@ test('detects Chrome', function(t) { { name: 'chrome', version: '41.0.2228', os: 'Windows 7' } ); + assertAgentString(t, + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36', + { name: 'chrome', version: '72.0.3626', os: 'Windows 10' } + ) + t.end(); }); @@ -233,6 +238,16 @@ test('detects native iOS WebView browser', function (t) { { name: 'ios-webview', version: '605.1.15', os: 'iOS' } ); + assertAgentString(t, + 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16B92', + { name: 'ios-webview', version: '605.1.15', os: 'iOS' } + ); + + assertAgentString(t, + 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko)', + { name: 'ios-webview', version: '605.1.15', os: 'iOS' } + ); + t.end(); }); @@ -277,7 +292,7 @@ test('detects Opera-Mini', function (t) { 'Opera/9.80 (Android; Opera Mini/8.0.1807/36.1609; U; en) Presto/2.12.423 Version/12.16', { name: 'opera-mini', version: '12.16.0', os: 'Android OS' } ); - + assertAgentString(t, 'Opera/9.80 (BlackBerry; Opera Mini/6.5.27548/27.2020; U; en) Presto/2.8.119 Version/11.10', { name: 'opera-mini', version: '11.10.0', os: 'BlackBerry OS' } @@ -309,7 +324,7 @@ test('detects Chrome OS', function (t) { 'Mozilla/5.0 (X11; CrOS x86_64 10895.78.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.120 Safari/537.36', { name: 'chrome', version: '69.0.3497', os: 'Chrome OS' } ); - + assertAgentString(t, 'Mozilla/5.0 (X11; U; CrOS i686 9.10.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Gecko/20100101 Firefox/29.0', { name: 'firefox', version: '29.0.0', os: 'Chrome OS' } @@ -317,6 +332,14 @@ test('detects Chrome OS', function (t) { t.end(); }); +test('detects miui', function(t) { + assertAgentString(t, + 'Mozilla/5.0 (Linux; U; Android 7.0; en-us; MI 5 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.146 Mobile Safari/537.36 XiaoMi/MiuiBrowser/9.0.3', + { name: 'miui', version: '9.0.3', os: 'Android OS' } + ); + t.end(); +}); + test('handles no browser', function(t) { assertAgentString(t, null,