I have a web app hosted and accessed via a domain. I have a requirement to check Samsung TV model year and based on year redirect to different version of app.
Below code i am using in index.html for redirection. I am getting an error
Error logs:
main.b9955455.chunk.js:1 [Device] Tizen
VM14 webapis.js:1 [webapi.js] WebAPIException:TypeError: this.elPlugin.postMessageAndAwaitResponse is not a function
index.html:1 Uncaught (in promise) WebAPIException {code: 9, name: ‘NotSupportedError’, message: ‘Please check dynamic library of this pepepr plugin.’}
Same redirection code works fine for Samsung 2024 model, below 2024 model redirection code does not work. I have tried multiple ways for redirection i.e, window.location.href, window.location.replace , window.location.assign but none of those worked.
For Samsung 2023 OS is Tizen 7.0 and Chromium 94.0.4606.31
Code for redirection:
if (manufacturer === ‘Samsung’ && year === 2023) {
const redirectUrl = https://xyz.com/${softwareVersion}/index.html?t=${Date.now()}
;
loadAndReplaceContent(redirectUrl);
}
function addBaseUrls(text, sourceUrl) {
const regex = /(href=|src=)[‘"]{1}([^’“]*)['”]/gm;
function replacer(match, p1, p2) {
const url = new URL(p2, sourceUrl);
return p1 + url.href;
}
return text.replace(regex, replacer);
}
function loadAndReplaceContent(url) {
const xhr = new window.XMLHttpRequest(),
failMessage = ‘Something went wrong, please 'Exit' and start the app again’,
xhrDoneStatus = xhr.DONE || 4;
xhr.open(‘GET’, url);
xhr.onreadystatechange = function handleReadyStateChange() {
if (xhr.readyState !== xhrDoneStatus) {
return;
}
if (xhr.status === 200) {
document.open();
document.write(addBaseUrls(xhr.response, url));
document.close();
} else {
document.getElementById('status-message').innerHTML = failMessage;
}
};
xhr.send();
}
Could you please help how to redirect to different version of the app runtime?