Cap-go / capacitor-inappbrowser

Capacitor plugin in app browser with urlChangeEvent
MIT License
58 stars 38 forks source link

Sample Usage/Implementation (Listeners not working) #53

Closed bhekor closed 3 months ago

bhekor commented 1 year ago

I think it'll be very useful to show a sample usage instead of just listing the functions(Listener) out, as there are lots of beginners.

For instance, I have this code it's opening the URL but the listeners aren't and I have no idea why;

async openURL(url: string): Promise<void> {
    await InAppBrowser.open({ url });
    InAppBrowser.addListener('urlChangeEvent', async (event) => {
      console.log('InAppBrowser url changed');

      const currentURL = window.location.href;
      if (currentURL.includes(`/payment/callback`)) {
        alert('Here')
        console.log('Callback URL loaded');
        await InAppBrowser.close();
        this.checkPayment();
      }
    })

    InAppBrowser.addListener('closeEvent', async () => {
      console.log('InAppBrowser page closed');
      alert('Closed')
    })
  }

Just so you have a context I want to load a payment page, e.g https://google.com/payment/pay and after a successful payment it'll be redirected here https://google.com/payment/callback so I want to listen to when this redirecting happens which I think the urlChangeEvent to care of and close the browser but no even the closeEvent

riderx commented 1 year ago

You are doing it right, can you share on what device you do this, it seems you find a bug !

chrste90 commented 1 year ago

I have the same problem. The code is working on an iPhone 13, but not on a Google Pixel 6 Pro. Anything i can do to help reproduce the problem?

chrste90 commented 1 year ago

Hm, InAppBrowser.open() doesn't register any listeners, only InAppBrowser.openWebView, so the code can't work on android.

riderx commented 1 year ago

yes i think it's a limitation of the basic view who don't support it

bhekor commented 10 months ago

You are doing it right, can you share on what device you do this, it seems you find a bug !

Android, Nokia 7plus

bhekor commented 10 months ago

Please is there any way forward?

riderx commented 3 months ago

use openWebView, we cannot have event working in InAppBrowser.open sadly