-3

Requirement: I have to show a popup(under maintenance) to block the using of our website through TV browser. We are using ReactJS.

I'm unable to get the device information(to check whether its a tv device) using the UserAgents that we are getting from Toshiba and Huawei Tvs

I tried to find the device is a TV using user agents but it does n't work for all TVs

Some examples of user agents that we got from TVs but it doesn't provide any info about detecting TVs

Toshiba - Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X;en-us) AppleWebKit/534.46(KHTML,like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3

Huawei TV - Mozilla/5.0 (Linux; Android 10.0; KANT-359 Build/HUAWEIKANT-359) AppleWebKit/537.36(KHTML,like Gecko) Chrome/50.0.2661.89 Mobile Safari/537.36

Please help!

Raphael
  • 1
  • 2
  • This isn't reliable. Lots of browsers have overtime spoofed the user agents of other browsers. If there's something a browser doesn't provide which the application needs, use feature detection – Aluan Haddad Aug 08 '23 at 06:27
  • Hi @AluanHaddad, thanks for replying. Can you please give more insight on “feature detection”? – Raphael Aug 09 '23 at 14:15
  • It's a long-term practice, and pain in the ass for web developers. It involves doing things like `if (typeof navigator.canShare !== "function") alert("your browser doesn't support the share API");`. As you can see in this mdn article this is a common pattern for dealing with browser differences. https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share. Sometimes you might provide a polyfill of the missing functionality or perform some other fall back behav instead of failing. It all depends on the application you're writing – Aluan Haddad Aug 09 '23 at 14:22

0 Answers0