InAppBrowser.close() blocked by close prompt


#1

Hi,

I have an InAppBrowser I am using in my project.

When I try and close the browser, depending on the web page, it pops up with a dialog (Do you want to close this page kinda thing).

Any way to stop that happening and just force close the InAppBrowser?

Thank you! :slight_smile:


#2

HI @ryanhow

could you add here your code of in app browser
thanks


#3

That’s classified :), but it goes like this…

  1. Open In App Browser on a site with a window.beforeunload listener that pops open a confirmation when closing.
  2. Call browser.close()

The browser then pops up the close prompt (as it should I expect) and closes after the dialog is dismissed. Just like when using a normal web browser.

So I was hoping there may be a way to not allow alerts and other browser prompts which block?


#4

Work around answer: Do you control which URL is being opened? If so, you could route it through a proxy that removes the code that opens the alert…


#5

I don’t sorry. But I had the idea to inject some JavaScript to remove the code. Doesn’t work 100%of the time though.


#6

So the users start somewhere and then navigate to a page where this “Please confirm you want to leave” alert/confirm happens?

Yes, using https://github.com/apache/cordova-plugin-inappbrowser#inappbrowserexecutescript you could probably do something like that.
I thought if you could maybe overwrite the alert or confirm function, but I don’t think (and somehow hope) this is not possible.


#7

Yes, the navigation is to 3rd party sites. Thanks for the override idea, looks like it is quite possible :grin:. It does feel wrong though!

I’m not sure that it would be 100% reliable though. Every time a link is clicked to navigate to a new page it will need to be overridden again. Time will tell.

I’m actually quite surprised that we are allowed to inject JavaScript into the InAppBrowser. It’s like a free for all XSS.