I’m trying to include notifications in this Laravel project, so I’ve implemented service workers. The issue is that everything works fine on localhost, but on the host, the service workers don’t function properly. Of course, my protocol is HTTPS.
localhost
host
i include this in my page:
<script> navigator.serviceWorker.register("{{ URL::asset('service-worker.js') }}"); </script>
I am trying to do this:
<script> navigator.serviceWorker.register("{{ URL::asset('public/service-worker.js') }}"); </script>
But it still doesn’t work. And here is the content of this file:
self.addEventListener("push", (event) => {
const notification = event.data.json();
event.waitUntil(
self.registration.showNotification(notification.title, {
body: notification.body,
icon: "",
data: {
url: notification.url
}
})
)
});
self.addEventListener("notificationclick", (event) => {
event.waitUntil(
clients.openWindow(event.notification.data.url)
)
})
New contributor
IBRA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.