Search code examples
javascripthtmlroku

How to identify Roku Tv Device in code level (HTML/JavaScript) ..?


I have developed a Roku Tv application.That app is for Roku. I need to identify what is the currently accessing device.

How can I do this using HTML/JavaScript..?

Thanks


Solution

  • You can identify them using the user agent string.

    roku devices has a user-agent string something like this

    Mozilla/5.0 (compatible; U; NETFLIX) AppleWebKit/533.3 (KHTML, like Gecko) Qt/4.7.0 Safari/533.3 Netflix/3.2 (DEVTYPE=RKU-42XXX-; CERTVER=0) QtWebKit/2.2, Roku 3/7.0 (Roku, 4200X, Wireless)
    

    you can access the user agent string with this in js

    is_a_roku =  function (){
       let user_agent = navigator.userAgent;
       return user_agent.indexOf("Roku") != -1
    }