Having trouble implementing this on my website; it keeps showing the following error. Help, please!
Service Worker Error DOMException: Only secure origins are allowed.
if ('serviceWorker' in navigator && 'PushManager' in window) {
console.log('Service Worker and Push is supported');
navigator.serviceWorker.register("{{ 'sw.js' | asset_url }}")
.then(function(swReg) {
registration.pushManager.subscribe({ userVisibleOnly: true })
.then(function(subscription) {
console.log('endpoint:', subscription.endpoint);
});
console.log('Service Worker is registered', swReg);
swRegistration = swReg;
initialiseUI();
})
.catch(function(error) {
console.error('Service Worker Error', error);
});
} else {
console.warn('Push messaging is not supported');
pushButton.textContent = 'Push Not Supported';
}