如何检查workbox-background-sync中是否有待处理的请求?

时间:2020-10-15 10:41:55

标签: workbox workbox-webpack-plugin background-sync

如果workbox-background-sync表中有待处理的请求,我想在Vue中显示通知。 This is my IndexedDB where I store all pending requests.

这是我的service-worker.js文件


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 个答案:

没有答案