google / cordova-plugin-browsertab

A Cordova plugin that provides an interface to in-app browser tabs that exist on some mobile platforms, such as SFSafariViewController on iOS and CustomTabs on Android.
Apache License 2.0
117 stars 147 forks source link

Can I attach listener to the browser to close the browser after a particular event> #5

Open nikhil91 opened 7 years ago

mr-e- commented 7 years ago

I'm trying to figure this out too... How to listen for certain urls and close the browser?

dorgold commented 7 years ago

You can do that using custom urls (https://github.com/EddyVerbruggen/Custom-URL-scheme) Have the webpage navigate to a custom URL that your app is registered with, it will close the browsertab for you (And will allow you to pass data in using query params).

washowasho commented 6 years ago

@dorgold Thank you. That worked for me.

washowasho commented 6 years ago

@dorgold , I decided to take the Universal Links approach since Apple doesn't seem to be supporting Custom URL Scheme anymore. I have this working for Android fine... but Universal Links doesn't seem to be working for me. Do you have this implemented?

larssn commented 6 years ago

@dorgold Hmm, that doesn't seem to close it on iOS. Works fine on Android though.

dorgold commented 6 years ago

@washowasho @larssn sorry for the late response. I have double checked, we use a custom URL scheme on iOS and it works fine (closes the tab). Make sure you use a custom URL (app-identifier://something) and not a universal link (http://www.something.com)

washowasho commented 6 years ago

@dorgold Yes, I ended up using custom URL scheme as well. Any idea on how long that will be good for as universal links seem to be taking over?

dorgold commented 6 years ago

@washowasho I didn't see any publication stating that Apple are planning to deprecate this feature. They do seem to favor universal links, but i don't think they are going to remove support for custom urls anytime soon.

larssn commented 6 years ago

Hm, I can only get the browser-tab to close when I physically click our custom url scheme link. Not when I redirect to it. It's in the form appname://. We're using InAppBrowser for now, but I'd prefer to use this.

FYI I'm building an OAuth1 flow.

dorgold commented 6 years ago

We use javascript to redirect: window.location = 'appnames://someting' and it works ok.