I've got a PWA and I'm trying to run OneSignal (for web push notification subscriptions) and an offline service worker alongside each other. They both work on their own. I've tried a few iterations with varying levels of one working or the other. I've got a vague sense that the answer is that I need to merge the 2 service workers but I'm not 100% sure how to do this. Any insight or guidance on this would be appreciated.
This is the OneSignalSDKWorker.js script (as supplied by OneSignal)
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');
This is my offline service worker script (as supplied by PWA builder)
importScripts("https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.sw.js");
const CACHE = "pwabuilder-offline";
self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});
workbox.routing.registerRoute(
new RegExp('/*'),
new workbox.strategies.StaleWhileRevalidate({
cacheName: CACHE
})
);
I got the functionality from both service workers working by adding / merging the PWA Builder offline service worker script into OneSignalSDKWorker.js like so:
Then I initialised the service worker in the head of my html with the following: