Can I use pure grpc (not grpc-web) in frontend javascript

757 Views Asked by At

According to https://grpc.io/blog/state-of-grpc-web/

It is currently impossible to implement the HTTP/2 gRPC spec3 in the browser, as there is simply no browser API with enough fine-grained control over the requests. For example: there is no way to force the use of HTTP/2, and even if there was, raw HTTP/2 frames are inaccessible in browsers.

However caniuse says most of the browsers have http/2 implementation.

Is it still impossible to use pure grpc in frontend javascript? If it is, why?

1

There are 1 best solutions below

1
On

As that caniuse page shows, browsers are able to communicate with HTTP/2 servers. But the gRPC protocol does not just use the HTTP/2 protocol, it uses HTTP/2 in a specific way. The problem is that browsers do not provide the JavaScript APIs that are necessary to control the use of HTTP/2 in the ways that are required by the gRPC specification. In particular, trailers are an important part of the gRPC protocol, and they are not generally accessible in browser HTTP/2 APIs.