DamonOehlman / detect-browser

Unpack a browser type and version from the useragent string
MIT License
687 stars 102 forks source link

Unable to detect Brave Browser #159

Open jeynergil opened 3 years ago

jeynergil commented 3 years ago

This is an awesome package.

Can it detect Brave Browser?

Using Brave, it returned this:

BrowserInfo {name: "chrome", version: "88.0.4324", os: "Android OS", type: "browser"}
name: "chrome"
os: "Android OS"
type: "browser"
version: "88.0.4324"

Thanks!

DamonOehlman commented 3 years ago

@jeynergil If you can capture the user agent string I can take a look.

jeynergil commented 3 years ago

Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.152 Mobile Safari/537.36

dFilipkowski0131 commented 3 years ago

i dont believe it will provide your brave due to the fact that edge and brave are both chromium browsers at their base level

DamonOehlman commented 3 years ago

@jeynergil @dFilipkowski0131 based on that user agent string, I feel like that is definitely going to be the case. Feels like at some stage detect-browser should be returning something "less specific". I've been running Brave for the last couple of weeks for personal use, and I just looked at the user agent here on my laptop and despite running on Windows I see exactly the same user agent string.

I think the browser developers are definitely ramping up their efforts to ensure we aren't using user agent strings!

Benibur commented 3 years ago

you can detect Brave this way (I tested) : (navigator.brave && await navigator.brave.isBrave() || false) found here : https://stackoverflow.com/a/60954062

martonlederer commented 3 years ago

You can also make a request to https://api.duckduckgo.com/?q=useragent&format=json and that shows Brave as a user-agent

lancesnider commented 11 months ago

you can detect Brave this way (I tested) : (navigator.brave && await navigator.brave.isBrave() || false) found here : https://stackoverflow.com/a/60954062

I started to make a PR for this, but got stuck on testing. I can't see a way with tape to mock navigation to include navigation.brave.isBrave(). If anyone knows how to do that, I'll happily add a PR.

DamonOehlman commented 11 months ago

@lancesnider Thanks for having a crack at a PR. I'm thinking that the best way to deal with the various "work arounds" required to detect browsers these days might be to add a separate file into the repo that includes the various hacks. Ideally, I'd like to keep the core functionality of this module to UA sniffing even though it's very unreliable these days. The alternative is to make the module detect all browsers by default (including the various hacks required to do so) and if people want to only use the UA sniffing they can only import that function and let dead code elimination strip out the unused code from this package.

Just trying to think of the best way to structure it. Certainly having to execute async functions to detect a browser does change the game a little.

lancesnider commented 11 months ago

Yeah, that all makes sense.

Regarding the async, I didn't end up needing it. if(navigator.brave) worked fine.