Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fetch instead of goog.net.XhrIo/XMLHttpRequest #1134

Open
avm99963 opened this issue Sep 6, 2021 · 6 comments
Open

Use fetch instead of goog.net.XhrIo/XMLHttpRequest #1134

avm99963 opened this issue Sep 6, 2021 · 6 comments

Comments

@avm99963
Copy link

avm99963 commented Sep 6, 2021

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.

@avm99963
Copy link
Author

avm99963 commented Sep 6, 2021

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.

@sampajano
Copy link
Collaborator

sampajano commented Sep 10, 2021

Glad you found a solution! 😃

More native Service Worker support would definitely be a plus for gRPC-web too :)

@sampajano
Copy link
Collaborator

sampajano commented Jan 27, 2022

FYI -- an update about the reason we cannot yet switch to fetch is provided in this related thread :)

@sampajano
Copy link
Collaborator

FYI, a solution regarding enabling Fetch was discussed below:
#587 (comment)

@avm99963
Copy link
Author

Thanks @sampajano! Should we consider closing this issue in favor of the other one?

@sampajano
Copy link
Collaborator

@avm99963 Thanks for suggesting!

The other issue is specifically addressing the service worker use case — while probably tightly related, is maybe a different context. So I think it's ok to keep them as separate for now.

But whatever solution we come up with should address both.. :)

Hope that makes sense :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants