Hello Forum,
We are working on the Samsung SmartTv application development with tizen.
While developing we had a features such as deeplink and firebase analytics one needs hosted application and another needs the native code to have the tizen window object to be present.
To work with both of them we implemented the postMessage functionality with iframe to communicate between the iframe(hosted app) and native app so that we can send message from hosted app to native app to launch the deeplink and firebase would eventually work through hosted app.
After this implementation we have encountered an issue with tizen version 5.5 and 6.0 that this functionality is not working on this versions. We didn’t found any clear document saying postMessage doesn’t support on 5.5 and 6.0
Could you please help us to get this issue solved as this is blocking the application on 5.5 and 6.0
Here is the example code snippet we are using this -
index.html
<!DOCTYPE html>
<html>
<head>
<title>Example TV</title>
<link rel="stylesheet" href="index.css">
<script src="index.js"></script>
</head>
<body>
<div class="frame">
<iframe id="some-id" allow="encrypted-media *;" src="example-url.com" frameborder="0">.
</iframe>
</div>
</body>
</html>
index.js
const launchApp = (appId) => {
var service = new tizen.ApplicationControl(
"http://tizen.org/appcontrol/operation/tizenstoreview",
"tizenstore://MainPage",
null,
null,
null
);
try {
tizen?.application?.launchAppControl(
service,
appId,
function () {
console.log("app Service launched");
},
function (err) {
},
null
);
} catch (exc) {
const iframeElement = document.getElementById("example-id");
iframeElement.contentWindow.postMessage(
{ appLaunchError: exc },
serverOrigin
);
console.log("launchService exc: " + exc);
}
};
window.addEventListener("message", function (event) {
// Validate origin to ensure it's coming from the hosted app
if (event.origin !== serverOrigin) {
console.log("Invalid origin:", event.origin);
return;
}
if (
event.data &&
event.data.action === "triggerAppLaunch" &&
event.data.appId
) {
console.log('launched application with appId', event.data.appId)
launchApp(event.data.appId);
}
});
Thanks