When switching networks (i.e. from WiFi to mobile network) or switching network for mobile and restart watch, the widget is not able to send requests to the server anymore due to the XMLHttpRequest class not working as it is supposed to. Besides, if I turn WiFi on, or re-add the widget everything work fine.
Testing on Tizen 5.5.0.1, Tizen 5.5.0.2, Tizen 4.0.0.7, Tizen 2.3.2.7
Here it is simple web widget code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script>
window.onload = function() {
document.addEventListener('visibilitychange', visibilitychange);
isInternet();
function isInternet() {
var xhr = new XMLHttpRequest();
var file = 'https://jsonplaceholder.typicode.com/todos/1';
var randNum = Math.round(Math.random() * 10000);
xhr.open('GET', file + "?rand=" + randNum, false);
try {
xhr.send();
if (xhr.status >= 200 && xhr.status < 304) {
document.getElementById('message').textContent = 'internet';
}
} catch (e) {
document.getElementById('message').textContent = 'no internet';
}
}
function visibilitychange() {
if (document.visibilityState === 'visible') {
isInternet();
}
}
};
</script>
</head>
<body>
<div style="text-align: center;">
<div id="message"></div>
</div>
</body>
</html>
How to reproduce the error:
- Install the application with this code. Make sure both WiFi is enabled and your watch is tethered to your phone.
- Add the widget to your homescreen. It will show your ‘internet’ when widget can do requests.
- Turn off WiFi on your watch. Reboot watch.
- The widget will stop working, and show ‘no internet’ even though the watch is connected to the internet. Other apps can still connect to the internet. Once the widget is in this state, it seems not to be able to recover. Removing and re-adding the widget will have it working again.
Whats wrong? Is it Tizen bug?