Ok, so I'm trying to make an Angular 7 PWA that uses background sync.
I can trigger the sync event from within the dev tools in Chromium but it won't trigger when I remove my ethernet cable and plug it back in.
I originally thought it was my service worker file being odd so I added this: https://stackoverflow.com/a/50414028/9978023 , what's weird is that it works in Firefox but not Chromium. So using this I can trigger the same function that the sync event is meant to call. But it's not a great solution.
self.addEventListener('sync', function (event) {
console.log('I heard a sync event. Sending Posts to server', event);
event.waitUntil(sendPostsToServer()
.then(res => {
console.log(res);
})
.catch(e=>{console.log(e)}));
});
async function sendPostsToServer() {
// POST to server
}
service-worker.js
What am I doing wrong? Why isn't the sync event triggering when I reconnected to the Internet?