apache / cordova-plugin-inappbrowser

Apache Cordova InAppBrowser Plugin
https://cordova.apache.org/
Apache License 2.0
1.12k stars 2.16k forks source link

exit event is handled in ios diferently than in android #649

Open alesrosina opened 4 years ago

alesrosina commented 4 years ago

Bug Report

Problem

Event exit is triggered in Android every time browser is closed - so if it is closed with browser.close() or if it is closed via "Done" button in footer.

In iOS this event is triggered ONLY when a user clicks "Done" button, but it does not trigger when browser.close() is called.

What is expected to happen?

Both platforms should handle it the same way - in my opinion, Android way of implementing it is the correct one.

What does actually happen?

Already described above.

Command or Code

import { Injectable } from '@angular/core';
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';

@Injectable()
export class Demo {

  constructor(private iab: InAppBrowser) {}

  public runBrowser(url) {

    const browser = this.iab.create(url, '_blank', { usewkwebview: 'yes', hidden: 'yes' });

    browser.on('loadstop').subscribe(async event => {
      //this  will not trigger exit event on ios, while on android it will
      browser.close(); 
    });

    browser.on('exit').subscribe(event => {
      console.log("exit");
    });
  }
}

Environment, Platform, Device

Android 9, iOS 13

Version information

"cordova": "^9.0.0",
"cordova-android": "^8.1.0",
"cordova-ios": "^5.1.1",
"cordova-plugin-inappbrowser": "^3.2.0",

Checklist

KuschL commented 4 years ago

I've got almost the same (if not the same) issue. The 'exit' event is triggered correctly on iOS if the browser is not hidden.

So the code above will work as intended. The code below doesn't close the browser.

import { Injectable } from '@angular/core'
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx'

@Injectable()
export class Demo {

  constructor(private iab: InAppBrowser) {}

  public runBrowser(url) {

    const browser = this.iab.create(url, '_blank', { hidden: 'yes' })

    browser.on('loadstop').subscribe(async event => {
      // browser is still running in background
      browser.close();
    })

    browser.on('exit').subscribe(event => {
      console.log("exit")
    })
  }
}

I'm using Ionic with latest versions:

Ionic:

   Ionic CLI                     : 6.4.0 (~/.nvm/versions/node/v13.2.0/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.0.7
   @angular-devkit/build-angular : 0.901.0
   @angular-devkit/schematics    : 9.1.0
   @angular/cli                  : 9.1.0
   @ionic/angular-toolkit        : 2.2.0

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 8.1.0, ios 5.1.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 21 other plugins)

Utility:

   cordova-res : 0.11.0
   native-run  : 0.3.0

System:

   ios-deploy : 1.9.4
   ios-sim    : 8.0.2
   NodeJS     : v13.2.0 (~/.nvm/versions/node/v13.2.0/bin/node)
   npm        : 6.14.4
   OS         : macOS Catalina
   Xcode      : Xcode 11.4 Build version 11E146
alesrosina commented 4 years ago

@KuschL you are correct, I missed that setting while making a small example. It's same for me, so I will edit main post.

Thanks.

MumblesNZ commented 3 years ago

Hey @alesrosina / @KuschL, did either of you find a fix for this?

alesrosina commented 3 years ago

Sadly no. I went with a bit different solution, but would be out of scope for this bug.

dpadilla20 commented 3 years ago

Any idea? :( other solution ?

techrationaldev commented 3 years ago

Use const browser = this.iab.create('https://ionicframework.com/','_system','hidden=no'); and try!

ilyakamens commented 6 days ago

This worked for me on iOS: https://github.com/Something-Useful/cordova-plugin-inappbrowser/commit/61720c6caba695ddf2204d9c80ec2153d1218415