mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 16:08:47 +03:00
Backport - Prevent altering the result when supplied user-agent is different from current user-agent
Reference: Commit: b09878934fce1de9bcadace72cc3a6fd6c613e34
This commit is contained in:
parent
2e06a34062
commit
5b8adfef7b
@ -803,6 +803,7 @@
|
|||||||
var _ua = ua || ((_navigator && _navigator.userAgent) ? _navigator.userAgent : EMPTY);
|
var _ua = ua || ((_navigator && _navigator.userAgent) ? _navigator.userAgent : EMPTY);
|
||||||
var _uach = (_navigator && _navigator.userAgentData) ? _navigator.userAgentData : undefined;
|
var _uach = (_navigator && _navigator.userAgentData) ? _navigator.userAgentData : undefined;
|
||||||
var _rgxmap = extensions ? extend(regexes, extensions) : regexes;
|
var _rgxmap = extensions ? extend(regexes, extensions) : regexes;
|
||||||
|
var _isSelfNav = _navigator && _navigator.userAgent == _ua;
|
||||||
|
|
||||||
this.getBrowser = function () {
|
this.getBrowser = function () {
|
||||||
var _browser = {};
|
var _browser = {};
|
||||||
@ -811,7 +812,7 @@
|
|||||||
rgxMapper.call(_browser, _ua, _rgxmap.browser);
|
rgxMapper.call(_browser, _ua, _rgxmap.browser);
|
||||||
_browser[MAJOR] = majorize(_browser[VERSION]);
|
_browser[MAJOR] = majorize(_browser[VERSION]);
|
||||||
// Brave-specific detection
|
// Brave-specific detection
|
||||||
if (_navigator && _navigator.brave && typeof _navigator.brave.isBrave == FUNC_TYPE) {
|
if (_isSelfNav && _navigator && _navigator.brave && typeof _navigator.brave.isBrave == FUNC_TYPE) {
|
||||||
_browser[NAME] = 'Brave';
|
_browser[NAME] = 'Brave';
|
||||||
}
|
}
|
||||||
return _browser;
|
return _browser;
|
||||||
@ -828,11 +829,11 @@
|
|||||||
_device[MODEL] = undefined;
|
_device[MODEL] = undefined;
|
||||||
_device[TYPE] = undefined;
|
_device[TYPE] = undefined;
|
||||||
rgxMapper.call(_device, _ua, _rgxmap.device);
|
rgxMapper.call(_device, _ua, _rgxmap.device);
|
||||||
if (!_device[TYPE] && _uach && _uach.mobile) {
|
if (_isSelfNav && !_device[TYPE] && _uach && _uach.mobile) {
|
||||||
_device[TYPE] = MOBILE;
|
_device[TYPE] = MOBILE;
|
||||||
}
|
}
|
||||||
// iPadOS-specific detection: identified as Mac, but has some iOS-only properties
|
// iPadOS-specific detection: identified as Mac, but has some iOS-only properties
|
||||||
if (_device[MODEL] == 'Macintosh' && _navigator && typeof _navigator.standalone !== UNDEF_TYPE && _navigator.maxTouchPoints && _navigator.maxTouchPoints > 2) {
|
if (_isSelfNav && _device[MODEL] == 'Macintosh' && _navigator && typeof _navigator.standalone !== UNDEF_TYPE && _navigator.maxTouchPoints && _navigator.maxTouchPoints > 2) {
|
||||||
_device[MODEL] = 'iPad';
|
_device[MODEL] = 'iPad';
|
||||||
_device[TYPE] = TABLET;
|
_device[TYPE] = TABLET;
|
||||||
}
|
}
|
||||||
@ -850,7 +851,7 @@
|
|||||||
_os[NAME] = undefined;
|
_os[NAME] = undefined;
|
||||||
_os[VERSION] = undefined;
|
_os[VERSION] = undefined;
|
||||||
rgxMapper.call(_os, _ua, _rgxmap.os);
|
rgxMapper.call(_os, _ua, _rgxmap.os);
|
||||||
if (!_os[NAME] && _uach && _uach.platform != 'Unknown') {
|
if (_isSelfNav && !_os[NAME] && _uach && _uach.platform != 'Unknown') {
|
||||||
_os[NAME] = _uach.platform
|
_os[NAME] = _uach.platform
|
||||||
.replace(/chrome os/i, CHROMIUM_OS)
|
.replace(/chrome os/i, CHROMIUM_OS)
|
||||||
.replace(/macos/i, MAC_OS); // backward compatibility
|
.replace(/macos/i, MAC_OS); // backward compatibility
|
||||||
|
Loading…
x
Reference in New Issue
Block a user