grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.56k stars 762 forks source link

Navigator.sendBeacon() or fetch keepalive support of unary RPC? #1192

Open makotoshimazu opened 2 years ago

makotoshimazu commented 2 years ago

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.

sampajano commented 2 years ago

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() :))