ng-cordova-oauth icon indicating copy to clipboard operation
ng-cordova-oauth copied to clipboard

Suggest inappbrowser open as hidden

Open wkande opened this issue 8 years ago • 7 comments

Perhaps open the inappbrowser as hidden and look for the loadstop event to show. Many times the web page will not load because the site is down or not available, worse the network connection is down. This causes the app to hang to the user because the inappbrowser is blank. $timeout is needed to kill the browser if this happens.

wkande avatar Sep 28 '15 12:09 wkande

Thanks for the suggestion. I'll take it into consideration :-)

nraboy avatar Sep 28 '15 17:09 nraboy

That is a very common issue. When network is "floating" between online and offline states, you can end up having a NET::ERR_CONNECTION_TIMED_OUT or other similar error tossed out of inAppBrowser

How would loadstop catch such an error and get the user back to the app?

ffabreti avatar Mar 16 '16 19:03 ffabreti

Its more of a dirty trick to keep the flow through the browser from getting stuck. If the connection does not come to life you end up closing the inappbrowser with a timer, if the connection is good then you show it. Once it is shown you could still have other network issues but at least you know you got to Facebook to begin with.


var browserRef = cordova.InAppBrowser.open(flowUrl,
                    '_blank', 'hidden=yes,location=no,clearsessioncache=yes,clearcache=yes');

var timerPromise = $timeout( function(){
              if(wifiFlag == false){
                  browserRef.removeEventListener("exit",function(event){});
                  browserRef.removeEventListener("loadstop",function(event){});
                  browserRef.close();
                  window.plugins.toast.showLongTop($translate.instant('_CONNECT_TMEOUT'));
              }
            }, 10000);

browserRef.addEventListener('loadstop', function(event) {
                $timeout.cancel(timerPromise);
                // If the event.url is the same as the url we called then the site was not found
                // because there is no redirect. Cause no wifi or data connection.
                if(flowUrl == event.url){
                    //console.log("loadstop");
                    browserRef.removeEventListener("exit",function(event){});
                    browserRef.removeEventListener("loadstop",function(event){});
                    browserRef.close();
                    window.plugins.toast.showLongTop($translate.instant('_CONNECT_INTERNET'));
                }
                wifiFlag = true;
                browserRef.show();
            });

wkande avatar Mar 16 '16 21:03 wkande

Did not see your answer, but I have done it thru a different approach (without timeout). I will make a commit on my repo.

ffabreti avatar Mar 18 '16 13:03 ffabreti

Pull requests are always encouraged if you want to contribute to this project.

nraboy avatar Mar 18 '16 14:03 nraboy

What happened to this? can it be used somehow? any docs?

mateosss avatar Oct 16 '16 14:10 mateosss

I don't believe @ffabreti ever made me a PR.

nraboy avatar Oct 19 '16 17:10 nraboy