How to check if there are pending requests in workbox-background-sync?

723 views Asked by At

I want to show a notification in Vue, if there are pending requests in workbox-background-sync table. This is my IndexedDB where I store all pending requests.

And this is my service-worker.js file


const showNotification = () => {
    self.registration.showNotification('Sync success!', {
        body: 'Queue Resolved ''',
    });
};

const bgSyncPlugin = new workbox.backgroundSync.Plugin('offlineData', {
    maxRetentionTime: 24 * 60, // Retry for max of 24 Hours (specified in minutes)
    callbacks: {
        queueDidReplay: showNotification,
    },
});

const networkWithBackgroundSync = new workbox.strategies.NetworkOnly({
    plugins: [bgSyncPlugin],
});

workbox.routing.registerRoute(/\/*/, networkWithBackgroundSync, 'POST');
0

There are 0 answers