phonegap / build

This is the public repository for PhoneGap Build source and bug tracking
92 stars 33 forks source link

[Android] Not whitelisted link still open in webview - PhoneGap 2.1.0 #66

Closed amirudin closed 10 years ago

amirudin commented 11 years ago

Unlisted site still open in webview - PhoneGap 2.1.0 even with target="_blank". I can confirm and able to reproduce the problem.

Below is the code to reproduce the problem: https://github.com/amirudin/Unlisted-Bug-PG-2.1

Related issue: http://community.phonegap.com/nitobi/topics/android_apps_using_build_service_and_version_2_1_never_open_links_in_browser

mrfatguy commented 11 years ago

Nothing has been done ever since opening this thread! We have PhoneGap 2.3.0 official and 2.4.0 right away to be released and still every application build with Build always opens all links in WebView on Android, no matter what configuration changes has been done.

This is completely aganist Access Tags blog article -- no matter, if you whitelist or not your URL, no matter if you use target="_blank" or not and finally, no matter, if you set OpenAllWhitelistURLsInWebView (ignored under Android?) to no in config.xml, PhoneGap Build apps will always open all URLs in WebView.

Additional problem appears, that once link is opened in WebView on Android, user cannot use Back button to go back to your application. This button is ignored in this state and the only way to leave such 'hanged' mobile application, is to use Home button and then restart your app.

I have an example application, where pressing Back button always triggers prompt, if user really want to exit the app. This prompt displays only in my app. Whenever I tap any link and destination page is opened, Back button stops responding. So, I'm not pretty sure, if I'm still really in WebView or in some strange places, where nothing except Home button and tapping other links works.

Plus BlackBerry: I have been only able to test this issue on old, hacked 5.0 device, but it turned out, that external links behavior also does not follows Access Tags blog article. It is said, that for not whitelisted links, BlackBerry should prompt, where to open such link. But I was informed, that PhoneGap Build application complies on BlackBerry, that particular link is not whitelisted (put to config files) and refuses to open it anywhere.

This is completely not acceptable and make apps build with Build nearly unusable on Android. As a user I personally hate applications that opens URLs inside them, not in a browser and I would surely stop using any that would force me to do so.

When can we expect this issue to be finally fixed?

hardeep commented 11 years ago

@trejder I've noticed that OpenAllWhitelistURLsInWebView is deprecated in 2.3.0+

Try using the in app browser, specifically the window.open function.

Here is some documentation: http://docs.phonegap.com/en/2.3.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser

Let me know how it goes.

mrfatguy commented 11 years ago

@hardeep I don't know, if OpenAllWhitelistURLsInWebView is depracted, but even if it is, it was always mentioned in iOS, specific section. So, that is not an issue, I added it extra.

The issue is, that Access Tags blog article says, that links not whitelisted under Android will always open in system browser, which is not true. Currently they always opens in WebView, no matter, if whitelisted or not. This is a bug in PhoneGap / PhoneGap Build.

Finally, something! :] Yes, your example does seems to be working great. The only thing, that bothers me, is that docs says that InAppBrowser object is available only on iOS and Android. What about other platforms? I have pointed out that there are problems / inconsistence with mentioned blog article and how external links are handled under BlackBerry. This can't be solved with InAppBrowser.

AlbertBrand commented 11 years ago

Did you specify a in your PG config with an external url?

I tried this for a mobile-site-as-app:

<content src="http://myexternalsite.com">

