How to exist a hosted app?

Hello

We are developing a hosted web application for tizen TV. We developed a YES / NO popup, but the following API is not available, specifically the tizen object is not available.

tizen.application.getCurrentApplication().exit();

Is there a suggested way to get the tizen object and / or exist the app?

Thanks,
Istikana

Since no one responded, I would suggest you look for an answer in the FAQ-Q/A under the most appropriate topic on the Smart TV Seller Office site If you don’t find a solution there then sign in and open a Smart TV Seller Support Request . They can help you better there.

Ron
Samsung Developer Relations

Hi istikana, did you find solution for that issue? I know that big companies like Disney+ also has web hosted app and they are usign tizen api, but I dont know how they achieve it…

I can tell you how. You host your app in an iframe, and make sure you set the iframe like this:

<style>
    body {
      position: absolute;
      width: 100vw;
      height: 100vh;
      margin: 0;
      padding: 0;
      display: block;
    }
    #contentHTML {
      position: absolute;
      top: 0;
      left: 0;
      width: 100vw;
      height: 100vh;
      margin: 0;
      padding: 0;
      border: none;
      display: none;
    }
  </style>
<iframe id="contentHTML" frameborder="0" scrolling="no" style="display: block;"></iframe>

now you add an iframe postMessage receiver somewhere in the body tag like this:

<script>
var origin = "https://hosted-app.example
  const iframeElem = document.getElementById('contentHTML');
  iframeElem.src = origin
  iframeElem.onload = function () {
    iframeElem.focus();
  };
window.addEventListener('message', (event) => {
    if (event.origin === origin && event.data === 'exitApp') {
      tizen.application.getCurrentApplication().exit()
    }
  });

and within your hosted app you call the parent like this:

const referrerWindow = window.opener || window.parent
    if (referrerWindow) {
      // Send an exit signal to the referrer
      referrerWindow.postMessage("exitApp", "*")
    } else {
      console.error("Unable to communicate with the referrer.")
    }

Good luck.

As soon as you leave index.html, the Tizen APIs are gone.

Any info you need in the site you redirect to, you’ll have to pass on for example using URL query parameters.

That or use an IFRAME (or web view) as suggested, though I’m not sure how well that works nowadays.

Hosted apps are allowed on tizen, but publishing an app that isn’t able to quit programatically isn’t. This is a catch 22 because the exit function is disabled on hosted apps for “security reasons”, therefore the only way to implement a fully functional hosted app in the long run is to expose the app wrapper to additional security risks via iframes and such.

As for performance, I am not entirely sure if the app is significantly slowed down by using this tag, but it is for sure not optimized.

The most important aspect which usually breaks the functionality in iframes is focus. I copied the way samsung/wits uses iframes for debugging and it works here as well as shown above.

All in all, you should be able to get your app approved in this manner, but it’s a shame it has to be done this way.