Everytime I run this script, it shows "not connected" first time and after that "connected". Why does it always trigger "not connected" first? There are some topics with same issue like this one link, but no answers.
var connectedRef = firebase.database().ref(".info/connected");
connectedRef.on("value", function(snap) {
if (snap.val() === true) {
alert("connected");
} else {
alert("not connected");
}
});