grpc-web
grpc-web copied to clipboard
Use fetch instead of goog.net.XhrIo/XMLHttpRequest
I'm trying to use the gRPC-Web JS library inside a service worker, where XMLHttpRequest isn't exposed, so gRPC requests don't succeed (instead I get the error ReferenceError: XMLHttpRequest is not defined
).
The reason why I want to use gRPC-Web inside a service worker is that I'm developing a Chrome extension, and need to call a gRPC method every 30 minutes, which can only happen inside a service worker.
It would thus be great if the library used fetch instead of goog.net.XhrIo/XMLHttpRequest.
Just found out that using something like https://github.com/apple502j/xhr-shim lets me work around this problem easily!
Update: xhr-shim doesn't work well (requests are sent but responses are not being received), but it seems like https://github.com/markis/sw-xhr does work.
Glad you found a solution! 😃
More native Service Worker support would definitely be a plus for gRPC-web too :)
FYI -- an update about the reason we cannot yet switch to fetch is provided in this related thread :)