capacitor-plugins icon indicating copy to clipboard operation
capacitor-plugins copied to clipboard

feat: provide a workaround for Browser.close() on android

Open benjhess opened this issue 5 years ago • 27 comments

Feature Request

Provide a workaround for Browser.close() on android, in order to provide the same features on all platforms.

Description

As i understand it, capacitors goal is to provide the same api and features on all platforms (wherever possible). This currently seems to be not the case with the Browser plugin, as Browser.close() does not work on android (also documented). For me, this makes the plugin pretty much unusable, as i build my app for ios and android...

Currently i have to use cordova-plugin-inappbrowser, which is not a preferable solution. It would be very nice, if we could solely rely on capacitor to do this :)

Platform(s)

android

Preferred Solution

Provide a workaround for Browser.close() on android

Alternatives

Use cordova-plugin-inappbrowser (not really a preferable solution)

benjhess avatar Sep 24 '20 21:09 benjhess

BTW: I know that the android implementation uses chrome custom tabs and this does not provide a close functionality. However, there seems to be a workaround by using broadcasts and redirect to the activity, that opened the chrome custom tab. Maybe this solution could be used: https://gist.github.com/im182cm/2c7723d42b2d7091af6c493b97b732b7

benjhess avatar Sep 24 '20 22:09 benjhess

Any news?

kevinfavv avatar Aug 10 '21 13:08 kevinfavv

Any news on this ?

yaberkane05 avatar Dec 28 '21 21:12 yaberkane05

Any news on this issue?

nitsand avatar Feb 27 '22 14:02 nitsand

Any news on this issue?

Bernix01 avatar Apr 12 '22 02:04 Bernix01

We could do with this too - any update?

richardkshergold avatar Apr 22 '22 10:04 richardkshergold

Not being able to close the browser is a huge issue. Please, could you make it number one priority for this project? Thank you.

cyrilfr avatar Jun 29 '22 07:06 cyrilfr

My workaround was to use Observables.

I turned the Browser.open() into an observable with from and pipe takeUntil with a void Subject to cancel the observable. Worked on Android but not iOS for me

diogomgbrito avatar Jul 05 '22 14:07 diogomgbrito

My workaround was to use Observables.

I turned the Browser.open() into an observable with from and pipe takeUntil with a void Subject to cancel the observable. Worked on Android but not iOS for me

That sounds promising. Do you have an example?

cyrilfr avatar Jul 06 '22 06:07 cyrilfr

The workaround I'm using (on Android at least) is cordova-plugin-browser instead of cordova-plugin-inappbrowser and then simply use the new browser "Close" ('X') feature.

nitsand avatar Jul 07 '22 06:07 nitsand

My workaround was to use Observables. I turned the Browser.open() into an observable with from and pipe takeUntil with a void Subject to cancel the observable. Worked on Android but not iOS for me

That sounds promising. Do you have an example?

@cyrilfr Sure, this is a simplified example but it's something along those lines:

const cancel$ = new Subject<void>();

from(Browser.open({url}))
	.pipe(takeUntil(cancel$))
         .subscribe()

//Whenever you need, call next to cancel the previous observable
cancel$.next();

I work with Ionic/Angular, i don't know how it would look like with React and Vue.

diogomgbrito avatar Jul 07 '22 08:07 diogomgbrito

What version of Capacitor are you using? I tried with this code but that didn't work:

const cancel$ = new Subject<void>();
from(Browser.open({ url }))
      .pipe(takeUntil(cancel$))
      .subscribe();
setTimeout(() => cancel$.next(), 5000);

cyrilfr avatar Jul 11 '22 07:07 cyrilfr

It looks like there's a PR that has addressed this issue and it simply needs to have some formatting updated so that it'll pass linting. If there's anybody that has submitted PRs to Ionic before and knows the protocol for taking over the PR and getting it across the finish line.

dsmith-slalom avatar Jul 13 '22 05:07 dsmith-slalom

Added PR #1107 with the import fixes for #151 and added call.resolve() for async await support.

PH-Lars avatar Aug 03 '22 19:08 PH-Lars

Added PR #1107 with the import fixes for #151 and added call.resolve() for async await support.

You are a rockstar and a scholar! Fingers crossed the PR is merged "soon" 🤞

dsmith-slalom avatar Aug 03 '22 19:08 dsmith-slalom

Any updates on this? It's been 8 months since the PRs were opened... Thanks!

Dr-Zhi avatar Apr 23 '23 21:04 Dr-Zhi

I would also love to have this PR merged!

cyrilfr avatar May 06 '23 15:05 cyrilfr

It would be great if this PR could be completed! Who should we reach out to for approval?

cardacci avatar May 29 '23 20:05 cardacci

It is absolutely necessary to close the browser in case of auth redirections or they will not work within the web view. In case of Google auth, Cordova InAppBrowser is not secured from Google perspective and it will show an error. Consider some apps may have only Google as authentication option. Capacitor Browser plugin needs to address these issues.

idesignzone avatar Aug 29 '23 22:08 idesignzone

Its' been 3 years now, this is an absolutely necessary feature of this plugin.

timmyrosen avatar Sep 13 '23 13:09 timmyrosen

We need an answer if this will be completed or not! Thank you

GiannisS avatar Sep 19 '23 11:09 GiannisS

Any update on the PR ??

rumaisaknaz avatar Dec 05 '23 11:12 rumaisaknaz

Meeeeeeeeerge please

danbaechtold avatar Jan 19 '24 13:01 danbaechtold

I'm using patch-package in the interim to automate the patch as part of the build.

arashb31 avatar Jan 26 '24 03:01 arashb31

Really? Ionic team. 4 years in the making, and you do not have an answer or direction to this? In the mean time new version of Ionic is coming out, but a BASIC thing like closing an in app browser is NOT supported on Android. Someone seems just not interested in making this work. This is disappointing.. you would think it would be better than this.

gerhardcit avatar Mar 03 '24 13:03 gerhardcit

Really? Ionic team. 4 years in the making, and you do not have an answer or direction to this?

In the mean time new version of Ionic is coming out, but a BASIC thing like closing an in app browser is NOT supported on Android. Someone seems just not interested in making this work.

This is disappointing.. you would think it would be better than this.

It's another PR was merged. Just try latest version, it should work fine in Android as well.

kurtiev avatar Mar 03 '24 16:03 kurtiev

I can confirm it's working on Android, so this ticket can be closed.

Only the documentation needs to be updated (it still says "no-op on other platforms")

Badisi avatar Mar 08 '24 10:03 Badisi