I have two related questions regarding the Firebase web platform . synchronization of locally modified data on the server :
Each client sharing a Firebase database maintains its own internal version of any active data. When data is updated or saved, it is written to this local version of the database. The Firebase client then synchronizes this data with Firebase servers and other clients based on "best effort."
1. Handling synchronization errors
Data modification methods ( set() , remove() , etc.) can be taken by the onComplete callback parameter:
A callback function that will be called when synchronized with Firebase servers is complete. The callback will be passed to the Error object on error; else null .
var onComplete = function(error) { if (error) { console.log('Synchronization failed'); } else { console.log('Synchronization succeeded'); } }; fredRef.remove(onComplete);
In the example above, what errors should be expected from the fredRef.remove() callback?
- Temporary errors?
- Client disconnected (loss of network connection)
- Firebase server is temporarily overloaded or shut down for maintenance, but will be available again soon
- Permanent errors?
- Permission denied (due to security rules )?
- Does the database location not exist?
Is there a way to distinguish between temporary and permanent errors?
How should we handle / repair these errors?
For temporary errors, do we need to call fredRef.remove() again after a short time to repeat the operation?
2. Global sync status
I understand that each set() and remove() call will receive an individual success / failure synchronization will result in an onComplete callback. But I'm looking for a way to determine the global synchronization status for the entire Firebase client .
I would like to use the beforeunload event listener to alert the user when they try to leave the page before all the changed data is synchronized with the server, and I'm looking for some function like firebase.isAllModifiedDataSynced() . Something like that:
window.addEventListener('beforeunload', function (event) { if (!firebase.isAllModifiedDataSynced()) { event.returnValue = 'Some changes have not yet been saved. If you ' + 'leave this page, your changes will be lost.'; } });
Here is an example of the same functionality in Google Drive:

I know a special /.info/connected location :
It is useful for the client to know when they are online or offline. Firebase clients provide a special location in /.info/connected , which is updated each time the client's connection status changes. Here is an example:
var connectedRef = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com/.info/connected"); connectedRef.on("value", function(snap) { if (snap.val() === true) { alert("connected"); } else { alert("not connected"); } });
The special location /.info/connected can be connected to the beforeunload event beforeunload as follows:
var connectedRef = new Firebase('https://myapp.firebaseio.com/.info/connected'); var isConnected = true; connectedRef.on('value', function (snap) { isConnected = snap.val(); }); window.addEventListener('beforeunload', function (event) { if (!isConnected) { event.returnValue = 'Some changes have not yet been saved. If you ' + 'leave this page, your changes will be lost.'; } });
My question is:
- If
isConnected true , does this mean that all changed data has been synchronized with the server? - i.e. Is connected " means " synchronized " ?
If not, how can an application determine the global synchronization status of an entire Firebase client?
- Is there a special location
/.info/synchronized ? - Does the application need to manually track the result of successful / unsuccessful synchronization of each
onComplete callback?