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

后端 未结 9 673
旧巷少年郎
旧巷少年郎 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 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.

提交回复
热议问题