-
Notifications
You must be signed in to change notification settings - Fork 830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Background sync should add the ability to modify request prior to retrying #646
Comments
Yeah this sounds like a feature which could really help devs differentiate even normal req from the later replayed request, so 👍 for the feature. As for the code location part, we can take a similar function in the constructor and call it here Although I am a little unsure if a |
I'm in favor of moving all internal uses of If they don't provide a I can put together a PR for that, and once it's in place, @philipwalton will be able to handle what he needs by putting together a |
Reopening because it looks like this still isn't good enough. The After spending a bit of time thinking about it, I think doing option 1 above is still necessary, though since the method required will have to return something, I wonder if it makes sense to rethink how these are named (since it's more of a handler and less of a callback). |
hey @philipwalton @jeffposnick , else we can work towards an approach for option 1 of yours. Also a note, keeping two callbacks, option 1 and request wrapper's callbacks might get a little confusing, any thoughts? |
I'm not sure that's the cleanest approach either. Seems awfully specific to a particular use case and not reusable for anything else. @jeffposnick wdyt? |
Makes sense, unless there is a cleaner approach i guess we can go with option 1. You wanna PR? |
Sure, I can try to throw something together and then we can bikeshed on method names later.
SGTM |
I started looking into how to update the
workbox-google-analytics
library to usebackground-sync
, and I discovered that there's no way to modify the request before it retries.For the google analytics hit to work it needs to update the
qt
param to the difference between the current time and the original hit time. It also (for consistency with the existing API), needs to let developers set param overrides as well as modify the existing params via a hitFilter function.I see two options to make this work, and I wanted to get feedback before making any changes to the background sync code:
Add a new callback to the
workbox.backgroundSync.Queue
so it can modify the request after it pulls it from the IDB cache and before it sends it.Update the
workbox.backgroundSync.RequestQueue
class to support queuing both plainRequest
objects as well asRequest
objects with a correspondingRequestWrapper
object, then we could use aRequestWrapper
plugin'srequestWillFetch
lifecycle method to modify the request prior to sending it.I think both options are fine, but I slightly prefer option #2, if for no other reason than it seems wrong to duplicate behavior we already have in
RequestWrapper
. That being said, option #1 is probably much easier to implement.What do others think? @jeffposnick @prateekbh
The text was updated successfully, but these errors were encountered: