I have been messing around with the Brave browser (https://www.brave.com/), an I cannot figure out how to determine how if a user is using Brave. I used a simp
As of April 2020, you can use this detection method to get a boolean answer to whether the user is using Brave or not:
(navigator.brave && await navigator.brave.isBrave() || false)
The "Brave" in the user agent was removed in the 0.9 version.
From the changelog:
Removed Brave from the User Agent HTTP header to reduce fingerprinting.
Brave doesn’t have its own User-Agent, as pointed out in other answers. However, you can quite easily fingerprint it to differentiate it from Google Chrome. The current release, version 0.23.19, has at least 40 unique characteristics that can tell it apart from other browsers. I go into more detail on that in this article. However, this is a riddiculous sulution. Please just ask Brave to restore their own User-Agent string.
Kohjah Breese's solution isn't working to detect Brave on Android (e.g. Chrome is detected as Brave). But as he said "If you search DuckDuckGo for [what's my user agent] they will return Brave." Then you can use the API of Duckduckgo to know if they browser is Brave :
var request = new XMLHttpRequest()
request.open('GET', 'https://api.duckduckgo.com/?q=useragent&format=json', true)
request.onload = function () {
var data = JSON.parse(this.response)
var isBrave = data['Answer'].includes('Brave');
if(isBrave){
console.log( isBrave );
}
}
request.send()
2020. Updated solution:
Chrome now adds a new key to the window object: googletag, as opposed to the old one: google
This is the working code now:
const ua = window.navigator.userAgent.toLowerCase();
const isChrome = /chrome|crios/.test(ua) && ! /edge|opr\//.test(ua)
const isBrave = isChrome && ! window.googletag;
Brave appears has some different objects in the window object. I'm not sure how contiguous these are across Brave versions, but I noted two in the window.navigator object that are blanked out: plugins and mimeTypes. Since Brave is meant to be a privacy browser I think it's a good chance these will remain blanked. So my check is to check the length of those.
Please note that you also need to check for the browser being desktop first; it doesn't seem you can detect the Brave Mobile browser; and the below code will pick up many mobile browsers
var agent = navigator.userAgent.toLowerCase();
var isChrome = /chrome|crios/.test(agent) && ! /edge|opr\//.test(agent);
var isBrave = isChrome && window.navigator.plugins.length === 0 && window.navigator.mimeTypes.length === 0;
if(isBrave)
console.log( isBrave );
If you search DuckDuckGo for [what's my user agent] they will return Brave. If you open the attached JS files you will find an elaborate browser detection that can detect Brave.