Skip to content

Commit 73c2577

Browse files
committed
Fix #498 - Detect Brave Browser by checking navigator.brave
brave/brave-browser#10165 (comment) (cherry picked from commit 03b0a5a)
1 parent f8e5a1f commit 73c2577

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/ua-parser.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -786,16 +786,21 @@
786786
return new UAParser(ua, extensions).getResult();
787787
}
788788

789-
var _ua = ua || ((typeof window !== UNDEF_TYPE && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : EMPTY);
790-
var _uach = (typeof window !== UNDEF_TYPE && window.navigator && window.navigator.userAgentData) ? window.navigator.userAgentData : undefined;
789+
var _navigator = (typeof window !== UNDEF_TYPE && window.navigator) ? window.navigator : undefined;
790+
var _ua = ua || ((_navigator && _navigator.userAgent) ? _navigator.userAgent : EMPTY);
791+
var _uach = (_navigator && _navigator.userAgentData) ? _navigator.userAgentData : undefined;
791792
var _rgxmap = extensions ? extend(regexes, extensions) : regexes;
792793

793794
this.getBrowser = function () {
794795
var _browser = {};
795796
_browser[NAME] = undefined;
796797
_browser[VERSION] = undefined;
797798
rgxMapper.call(_browser, _ua, _rgxmap.browser);
798-
_browser.major = majorize(_browser.version);
799+
_browser[MAJOR] = majorize(_browser[VERSION]);
800+
// Brave-specific detection
801+
if (_navigator && _navigator.brave && typeof _navigator.brave.isBrave == FUNC_TYPE) {
802+
_browser[NAME] = 'Brave';
803+
}
799804
return _browser;
800805
};
801806
this.getCPU = function () {

0 commit comments

Comments
 (0)