How to resolve issues when using JavaScript and CSS from HTML in a XF WebView?

JohnHardmanJohnHardman GBUniversity mod
edited May 2017 in Xamarin.Forms

I’ve just spent a month developing a cross-platform project using Apache Cordova, HTML, CSS, JavaScript etc. Now that I am back on my Xamarin.Forms project, I am contemplating whether to combine C#/Xamarin.Forms and WebViews containing HTML, CSS and JS, simply as there are some things that are easier to do using browser technologies than using XF.

As an experiment, I took the source files for my Cordova app and loaded them in a Xamarin.Forms WebView and tested on Android, iOS and UWP. Mostly, things worked as expected. Two bits that didn’t on Android were/are:

(1a) the title on alert boxes, which shows up as ‘The page at "file://" says’ .
(2) Geolocation permissions being reported as denied. This appears to be a Chrome security thing that kicks in when the base url starts file:// (see https://stackoverflow.com/questions/5423938/html-5-geo-location-prompt-in-chrome for more details).

And on iOS:

(1b) the title on alert boxes is the path/name of the HTML file, rather than the application name
(3) The box that pops up to ask the user for permission to use current location contains a seriously user-unfriendly application name (although at least on iOS, it's possible to go into Safari settings to enable location services to stop this appearing, although unfortunately for all sites loaded into Safari)

So, five questions

(1) On Android and iOS, how can I change the title that appears on alert boxes in JavaScript (inside WebView)?
(2) How can I get Chrome in a WebView on an Android mobile device to allow geolocation when the base HTML page is local, rather than a remote URL?
(3a) On iOS, how can I force the permissions request box to use a friendly application name?
(3b) On iOS, is there any way to enable location services for specific websites in Safari, rather than all websites? (I wonder if this is an info.plist thing)
(4) Has anybody encountered any other gotchas when using JavaScript and CSS in a Xamarin.Forms WebView?

@TheRealJasonSmith - I seem to recall seeing a post from you about WebView issues a while back - I wonder if you've encountered any of the above and, if so, whether you found solutions?

Answers

Sign In or Register to comment.