Workbox background sync [Empty Body]

51 Views Asked by At

I'm using Workbox Background Sync in an internal React Progressive Web App (PWA) that is utilized by an average of 700 users per day. I employ background sync to handle file uploads on the app. For most requests, the process works well. When a user is offline while uploading their photo/document, the request is successfully stored in the indexedDB table and later replayed when the user regains network connectivity.

However, I am encountering an issue with a non-negligible portion of the requests. The request itself is stored correctly in the indexedDB table, but when I call my API to log the request, I observe that the request body is empty (screenshot provided below).

enter image description here

Do you have any ideas why the request body is null? We haven't encountered any issues with the original request, and the app has been thoroughly tested for almost a year now. It's important to note that we upload the file in Base64 format and do not use formData for file uploads :

Finally, here is the section of code responsible for cloning the requests:

const routesToRegister = [
{
    pattern: /.*\/file/,
    method: ['POST', 'DELETE'],
},
{
    pattern: /.*\/post_it/,
    method: ['POST', 'DELETE'],
},
{
    pattern: /.*\/report/,
    method: ['POST'],
},
{
    pattern: /.*\/arrival/,
    method: ['PATCH'],
},
{
    pattern: /.*\/product/,
    method: ['PATCH'],
},
];
routesToRegister.forEach((route) => {
  route.method.forEach((method) => {
    registerRoute(
        route.pattern,
        new NetworkOnly({
            plugins: [bgSyncPlugin],
        }),
        method,
    );
  });
});
0

There are 0 best solutions below