Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
benjhess opened this issue Sep 24, 2020 · 29 comments
Closed

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

benjhess opened this issue Sep 24, 2020 · 29 comments

Comments

@benjhess
Copy link

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
Copy link
Author

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

@imhoffd imhoffd transferred this issue from ionic-team/capacitor Sep 24, 2020
@imhoffd imhoffd added enhancement New feature or request plugin: browser and removed triage labels Sep 24, 2020
@kevinfavv
Copy link

Any news?

@yaberkane05
Copy link

Any news on this ?

@nitsand
Copy link

nitsand commented Feb 27, 2022

Any news on this issue?

1 similar comment
@Bernix01
Copy link

Any news on this issue?

@richardkshergold
Copy link

We could do with this too - any update?

@cyrilfr
Copy link

cyrilfr commented Jun 29, 2022

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

@diogomgbrito
Copy link

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

@cyrilfr
Copy link

cyrilfr commented Jul 6, 2022

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?

@nitsand
Copy link

nitsand commented Jul 7, 2022

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.

@diogomgbrito
Copy link

diogomgbrito commented Jul 7, 2022

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.

@cyrilfr
Copy link

cyrilfr commented Jul 11, 2022

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);

@dsmith-slalom
Copy link

dsmith-slalom commented Jul 13, 2022

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.

@PH-Lars
Copy link

PH-Lars commented Aug 3, 2022

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

@dsmith-slalom
Copy link

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" 🤞

@Dr-Zhi
Copy link

Dr-Zhi commented Apr 23, 2023

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

@cyrilfr
Copy link

cyrilfr commented May 6, 2023

I would also love to have this PR merged!

@cardacci
Copy link

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

@idesignzone
Copy link

idesignzone commented Aug 29, 2023

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.

@timmyrosen
Copy link

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

@GiannisS
Copy link

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

@rumaisaknaz
Copy link

Any update on the PR ??

@danbaechtold
Copy link

Meeeeeeeeerge please

@arashb31
Copy link

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

@gerhardcit
Copy link

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.

@kurtiev
Copy link

kurtiev commented Mar 3, 2024

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.

@Badisi
Copy link

Badisi commented Mar 8, 2024

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")

@menosprezzi
Copy link

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")

There's a PR for that 😄
#2197

@jcesarmobile
Copy link
Member

closing since it's been supported since the release of @capacitor/browser 6.0.0

@ionic-team ionic-team locked as resolved and limited conversation to collaborators Feb 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests