3 ms·
what are better methods?
by logicallee 4y ago
what are better methods?
- MBCook 4y agoJust check if the thing you want is defined in JS. Maybe add some supplementary methods to help with that kind of check. Parsing out the UA header mess is a disaster.
- andirk 4y agoThis is the correct answer. Allow 3rd party analytics or whatever to do as they choose, but your javascript should pretty much never believe a UA string. `if (someFeature && someFeature.someSpecificMethod)...` Or you can try/catch if you are less sympathetic to inferior tech.
- Macha 4y agoThis would be sufficient if features were a yes/no binary of supported or not, but sometimes browsers implement features but get them wrong, or incompletely.
- Xelynega 4y agoThen the features aren't supported in the browser and you should file a bug report to the vendor. Having the developers that use a tool work around the bugs in that tool is a recipe for having millions of repeated lines of code that don't actually solve the problem upstream.
- masswerk 4y agoThe problem being that browser vendors tend to implement Web APIs early, before the API and the respective specifications are frozen and are still likely to vary. They may even implement a certain (still valid) interpretation of the specs, which then turns out to be not exactly what everybody else eventually implements, but may stick to this for some time. (There are examples for about every browser vendor on the planet for this. Without this, if everybody had waited for finalized specs, we wouldn't have web sockets, web databases, or Web RTC for years now.) How do you handle this without version numbers?
- toast0 4y agoIt can be difficult to check for bugs in this manner. Especially if the feature you want to use worked fine before, then has one or two version where it crashes, and then works again. If you feature test for browser crashes, people are going to think it's your site, not their browser.
- mmis1000 4y agoThat don't work with render only bug, safari has tons of them. And in that case, JS is useless. Because everything reports correct, only the screen messed up. Another example, Android webview 69 on certain devices has a bug that will take down the whole app. There is no way you can workaround it without ua sniffing. Because a single try will take the whole app away.