Ionic / firebase stuck loading forever

Alright

I did try a few weeks ago to integrate services like ionic deploy, push, analytics, but ended up removing them from my project. One thing I thought it might be was the fact that had an old version of ionic in lib/ionic instead of the latest but I updated to 1.1.0 and still see this problem.

I am running Android 4.4.4 on a Droid Maxx

cordova plugins
com.ionic.keyboard 1.0.4 "Keyboard"
com.phonegap.plugins.facebookconnect 0.11.0 "Facebook Connect"
cordova-plugin-camera 1.2.0 "Camera"
cordova-plugin-device 1.0.1 "Device"
cordova-plugin-file 2.1.0 "File"
cordova-plugin-file-transfer 1.2.1 "File Transfer"
cordova-plugin-geolocation 1.0.1 "Geolocation"
cordova-plugin-inappbrowser 1.0.1 "InAppBrowser"
cordova-plugin-splashscreen 2.1.0 "Splashscreen"
cordova-plugin-whitelist 1.0.0 "Whitelist"
org.apache.cordova.statusbar 0.1.10 “StatusBar”

@mfeliciano.enrique

I wonder what version of android @pierro is running…

Its good to see your list is so simple, it rules out a lot of plugins.

Whats your content-security-policy in index.html?

@mfeliciano.enrique, @pierro

Ok maybe this will help:

Try adding this to your config.xml file:

<allow-intent href="*.firebaseio.com" />
  <allow-intent href="auth.firebase.com" />
  <access origin="*.firebaseio.com" />
  <access origin="auth.firebase.com" />

The allow-intent code came from here: https://www.firebase.com/docs/web/libraries/ionic/guide.html#section-cordova-inappbrowser

However, I found that it still did not work until I added the access-origin code too

Not sure if its a full fix tho… hmm

2 Likes

Hi all :smile:

My android version is >4.4

Actually, I no longer have that problem.

The problem came from my code, in my login controller where I use authentication, I had two “firebase ref”.

I noticed one of them wasn’t even used, maybe a leftover from previous attempt of facebook login.

Anyway, once I got rid of the extra " new Firebase " ref, I never encountered that problem again… Hopefully it can help.

Well, that’s good to know, because I do have a couple instances of multiple new Firebase…

Ok, so this seems to be the problem. Definitively - http://stackoverflow.com/questions/31219005/firebase-requests-stalling-at-negotiation-phase-how-to-debug

It’s fixed if you uncomment cordova.js in index.html.

Now I wonder what are the consequences of uncommenting cordova.js?

4 Likes

@jason_engage

That fixed it for me! Thanks so much you definitely helped me find the root cause of this problem faster than I would have otherwise. I will keep an eye out for any adverse effects.

Thanks ! I was stuck with the same problem, now everything work fine.
I think there no big conscequence about uncomment cordova, I see a line in the console about that :
Ionic Core: cordova.js has already been loaded

EDIT: Nope, the problem is still there :frowning:

I had more or less the same problem but in my case the issue was intermittent and not reproducible. See:

I also saw the warning about “cordova already loaded” (logged by the ionic.io libraries).

For now I just took out the ionic.io libraries (analytics etc, at the moment these are in “alpha” stage so probably it wouldn’t be wise to use them for production apps anyway). I’ll monitor closely if I see the issue again.

You help me a lot, thanks for posting the answer, I wonder if anyone from the Ionic team will post an official answer because right now I’m using ionic servers and I’ve uncommented cordova.js

Did you decide that this is the best solution to fixing the issue?

Do Not Remove Cordova, You may face some serious problem in future when you want to use some native library.

I made some tricks which solved this issue for me.

Create firebase instance just after app module like this -
var appMain = angular.module(‘starter’, [‘ngCordova’,‘ngStorage’,‘ionic’,‘starter.controllers’,‘starter.services’,‘firebase’]);
var firebaseInst = new Firebase(“https://xyz.firebaseio.com/”);

& this instance you can directly call in controller

var objMatches = $firebaseObject(firebaseInst.child(“methods”));

— Do Not Create Services for firebase instance.

2 Likes

Hey everyone!

I was facing a similar problem on my android phone. Ironically my app ran smoothly on my development laptop and most of the time it ran smoothly on my android phone, but once this problem occurred my android, it kept loading without doing anything anymore, it never ran on my android again. Only when I did ‘ionic run android’ and reinstalled the app did it work again.

I had a look at my app resources via remote debugging and I noticed the key value: “firebase:previous_websocket_failure” had “true” to its value. So I deleted this key-value pair and simply restarted my app, then my app finally began working again. I plan on getting around this solution by checking for this key-value pair and removing it programatically, and hopefully the next time a user opens the app it will work…if the user hasn’t uninstalled it by then.

I dont know what happens to my app that this bug seems to crop up, so I cant replicate the conditions for the bug and know whether my code works. Normally that particular key value pair would get deleted once loading starts, but on some occasions it doesnt and thats why my app fails.

I dont know if this post helps. Just check your resources via remote debugging. Maybe its is something there. Let me know what you guys think.

I’ve also noticed this websocket failure in the localstorage, but usually disappears automatically… Next time our app keeps stuck during loading (it happens sometimes) I’ll check if it’s still there and remove it…

Exactly my point. In my case when app got stuck loading that key-value pair never dissappered as it should have so I’ve put it on $watch to delete it immediately if it turns up. Lets see if I run into this problem again. For the time being the app seems to work fine. Fingers crossed.

This issue has bugged me the most. I have found a potential solution for this problem now which fixed it for me.
1- Do not uncomment cordova.js
2 - wrap every firebase init with ionic paltform ready.
Firebase stays connected as long as the app is open in device.

Hi timmy, could you provide some sample code. How are you wrapping the initialization? We have a factory and we’re not sure how to init firebase properly… would something like this work?

(function() {
	'use strict';

	angular
		.module('mycoolmodule')
		.factory('Auth', Auth);

	/* @ngInject */
	function Auth(FIREBASE_URL, $firebaseAuth) {
		return $q(function(resolve, reject) {
			$ionicPlatform.ready(function() {
		           var ref = new Firebase(FIREBASE_URL);
                           resolve( $firebaseAuth(ref) );
		        });
		});
	}
	
})();

You can use this solution - I asked this on stackoverflow . received an answer from firebase team - Interesting use of $q(Constructor)

Also you can monitor your connection by listening on firebase at .info/connected - like this
app.run(function($ionicPlatform, $ionicPush, FIREBASE_URL) {
$ionicPlatform.ready().then(function(){

var ref = new Firebase(FIREBASE_URL);
ref.child(".info/connected").on("value", function(snap){
  if(snap.val() === true){
    console.info("Firebase connected")
  }else{
    console.info("Firebase disconnected");
  }
});

});
});

1 Like

Aaah ok, just like we were doing… cool

Hi,

I’m experiencing the same issue on Ionic 2

Cordova CLI: 5.4.1
Ionic Version: 2.0.0-alpha.57
Ionic CLI Version: 2.0.0-beta.17
Ionic App Lib Version: 2.0.0-beta.8
ios-deploy version: 1.8.3
ios-sim version: 5.0.1
OS: Mac OS X El Capitan
Node Version: v5.1.1
Xcode version: Xcode 7.2 Build version 7C68

any ideas to resolve this issue? I can’t believe that I’m alone with issue. I’ve added an issue ticket for this:

1 Like