I am currently working on implementing push notifications for my domain across desktop and mobile devices. I have successfully set up push notifications on desktop, but I am facing issues with Chrome for Android.
Despite having tested the code on powerful devices such as the OnePlus 3 and Huawei Mate 9, I am unable to register the service worker on Chrome for Android. Strangely, I do receive web notifications on these devices, so it is a perplexing issue.
Here is the code snippet that I am using:
<script type="text/javascript">
if('serviceWorker' in navigator && 'PushManager' in window) {
alert('best');
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js').then(function(registration) {
alert('test');
});
});
}
</script>
The first alert indicates that the browser supports service workers and push notifications. However, the second alert does not pop up on mobile Chrome, even though it works perfectly fine on desktop Chrome. I am confused about what could be causing this discrepancy.
This code is implemented on a page named test.php
Any insights or suggestions would be greatly appreciated!