I'm developing a simple corporate AngularJS app and was planning on using Firebase for the backend.
The browsers I have to support are IE8 and Chrome (latest).
I have managed to fix all of the IE related quirks in the front end and can successfully retrieve data from my Firebase. As IE8 does not have support for WebSockets I assume it is using long polling. (this is fine performance-wise, the app is very simple and just pulls/updates two or three pieces of data).
Paradoxically, I am seeing the following error in Chrome repeatedly and it is failing to connect to Firebase. I am assuming this is due to the firewall/proxy of the corporate network.
WebSocket connection to 'wss://xxx.firebaseio/.es?v=5' failed: WebSocket is closed before the connection is established.
I have no control over the firewall/proxy, so my question is if I can force Chrome to use long polling too, using some sort of config flag when I create my Firebase reference?
I am using a mix of Angularfire and straight Firebase. The app works perfectly in IE so there does not appear to be anything wrong with my code. (Also simple test scripts encounter the same issue)
Update: The app does not work in Chrome (hence my question), so perhaps this is a bug I should raise with Firebase, but regardless a way to force long polling would (presumably) fix my issue.
I'm developing a simple corporate AngularJS app and was planning on using Firebase for the backend.
The browsers I have to support are IE8 and Chrome (latest).
I have managed to fix all of the IE related quirks in the front end and can successfully retrieve data from my Firebase. As IE8 does not have support for WebSockets I assume it is using long polling. (this is fine performance-wise, the app is very simple and just pulls/updates two or three pieces of data).
Paradoxically, I am seeing the following error in Chrome repeatedly and it is failing to connect to Firebase. I am assuming this is due to the firewall/proxy of the corporate network.
WebSocket connection to 'wss://xxx.firebaseio./.es?v=5' failed: WebSocket is closed before the connection is established.
I have no control over the firewall/proxy, so my question is if I can force Chrome to use long polling too, using some sort of config flag when I create my Firebase reference?
I am using a mix of Angularfire and straight Firebase. The app works perfectly in IE so there does not appear to be anything wrong with my code. (Also simple test scripts encounter the same issue)
Update: The app does not work in Chrome (hence my question), so perhaps this is a bug I should raise with Firebase, but regardless a way to force long polling would (presumably) fix my issue.
Share Improve this question edited Dec 27, 2013 at 19:35 Dean asked Dec 27, 2013 at 17:57 DeanDean 3683 silver badges9 bronze badges 2- Firebase should automatically fall back to long polling if WebSockets doesn't work, and as such the console error should be harmless. Does the app still work? – Anant Commented Dec 27, 2013 at 19:28
- Anant: It is not falling back on long polling in Chrome. (so I am not in this situation stackoverflow./questions/12421993/…) – Dean Commented Dec 27, 2013 at 19:37
2 Answers
Reset to default 6you can use Firebase.INTERNAL.forceLongPolling();
to force long polling Firebase.INTERNAL.forceWebSockets();
to force web socket
I'm sure there is a better way but I just went in to firebase-debug.js and changed the following function:
fb.realtime.WebSocketConnection["isAvailable"] = function() {
var isOldAndroid = false;
if(typeof navigator !== "undefined" && navigator.userAgent) {
var oldAndroidRegex = /Android ([0-9]{0,}\.[0-9]{0,})/;
var oldAndroidMatch = navigator.userAgent.match(oldAndroidRegex);
if(oldAndroidMatch && oldAndroidMatch.length > 1) {
if(parseFloat(oldAndroidMatch[1]) < 4.4) {
isOldAndroid = true
}
}
}
return!isOldAndroid && fb.WebSocket !== null && !fb.realtime.WebSocketConnection.forceDisallow_
};
to instead read:
fb.realtime.WebSocketConnection["isAvailable"] = function() {
return false
};
This worked, Chrome now long polls automatically and my app can municate with Firebase. I made the same change to the minified firebase.js but would obviously prefer a more future-proof workaround instead of this hack if anyone can suggest one.