6

I know the Firebase Realtime Database web SDK can use either WebSockets or long-polling to talk to the backend servers. Is there a way to force it to only use WebSockets?

1 Answer 1

12

In general, you don't want to do this since the Firebase SDK automatically detects whether the client supports WebSockets and will use them if possible. Since WebSockets don't work reliably in all browsers and in all environments (e.g. proxies occasionally don't reliably support WebSocket traffic), forcing WebSocket usage may cause your app to not work reliably in some situations.

As a diagnostic tool or to work around very specific issues, you can force the client to use WebSockets by changing your databaseURL to wss://<app>.firebaseio.com/ instead of https://<app>.firebaseio.com/ but if you find yourself needing to do this, it's probably worth reaching out to support to see if there's a better solution.

4
  • You might want to add a blurb that "the Firebase SDK automatically detects whether the client supports web sockets and will use that if possible. It will only fall back to long-polling when it can't use web sockets." Commented Jul 6, 2017 at 3:44
  • Good suggestion. Done! Commented Jul 6, 2017 at 15:45
  • I'd like to do the oposite. I would like to force Firebase, not using WS. I'm interested on this since Google Crawler does not use WS requests, and fails retrieving content and this causes indexation holocaust. I'm spending so much energy solving SEO issues of google products. I'd preffer my Firebase project to rely only in HTTP Commented Jun 17, 2018 at 12:34
  • 1
    For what it's worth, Firebase seems to be really bad at detecting whether web sockets are available in Electron when using the non-Node version of the module. WebSockets work, then fail at some point and Firebase tries to use long-polling over and over, but never succeeds. Forcing WebSockets gets me reconnected and keeps me reconnected so far.
    – Slbox
    Commented Nov 10, 2018 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.