mirror of
https://github.com/lancedikson/bowser
synced 2026-02-10 01:50:10 +00:00
Add support for navigator.brave.isBrave() detection
Co-authored-by: naorpeled <6171622+naorpeled@users.noreply.github.com>
This commit is contained in:
parent
f5d89c124d
commit
dfdb36ce96
@ -1023,6 +1023,10 @@ const browsersList = [
|
|||||||
/* Brave Browser */
|
/* Brave Browser */
|
||||||
{
|
{
|
||||||
test(parser) {
|
test(parser) {
|
||||||
|
// Check navigator.brave.isBrave() result from hints
|
||||||
|
if (parser.isBrave()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
// Check Client Hints brands for Brave
|
// Check Client Hints brands for Brave
|
||||||
return parser.hasBrand('Brave');
|
return parser.hasBrand('Brave');
|
||||||
},
|
},
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import Utils from './utils.js';
|
|||||||
* @property {string} [architecture] CPU architecture
|
* @property {string} [architecture] CPU architecture
|
||||||
* @property {string} [model] Device model
|
* @property {string} [model] Device model
|
||||||
* @property {boolean} [wow64] Whether running under WoW64
|
* @property {boolean} [wow64] Whether running under WoW64
|
||||||
|
* @property {boolean} [isBrave] Result of navigator.brave.isBrave() for Brave browser detection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -123,6 +124,16 @@ class Parser {
|
|||||||
return brand ? brand.version : undefined;
|
return brand ? brand.version : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the browser is Brave using navigator.brave.isBrave() result
|
||||||
|
* @return {boolean}
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
isBrave() {
|
||||||
|
return !!(this._hints && this._hints.isBrave === true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get UserAgent string of current Parser instance
|
* Get UserAgent string of current Parser instance
|
||||||
* @return {String} User-Agent String of the current <Parser> object
|
* @return {String} User-Agent String of the current <Parser> object
|
||||||
|
|||||||
@ -413,3 +413,25 @@ test('Parser.getBrandVersion returns version for Brave', (t) => {
|
|||||||
const p = new Parser(BRAVE_UA, false, BRAVE_HINTS);
|
const p = new Parser(BRAVE_UA, false, BRAVE_HINTS);
|
||||||
t.is(p.getBrandVersion('Brave'), '1.73.97');
|
t.is(p.getBrandVersion('Brave'), '1.73.97');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Parser.isBrave returns true when isBrave hint is set', (t) => {
|
||||||
|
const hints = { isBrave: true };
|
||||||
|
const p = new Parser(BRAVE_UA, false, hints);
|
||||||
|
t.true(p.isBrave());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Parser.isBrave returns false when isBrave hint is not set', (t) => {
|
||||||
|
const p = new Parser(BRAVE_UA, false, BRAVE_HINTS);
|
||||||
|
t.false(p.isBrave());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Parser.isBrave returns false when no hints provided', (t) => {
|
||||||
|
const p = new Parser(BRAVE_UA);
|
||||||
|
t.false(p.isBrave());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Parser detects Brave from isBrave hint', (t) => {
|
||||||
|
const hints = { isBrave: true };
|
||||||
|
const p = new Parser(BRAVE_UA, false, hints);
|
||||||
|
t.is(p.getBrowserName(), 'Brave');
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user