Users can submit a form when offline that gets synced to my database with background sync. This is working as expected. The issue I am having is that when the user is offline and submits the form it redirects to a "site not found" error page in Chrome. The user should be redirected back to the list of all their entries. I have confirmed the page it is redirecting to is cached.
Server Worker file:
importScripts(
"https://storage.googleapis.com/workbox-cdn/releases/6.1.2/workbox-sw.js"
);
const CACHE = "example-offline";
const QUEUE_NAME = "bgSyncQueue";
self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});
workbox.routing.registerRoute(
new RegExp("/*"),
new workbox.strategies.NetworkFirst({
cacheName: CACHE,
})
);
const bgSyncPlugin = new workbox.backgroundSync.BackgroundSyncPlugin(
QUEUE_NAME,
{
maxRetentionTime: 24 * 60, // Retry for max of 24 Hours (specified in minutes)
}
);
workbox.routing.registerRoute(
new RegExp("^https://example.com/[a-zA-Z]+/journal"),
new workbox.strategies.NetworkOnly({
plugins: [bgSyncPlugin],
}),
"POST"
);