6 ms·
I have been on receiving end of browser bugs, developing cutting edge JavaScript applications. It's VERY useful to be able to use the UA string to do something
by jackjeff 7y ago
I have been on receiving end of browser bugs, developing cutting edge JavaScript applications.
It's VERY useful to be able to use the UA string to do something like:
if (Chrome version X) then { do this crazy workaround because Chrome is broken }
No. People don't even necessarily update to the latest version. The "Samsung Browser" was notorious for seemingly always be some old fork of Chrome or Chromium that would never update.
- pornel 7y agoThat approach is fragile, because it won't stop applying the crazy workaround after Chrome version Y fixes the problem. You can't know which version it's going to be, and there's a chance you won't be maintaining that code anymore then.
- wvenable 7y agoBut if you can't sniff the browser version, you might still have to apply the crazy work around forever because you have no way of knowing when to stop. It works both ways.
- dessant 7y agoThe correct approach is to use feature detection. There are libraries available for it, such as Modernizr [1]. [1] https://modernizr.com/docs/#what-is-feature-detection https://modernizr.com/docs/#what-is-feature-detection
- wvenable 7y agoYou can't always feature detect bugs. I'm not sure why this entire thread is filled "use feature detection" when it's been historically clear that it isn't sufficient.
- shakna 7y agoPart of the proposed deprecation of the useragent is a JS API to expose the information.
- deleted 7y ago[deleted]
- Rebelgecko 7y agoA JS API that tells you which bugs exist in the browser?
- shakna 7y ago> Where feature detection fails developers, UA Client Hints are the right path forward. UA Client Hints will provide: brand, major version, full version, platform brand and architecture, platform architecture, model and whether it should be treated as a mobile platform. If you were using the UserAgent to guess if the browser was a particular version with a particular bug, now you don't have to parse something and probably get it wrong.
- Jon_Lowtek 7y ago> UA Client Hints will provide: brand, major version, ... It seems you are using "Mozilla 5.0". Your browser is really out of date! Please consider updating to rand("Googlebot/2.1", "Version/7", "XUL/97", "HTML/5").
- shakna 7y agoThere's no guarantee the user's browser will just hand over that information with the new spec: > User agents ought to exercise judgement before granting access to this information, and MAY impose restrictions above and beyond the secure transport and delegation requirements noted above.
- pjmlp 7y ago
- microtherion 7y agoFor that to work, browsers would also have to accurately advertise their own bugs/quirks, which might be a difficult ask.
- ebiester 7y agoWouldn't those quirks be sufficient to fingerprint in the same way?
- microtherion 7y agoWhat if the DOM looks perfectly normal, but doesn't render correctly?
- pixelbash 7y agoThe fundamental issue with this is it tells you about what's there when what you need to know is what's broken (not even necessarily what's missing).
- Lx1oG-AWb6h_ZG0 7y agoBut this is only accessible on the client side, what about all the other backcompat code on the server side (like the SameSite issue mentioned elsewhere in the thread?) Or server-side rendering? Are we not supposed to care about progressive enhancement anymore?
- Kiro 7y agoI build HTML5 games and I need to use very specific hacks for certain browsers, e.g. use a different offscreen canvas implementation for Safari due to performance. I can't use feature detection since it's not about a missing feature.
- clopez 7y agoYou can benchmark the alternatives for 2 seconds and choose the faster. Call it: performance detection
- AdamTReineke 7y ago+1. The number of rendering invalidation bugs I had to work around in mobile Safari is crazy. `if(affectedBrowserUA) { elem.style.transform = 'translate3d(0,0,0); elem.style.transform = ''; }` Edit: I guess you can achieve the same thing through UA client hints. Just need to add a new JS file that reads the request headers and maps them into JS globals.
- tbodt 7y agoThere's a proposed API for JavaScript to get the same information.
- AdamTReineke 7y agoOh, yup, I see that now. That was the next point after the headers one in the spec.
- kerkeslager 7y agoI'd argue that if you're doing this you can't have tested your JavaScript on many platforms. This breaks very quickly in my experience. Feature detection[1] is a much better strategy. That can get complicated too, but often there are third-party polyfills that can do that for you. [1] https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Feature_detection https://developer.mozilla.org/en-US/docs/Learn/Tools_and_tes...
- henryfjordan 7y agoIn the short-term this might be annoying, but in the longer term this is going to force browsers to adhere more closely to standards. When sites are less able to write different code for different browsers, the onus to fix inconsistencies will transfer from site-maintainers to browser-maintainers. In 5 years you might look back and realize you no longer write browser-specific code any more.
- pjmlp 7y agoI have been involved with Web development in some form since late 90's, nice utopia that will never happen. Unless in 5 years we have only Chrome left, then surely.
- jedberg 7y ago> In 5 years you might look back and realize you no longer write browser-specific code any more. We said the same thing when IE started losing market share a decade ago. The problem is, everyone who makes a browser thinks they have the best ideas in the world, and then impliment them, but their users never blame the browser. If someone is trying to access your site and it breaks, do you really think they're going to say, "dang, I should really tell Chrome to fix their incompatibility". No, they will always assume the error lies with the site owner.
- bhk 7y agoIn such a world, it is not standards that win. It is the predominant browser that wins. Are you old enough to remember the "best viewed with Netscape" badges that were everywhere in the 90s?
- necovek 7y agoHaha, brings back the old days. I had my sites plastered with "best viewed with your eyes" badges, but that never took hold :)