Anonymous - 2025-02-14

Originally posted by: Anubarak

Anyone found a solution for this?

A working - but not good way - is to manually trigger replayRequests. But since i access the private _queue property it does not feeld good

const bgSyncPlugin = new BackgroundSyncPlugin('myQueueName', {
    maxRetentionTime: 24 * 60, // Retry for max of 24 hours (in minutes)
});

registerRoute(
    ({ request }) => request.method === 'POST' && request.url.includes('/api/'),
    new NetworkOnly({
        plugins: [bgSyncPlugin],
    }),
    'POST'
);

async function processQueue() {
    console.log('📡 Checking for pending requests...');
    try {
        await bgSyncPlugin._queue.replayRequests();
        console.log('✅ Successfully replayed queued requests');
    } catch (error) {
        console.error('❌ Error replaying queued requests:', error);
    }
}

// 🔹 Fallback: Run Every 30 Seconds
setInterval(() => {
    processQueue();
}, 30000);

Otherwise my requests are indeed queued but will never run