Remix.run Logo
Device-detector: Universal Device Detection library from User Agent(github.com)
69 points by josephscott 14 hours ago | 19 comments
ChrisMarshallNY 19 minutes ago | parent | next [-]

Many years ago (pre-smartphone), there was a Java library, written by an Italian chap, that did pretty much the same thing. Don’t remember the name. This appears to use the same approach. I think they had PHP version, but that was a long time ago. I know it was several megabytes, which was huge, in those days.

Did what it said on the tin, but did so, by maintaining a huge list of individual devices and their characteristics. At the time, I chose not to use it (I was developing a [c]WAP server), but it had a number of supporters, and its maintainer was pretty sharp, and quite dedicated.

These days, there’s an order of magnitude more devices, and a much greater variety. Big job.

selamtux 7 minutes ago | parent | prev | next [-]

i was need something similar for golang and i try to use regexes in those projects, but in eye of performance it wasnt good enough. sometimes i wish to understand more deeply regexes.

it maybe another way to speed up for golang like prefix tree instead of using regexes, any one know a something similar for golang?

donatj 8 hours ago | parent | prev | next [-]

I've got a more limited and performant library I maintain. It frequently comes in first in speed comparisons.

It can only tell you things actually included in the UA string itself as it's just be a parser and not a "knowledge engine"

https://github.com/donatj/PhpUserAgent

foreigner 2 hours ago | parent | prev | next [-]

I need a way to detect the screen DPI from the user agent, so I can return higher resolution images only to devices that can use them. I realize detecting that based on user agent may not always be accurate, but surely it could work the vast majority of the time. Does anybody know of a lib that implements that on NodeJS?

AndrewStephens 37 minutes ago | parent | next [-]

Consider using the img tag’s srcset property for this purpose. It has many advantages over what you are suggesting.

https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageEl...

foreigner 24 minutes ago | parent [-]

I didn't realize srcset could select for "pixel density", thanks for the tip!

agos an hour ago | parent | prev | next [-]

what can you say about DPI from a string like "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"? I don't think it's possible from the user agent, but it's a one liner in Javascript

ivan_gammel an hour ago | parent | prev [-]

Please consider taking network speed into account. The device can be great but on mobile network it may take ages to load everything, depending on the location (e.g. on a train you may not have stable 5G long enough).

qingcharles 8 hours ago | parent | prev | next [-]

I have a bot I wrote to help me with various web tasks that are too tedious manually. I just tested it against this and it says "isbot: false".

edit: looks like it only detects bots that overtly identify themselves as bots, e.g. Googlebot -- it's designed to identify clients, not as some sort of security device

riiii 2 hours ago | parent [-]

That flag should be called isKnownBot.

PeterStuer an hour ago | parent | prev | next [-]

The reverse would also be handy. Device-pretender: Universal comprehensive User Agent from pretender library.

benzimmer 13 hours ago | parent | prev | next [-]

If you're looking for a Ruby implementation based on the same underlying user-agent parsing data, here you go: https://github.com/podigee/device_detector

vinnymac 13 hours ago | parent [-]

The README lists all the ports here: https://github.com/matomo-org/device-detector?tab=readme-ov-...

sibeliuss 12 hours ago | parent | prev | next [-]

PHP made it to the front page!

xnx 13 hours ago | parent | prev | next [-]

Good tool. I wish Google had gone even further with Chrome in reducing the information in the user agent. It seems like user agent is primarily used as a browser fingerprinting signal.

kristofferg 9 hours ago | parent [-]

Indeed - its been years since browsing anonymity was possible (without rigorous opsec and inconvenience).

legrandmag 12 hours ago | parent | prev [-]

Does something similar exist for python or node.js ?

If not I would like to contribute to that as an open source.

fyzlman 5 hours ago | parent | next [-]

I made something similar, but with a JavaScript-first approach:

https://github.com/faisalman/ua-parser-js

revscat 11 hours ago | parent | prev [-]

https://github.com/matomo-org/device-detector

List of ports