grpc-web
grpc-web copied to clipboard
Navigator.sendBeacon() or fetch keepalive support of unary RPC?
Hi!
I'm now trying to create a system collecting logs recorded on a page, and now wondering if there's a way to make a rpc call just before a user leaves from the page (like the last visibilitychange event or unload event). The connection could suddenly be disconnected before sending a request because the method is called just before closing the tab and all in-flight network requests seem to be discarded when closing a tab. Is it possible to send a request in that case?
IIUC, grpc-web seems to use xhrio.send() here so it's not possible. I guess my use case can be covered by adding an option to use navigator.sendBeacon()
or fetch()
with a keepalive option, but not sure if the closure-library supports them.
thanks for the suggestion! this would be a nice improvement to have when we add fetch() support later. :) (Although fetch() support is not planned yet..) (and sendBeason() would be an interesting alternative too but it's probably an even bigger change than fetch() :))