But this led to baseUrl being set to "http://" (https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/CordovaWebView.java#L397) and this made the check for webview/external always to end up as webview (https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/CordovaWebViewClient.java#L195)

The solution in this case is to add a / at the end of the src:

<content src="http://myexternalsite.com/">

and add the access origin as stated in the docs.

Pseudo-Nym commented 11 years ago

I've tried a multitude of hacks and workarounds in attempt to address the issue of target="_blank" not opening the URL in the devices native browser (both iOS and Android). Nothing has worked other than going back to PhoneGap 2.0.0

How long before 2.0.0 is no longer supported at build.phonegap.com & links are forced to open up in WebView?

mrfatguy commented 11 years ago

Conluding above answers and some docs I've found, I think, you have two solutions to check out.

First, is a standard one and goes like this:

  1. White list your domain or link -- i.e. add <access origin="http://domain.com" /> to config.xml.
  2. Add <preference name="OpenAllWhitelistURLsInWebView" value="No" /> to config.xml.
  3. In your application, add target="_blank" to any link, you wish to open in external browser -- for example: <a href="http://domain.com" target="_blank">domain.com</a>.

It is said (by many, though not proven by me) that this solution works 100% sure under iOS.

You can also borrow solution from Android, with using InAppBrowser, which is said to be available in iOS as well:

var ref = window.open('http://acrid.pl', '_system', 'location=yes');

You can omit location=yes (third parameter) part as it is its default value and it is ignored with second argument set to _system.

This is the key, solution and workaround. Using window.open with _system parameter will always open your link in external, system-level webbrowser, while your mobile application will be suspended. Once user press back button, system browser will be closed (suspended) and your application restored.

More info is available in PhoneGap Documentation.

I don't have any iOS device at hand, so I neither can't test first solution, nor prove that second one works. But is surely works on Android, in all my apps, so if InAppBrowser is available in iOS, this solution should work for you as well.

B.T.W.: I've tested this solution with PhoneGap 2.3.0 (actually PhoneGap Build), so, if it works for you, you don't have to bother about PG 2.0.0 end of maintenance.

Pseudo-Nym commented 11 years ago

trejder,

First let me say thank you. The first works like a charm in iOS indeed but not Android. The second I'm not sure about yet. I don't know if build.phongap.com supports the InAppBrowser plugin. I don't see it listed in the documentation there https://build.phonegap.com/docs/plugins

And there is no Eclipse project for this as we've strickly been using build.phonegap.com to generate the binaries rather than doing it locally. If not then this is a good excuse to insist I be able to set up Eclipse on my workstation (ugh IT and their restrictions here can be such a pita sometimes)

amirudin commented 11 years ago

@Pseudo-Nym InAppBrowser is a built-in function at the PG core level, available on Build since 2.3.0. Give it a shot: https://github.com/amirudin/pgb-inAppBrowser

mrfatguy commented 11 years ago

@Pseudo-Nym as amirudin has already told you, the InAppBrowser is a core PG object, not PGB plugin so you have to look for it in PhoneGap docs, not PhoneGap Build plugins. Since, it is core, it should work on all platforms, but I have confirmations about iOS and Android only. I've heard that there were some issues / limitations in using it on BlackBerry, but I wasn't able to confirm then, as I don't have any such device. To be more specific -- InAppBrowser object itself is supported on all platforms, but opening links outside WebView, in external browser may fail on platforms other than iOS and Android.

Sorry, for not making it clear enough, that first solution is iOS-only. No, as far as I know, there is no chance, it will work on any other platform -- neither Android nor any else than iOS.

I don't use Eclipse at all, and all this stuff with making PG installed local and compiling local is large than me. Beside, it always lets you build for one specific target platform only, while Build makes all platform files at once. That's why I decided to use PGB only. I know the limitations (only Javascript, no way to attach any Java or native code library, so for example hard stuff working with ads) and I accept them. So, I can assure you that either InAppBrowser or any other PhoneGap core object is supported on Build (PGB is actually nothing else than specific PG installation in the cloud) and will work fine in any platform, you compile your project to, via PGB.

wildabeast commented 11 years ago

Fixed.

wildabeast commented 11 years ago

Had to temporarily revert this fix, as pluginstall does not support android access tags.

Reverting to always wildcard access until fixed.

Renzox commented 10 years ago

any solution?

wildabeast commented 10 years ago

We are in the process of upgrading out systems to plugman, which will include this fix. Will update when complete, hopefully this week.

wildabeast commented 10 years ago

Fixed.

Fortuitous commented 9 years ago

"Using window.open with _system parameter will always open your link in external, system-level webbrowser, while your mobile application will be suspended."

This works for me (phonegap build) for external urls. But I'd like the same behavior for opening an internal html page that is bundled along with my app. Instead, the system browser doesn't open at all and I get asked if I want to use dolphin or html viewer . . . neither of which will connect to my file.

Any thoughts? Thanks. .

wildabeast commented 9 years ago

@Fortuitous I don't think this is possible -- one application (dolphin etc) can't access the assets inside another application bundle (your app), for security reasons. A solution would be to use the File API to copy the html page to a publicly accessible location on the device, and then launch that in the InAppBrowser.