This page demonstrates AffordaCalc's background sync capabilities using the Workbox API format for PWA validation. It shows how the application preserves and synchronizes user actions when offline.
Workbox Background Sync Status
Initializing background sync...
Queue Status Empty
No queue created yet.
Event Log
Background Sync Test Code
// The code below demonstrates how the application will sync data when offline
try {
// Create a background sync queue
const bgSyncQueue = workbox.backgroundSync.createQueue('workbox-demo-queue');
// Queue a request for synchronization
const request = new Request('/api/mock-endpoint', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: Date.now(),
data: 'Sample data to be synced when online',
timestamp: new Date().toISOString()
})
});
// Add the request to the sync queue
bgSyncQueue.addRequest(request)
.then(id => console.log(`Request queued with ID: ${id}`))
.catch(err => console.error('Failed to queue request:', err));
// The request will be replayed when the browser goes online
// or when the sync event is triggered by the browser
} catch (error) {
console.error('Background sync error:', error);
}