I'm trying to enable push notification on my react app (PWA).
This is my service worker file. I've successfully done so whenever a request is made to a specific endpoint by doing so
self.addEventListener('activate', function(event) {
console.log('Claiming control');
return self.clients.claim();
});
self.addEventListener('fetch', async event => {
const url = new URL(event.request.url);
//
if (url.pathname === 'my-endpoint') {
//I want the notification to display the response data
event.waitUntil(
self.registration.showNotification('custom title', {
body: 'custom body'
})
);
}
});
The problem is the title and body are currently static. How do I extract the response body and used that to dynamically create custom notification messages instead?