How do I tell if a user is using Brave as their browser?

后端 未结 9 677
旧巷少年郎
旧巷少年郎 2021-02-04 01:29

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

9条回答
  •  独厮守ぢ
    2021-02-04 02:18

    Brave has a class Brave, which is created and added to navigator as navigator.brave upon page load. It has one method which returns a promise: Brave.prototype.isBrave() Using these three you can create a check for brave browser (something like this):

    var isBrave = false;
    if(window.Brave&&navigator.brave&&navigator.brave.isBrave){
        isBrave = 'probable';//or some other value, as you wish
        navigator.brave.isBrave().then(function(r){
            if(r)isBrave = true;
        });
    }
    

提交回复
热议问题