grpc / grpc/grpc-web

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

Open
#1,192 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
9.3k
Forks
802
Avg merge
1d 7h
Merged PRs (30d)
5

Description

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()](https://google.github.io/closure-library/api/goog.net.XhrIo.html) [here](https://github.com/grpc/grpc-web/blob/3956560ad01b4af0a2a5c29c081f5bbd1424e85d/javascript/net/grpc/web/grpcwebclientbase.js#L216) 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.