Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support more browsers #28

Open
itusprotanha opened this issue Oct 5, 2023 · 5 comments
Open

Support more browsers #28

itusprotanha opened this issue Oct 5, 2023 · 5 comments

Comments

@itusprotanha
Copy link

itusprotanha commented Oct 5, 2023

Hi bro, you are doing well, and thank you for your contribution.

Currently, this library supports a few common browsers. Can we add more browsers to make the parse function more exactly?

We have a list of 272 browsers with user agent examples from this link: https://user-agents.net/browsers

For example: Coc Coc Browser
image

Javascript package: https://github.com/faisalman/ua-parser-js/tree/master

@mileusna
Copy link
Owner

mileusna commented Oct 5, 2023

Hello,

Package focus more on most common browsers, but its "best guess" approach detects most of the browsers correctly, for example Coc Coc browser will be detected as coc_coc_browser from the User Agent string.

But yes, it is possible to put all the browsers from the list into the test and make it all work correctly if there are some issues.

@Nikola-Milovic
Copy link

Here's a snippet from a js library that does very similar thing.

https://github.com/DamonOehlman/detect-browser/blob/master/src/index.ts#L67

They took the approach of regexp which hands itself nicely to extending and supporting a lot of different entries, but is probably much slower.

@mileusna
Copy link
Owner

mileusna commented Oct 8, 2023

Yes, regexp is much slower, specially if you run it through the loop multiple times to match browser/OS, that is why this package parse the user agent string and then tries to match recognizable tokens. I still try to improve performance further.

@ayuhito
Copy link

ayuhito commented Sep 8, 2024

Yes, regexp is much slower.

They're pretty fast if compiled. Heavy string contains matching can sometimes be more expensive.

I benchmarked alternatives here and the regex-based solution with much more coverage ended up being on par with this library. Maybe there might be some easy wins to improve the performance by reducing the number of allocs because there are a lot that happen in this library.

@mileusna
Copy link
Owner

I will take a look, but overall footprint is very small, I run this on web sites and services with millions of daily page views and never had any issue with it. Sometimes people overreacts by looking at benchmarks and then they use the package for the service with total of 100 users.

Sure, if you are fortunate enough to work on services with billions requests, you should pick the fastest package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@mileusna @ayuhito @Nikola-Milovic @itusprotanha and others