Skip to content

Commit

Permalink
Utilize navigator.userAgentData as a fallback #588
Browse files Browse the repository at this point in the history
  • Loading branch information
faisalman committed Jan 24, 2023
1 parent 5d4ca2b commit 1a521b8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/ua-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand Down

0 comments on commit 1a521b8

Please sign in to comment.