We are in the midst of creating a PhoneGap-based app using AngularJS and Ionic.
This app is a store management system which ties in with an existing web app using OAuth2, and we have a problem with Android redirecting after authentication.
An event listener is set up as follows to close the InAppBrowser window either upon successfully connecting or cancelling::
if (runningInCordova) {
connectWindow.addEventListener('loadstart', function(event) {
var url = event.url;
if (url.indexOf("code=") > 0 || url.indexOf("error=") > 0) {
return callback(url).then(function() {
connectWindow.close();
},
function() {
connectWindow.close();
});
}
});
For browser testing purposes, a localhost redirect URI is also defined:
http://localhost:8100/oauthcallback.html
On iOS this works fine and the InAppBrowser closes immediately when it should, but on Android there is a delay before this event listener fires. The result is that for about 1 second the following error message is displayed:
Web page not available
The web page at http://localhost:8100/oauthcallback.html could not be loaded as:
net::ERR_CONNECTION_REFUSED
The event listener then fires and the window closes.
Is there any way to make the event listener fire more quickly in order to avoid this error?
Many thanks