by m45t3r · 6y ago · 0 comments
- Sites that try to detect mobile by looking at "ARM" in user-agent string
- Sites that try to parse the macOS minor version for some reason and would be confused to see something like "11_0"
BTW, user-agent is a hell anyway. Just looking at this user-agent that OP posted, macOS still identifies itself as "Mac OS X", still is based on Mozilla/5.0(!), still identifies itself as KHTML enginee (compatible with Gecko), and so on...
Browser makers tried to do that by providing feature detection, but the weight of legacy code and developers already used to using the user agent strings has made killing it impossible.
Edit: As pointed out in another comment here, it seems like Google is killing it (or planning to). [1]
[1]: https://www.zdnet.com/article/google-to-phase-out-user-agent...
But the many attempts to freeze the existing UA are for the purpose of stopping people testing through the UA
Because it only affect graphic, you can't really detect whether you are affected by it or not from js.
The best thing you can do it guess the browser from user-agent and apply the workaround anyway. Or you can pray for the apple to fix their sh*t (given what they have done in the past, it is unlikely).
This is why we have some more developers spending time on creating FOSS libraries that parse user agent strings and tell you exactly what the browser claims to be, with attributes like browser name, OS, version, browser engine, etc. All these libraries need updates (or at least a cursory look) whenever a new browser version is released so that they can continue identifying browsers correctly. All those people, bless them for this work, could be doing something else in an alternate universe.
Notwithstanding feature detection and graceful downgrades, browser user agent strings seem to be very commonly used to decide the behavior of many websites.
In the vast majority of use cases, these values should not be used to detect platform features - actual feature detection should be used instead.
And "actual feature detection" doesn't work with SSR, like, at all.
The latest iPadOS, for example, purposely reports itself as a Mac desktop because too many sites saw 'MobileSafari' and returned a sub-par site experience based on a small mobile phone screen. But it actually goes beyond that:
1. It lets the user toggle the user agent themselves between mobile and desktop (iPhone and Mac Desktop style agents)
2. The browser will by default use a mobile user agent when rendering in a small form, such as a browser in a smaller modal window or a side-bar.
Client hints might provide a way to actually formalize a contract for SSR apps, if people participate and indicate what they need.
It doesn't make sense to make the choice of what to render on the user agent: for example if it says Android, what does it mean? It is probably a smartphone, but it could also be a tablet, a TV, or even a PC!
An even more stupid idea is to redirect the user to a different domain if you detect that the user agent is mobile, since it usually work one way and thus if you share on a chat the link to the mobile version of the site and the other one opens it on a desktop there is no easy way to get back to the desktop site (most of the times I have to modify the URL!)