title: PhoneGap InAppBrowser event listener too slow (Android)
body: <p>We are in the midst of creating a PhoneGap-based app using AngularJS and the Ionic framework.</p>
  
  <p>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.</p>
  
  <p>An event listener is set up as follows to close the InAppBrowser window either upon successfully connecting or cancelling::</p>
  
  <pre><code>    if (runningInCordova) {
          connectWindow.addEventListener('loadstart', function(event) {
              var url = event.url;
              if (url.indexOf("code=") &gt; 0 || url.indexOf("error=") &gt; 0) {
  
                  return callback(url).then(function() {
                      connectWindow.close();
                  },
                  function() {
                      connectWindow.close();
                  });
              }
          });
  </code></pre>
  
  <p>For browser testing purposes, a localhost redirect URI is also defined: </p>
  
  <pre><code>http://localhost:8100/oauthcallback.html
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>Web page not available
  The web page at http://localhost:8100/oauthcallback.html could not be loaded as:
  net::ERR_CONNECTION_REFUSED
  </code></pre>
  
  <p>The event listener then fires and the window closes.</p>
  
  <p>Is there any way to make the event listener fire more quickly in order to avoid this error?</p>
  
  <p>Many thanks</p>