-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webpush support in service workers #84
Comments
@swina do you refer to something like this? If so, you need to use You can see a reference on workbox here. // service-worker.js
function getEndpoint() {
return self.registration.pushManager.getSubscription()
.then(function(subscription) {
if (subscription) {
return subscription.endpoint;
}
throw new Error('User not subscribed');
});
}
// Register event listener for the ‘push’ event.
self.addEventListener('push', function(event) {
// Keep the service worker alive until the notification is created.
event.waitUntil(
getEndpoint()
.then(function(endpoint) {
// Retrieve the textual payload from the server using a GET request. We are using the endpoint as an unique ID of the user for simplicity.
return fetch('./getPayload?endpoint=' + endpoint);
})
.then(function(response) {
return response.text();
})
.then(function(payload) {
// Show a notification with title ‘ServiceWorker Cookbook’ and use the payload as the body.
self.registration.showNotification('ServiceWorker Cookbook', {
body: payload,
});
})
);
}); |
Hi thank you for your response. My current configuration of PWA from vite.config.js is:
So if I have to add push support I will save the file you posted like service-worker.js and then add to vite.config :
Thank you again |
@swina my code is just a snipet, you need to modify/add your logic. The code is only for push notifications, not for the pwa servive worker, see also the inject manifest. You also need to add logic to your app to add subscriptor to the server... |
Is I'm right that you need to fork |
Having developed before some vue app with webpush notification support thru a custom service worker is there a way to support webpush notifications ?
Your help will be really appreciated.
Thanks
The text was updated successfully, but these errors were encountered: