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

后端 未结 9 695
旧巷少年郎
旧巷少年郎 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:16

    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()
    

提交回复
热议问题