Why do browsers not support gRPC?
Asked Answered
C

3

10

gRPC is based on HTTP/2, which (assumption) is widely supported by browsers. Therefore, I feel there should be no problem with gRPC from a browser.

However, it is clear that there is a problem. The protocol, grpc web, is different, as exists "due to browser limitation". There are also numerous blog post describing complicated tech stacks deployed to get gRPC to work from a browser.

I'm missing the actual problem - why does gRPC not simply work from browsers?

Cleave answered 6/9, 2018 at 21:35 Comment(0)
C
3

I now understand that browsers only supports HTTP/2 in the sense that they use it to fetch resources from the server on behalf of your application (javascript) code.

Javascipt application code can still only use HTTP/1 (which may be handled under the hood by the browser in an HTTP/2 connection). Therefore it is not possible for application code to use grpc.

If anyone should find where this is explained in the docs, it would be good to add a link to it here.

Cleave answered 28/9, 2018 at 9:46 Comment(0)
A
0

Most browsers use HTTP1.1 whereas GRPC only works with HTTP2. You can use nginx, envoy or traefic to run it behind a reverse proxy, very similar to how web sockets are often used behind a reverse proxy(in that case the http1 is upgraded to a websockets connection). The reverse proxy will send the grpc request sent over http1 to an http2 backend and vice versa. You can use Envoy(suggested/currently used by grpc-web), traefik(am using this personally) and nginx.

Armagh answered 26/9, 2018 at 17:30 Comment(0)
U
0

This question has been on my mind, and after some digging, I found the following comment from https://grpc.io/blog/state-of-grpc-web/#the-grpc-web-spec :

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.

Someone can correct me if I am wrong, but I believe another reason why grpc is not supported despite "widespread support" of HTTP/2 on browsers is that server push is not being implemented on browsers, for various reasons as discussed in this thread: How to implement HTTP/2 stream connection in browser?

Uphold answered 29/7, 2023 at 5:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.