firedart
firedart copied to clipboard
[Web] gRPC Error (code: 14, codeName: UNAVAILABLE, message: Error connecting: Unsupported operation: SecurityContext constructor)
Firestore seems be be throwing errors when deployed to Web.
Calling something like:
Firestore.instance.collection("users").get() is triggering:
Restarted application in 201ms.
Error: gRPC Error (code: 14, codeName: UNAVAILABLE, message: Error connecting: Unsupported operation: SecurityContext constructor, details: null)
at Object.createErrorWithStack (http://localhost:64615/dart_sdk.js:4362:12)
at Object._rethrow (http://localhost:64615/dart_sdk.js:38245:16)
at async._AsyncCallbackEntry.new.callback (http://localhost:64615/dart_sdk.js:38239:13)
at Object._microtaskLoop (http://localhost:64615/dart_sdk.js:38071:13)
at _startMicrotaskLoop (http://localhost:64615/dart_sdk.js:38077:13)
at http://localhost:64615/dart_sdk.js:33574:9
The same code is working great on Desktop, and FirebaseAuth works on both Web/Desktop.
Any thoughts on this? I can authenticate fine, but reading from firestore throws an error:

Is that still web? I have to say, I never tried running Firedart on a web browser so I'm not confident that it's actually working properly.
All tests are still passing on my end so it doesn't seem like anything broke in the meanwhile.
Cheers, ya it's Web. I looked into it a bit more, and I guess gRPC just does not work on web, so I guess this is expected. Somehow the official firestore sdk does have a socket-like connection in browser.
I believe the "fix" would be to use this RPC channel instead of a real one, when on web: https://github.com/wav/grpc-web-dart
Little more info here: https://github.com/flutter/flutter/issues/48054
If that's a drop-in fix then it should be easy to do. Would you like to try and implement it? I'd be happy to take that pull request!
gRPC just does not work on web,
It does gRPC

If I understand correctly browsers does not support regular sockets, they support web-sockets that is different protocol.
And for implementation I think we need to use different commands GrpcWebClientChannel from import 'package:grpc/grpc_web.dart';
Recently they added a new constructor that will handle the differences mostly: https://github.com/grpc/grpc-dart/blob/master/lib/grpc_or_grpcweb.dart. Of course this depends on the server end handling the different types of connections properly.
Any news about this feature :) ?
Another option that may help you is to switch to Appwrite instead of firebase. Didn't try it but it looks good and I think support dart on the web.
Closed by #130