From 1a521b867ff5b23d2a75eb5d62e10e22d78998ee Mon Sep 17 00:00:00 2001 From: Faisal Salman Date: Wed, 25 Jan 2023 01:05:50 +0700 Subject: [PATCH] Utilize navigator.userAgentData as a fallback #588 --- src/ua-parser.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ua-parser.js b/src/ua-parser.js index 31bc93a..1ea2344 100755 --- a/src/ua-parser.js +++ b/src/ua-parser.js @@ -775,6 +775,7 @@ } var _ua = ua || ((typeof window !== UNDEF_TYPE && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : EMPTY); + var _uach = (typeof window !== UNDEF_TYPE && window.navigator && window.navigator.userAgentData) ? window.navigator.userAgentData : undefined; var _rgxmap = extensions ? extend(regexes, extensions) : regexes; this.getBrowser = function () { @@ -797,6 +798,9 @@ _device[MODEL] = undefined; _device[TYPE] = undefined; rgxMapper.call(_device, _ua, _rgxmap.device); + if (!_device[TYPE] && _uach && _uach.mobile) { + _device[TYPE] = MOBILE; + } return _device; }; this.getEngine = function () { @@ -811,6 +815,9 @@ _os[NAME] = undefined; _os[VERSION] = undefined; rgxMapper.call(_os, _ua, _rgxmap.os); + if (!_os[NAME] && _uach && _uach.platform != 'Unknown') { + _os[NAME] = _uach.platform.replace(/chrome/i, 'Chromium').replace(/mac/i, 'Mac '); + } return _os; }; this.getResult = function () {