Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-13198

InAppBrowser doesnot disptach events after system browser is open using cordova.InAppBrowser.open(url, '_system')

    XMLWordPrintableJSON

Details

    • Patch, Important

    Description

      The InAppBrowser instance does not automatically dispatch the events after the system browser is opened via InAppBrowser. Please follow the generic code below:

      //example 1 : bug with cordova.InAppBrowser.open(url, '_system');
      //event hander for inAppBrowser
      function inAppBrowserEventHandler(event){
        //process few logic with the event parameter
        //and if conditions met lets open it on system browser
        var url = 'https://cordova.apache.org/';
      
        //open the url in system browser
        var _inAppBrowserSystem = cordova.InAppBrowser.open(url, '_system');
      }
      //open the link in inside the iAB without
      var _inAppBrowser = cordova.InAppBrowser.open(url, '_blank');
      _inAppBrowser.addEventListener('loadstop', inAppBrowserEventHandler);
      

      The _inAppBrowser instance works fine for the first time. But as soon as the system browser is opened, the event 'for eg. loadstop' does not fire automatically. This bug/issue appears only when system browser is open. for eg, the following code works perfectly.

      //example 2 : no bug without cordova.InAppBrowser.open(url, '_system');
      //event hander for inAppBrowser
      function inAppBrowserEventHandler(event){
        //process few logic with the event parameter
        //and if conditions met lets open it on system browser
        var url = 'https://cordova.apache.org/';
      
        //log the url in the console instead of browser
        console.log('open this url in the system browser ' + url)
      }
      //open the link in inside the iAB without
      var _inAppBrowser = cordova.InAppBrowser.open(url, '_blank');
      _inAppBrowser.addEventListener('loadstop', inAppBrowserEventHandler);
      

      It seems the new '_inAppBrowserSystem' instance somehow interrupts the event dispatcher for the '_inAppBrowser' instance. I found that if the _inAppBrowserSystem is assign the same eventHandler, then _inAppBrowser starts to dispatch the event. The following code helped me solve the problem but this should still be registered as a bug.

      //example 3 : hack/solution with cordova.InAppBrowser.open(url, '_system');
      //event hander for inAppBrowser
      function inAppBrowserEventHandler(event){
        //process few logic with the event parameter
        //and if conditions met lets open it on system browser
        var url = 'https://cordova.apache.org/';
      
        //open the url in system browser
        var _inAppBrowserSystem = cordova.InAppBrowser.open(url, '_system');
      
         //for somereason, after assigning the same event handler to the _inAppBrowserSystem, the event dispatcher continues to work
        _inAppBrowserSystem.addEventListener('loadstop', inAppBrowserEventHandler);
      }
      //open the link in inside the iAB without
      var _inAppBrowser = cordova.InAppBrowser.open(url, '_blank');
      _inAppBrowser.addEventListener('loadstop', inAppBrowserEventHandler);
      

      I have the solution for now, but I still register this as a bug as the event dispatcher is not consistent. For instance, the code in 'example 1' should work as in 'example 2'. If there is not a quick fix, I hope at least the documentation get updated with this hack.

      Thx
      Laxman

      Attachments

        Activity

          People

            Unassigned Unassigned
            laxman Laxman
            Votes:
            4 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated: