Background Sync replay request
See original GitHub issueHi,
I am trying to make a background-sync request with WorkBox, in a very simple example application with Vue. I revised my codes for a long time but I did not find the solution.
The service worker is well registered and when I make the ajax request, background-sync works properly.
This is my code in the sw.js:
const queue = new workbox.backgroundSync.Queue('asierrrna');
workbox.routing.registerRoute(
RegExp('^MY_URL'),
workbox.strategies.networkOnly({
plugins: [{
fetchDidFail: async ({request}) => {
await queue.addRequest(request);
},
}],
}),
'GET'
);
Background-sync is registered in indexedDB tab:
.Finally the network tab. There we see that the API call is well, because when the network returns it makes the call, but nothing else happens in the app, and the old data is not replaced by the new one 😕
Thanks 😃
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Manually replaying requests queued by workbox-background ...
Queue class (instead of workbox.backgroundSync.Plugin ) directly. The Plugin class takes care of setting up a fetchDidFail callback for you, so ...
Read more >workbox-background-sync - Chrome Developers
The easiest way to use Background Sync is to use the Plugin that will automatically Queue up failed requests and retry them when...
Read more >workbox-background-sync - npm package - Snyk
Queues failed requests and uses the Background Sync API to replay them when the network is available. Visit Snyk Advisor to see a...
Read more >workbox-background-sync examples - CodeSandbox
Learn how to use workbox-background-sync by viewing and forking ... AboutQueues failed requests and uses the Background Sync API to replay them when...
Read more >workbox-background-sync - UNPKG
18, * A class to manage storing failed requests in IndexedDB and retrying them ; 19, * later. All parts of the storing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @philipwalton,
The sync event works properly. As you can see in the picture above, when ajax petition fail and internet connection is restored, the sync event is well triggered and in the network tab I can see the API response.
My problem is related with how I can replace the old query with the new one in my app. I was looking to do with callbacks in the Queue like that (it doesn’t work for me with the new onSync callback):
Then in my SPA app I listen for a “message”, and I use my app logic to restore the failed request.
Is this the right way?
Thanks
@asiermusa I was not sure about how Background Sync work on workbox. After doing some research and experiments I was able to catch how things were working. Sorry for that comment