I would like to set a custom User Agent string on a Xamarin Forms WebView on iOS and Android. I am using a custom renderer for this on both platforms. The iOS version works fine, but on Android, the following code when placed in the OnElementChanged of the Android custom renderer causes the Navigated event of the WebView to fire twice, once when the WebView starts to load and once when it is actually completed. Commenting out the setting of the user agent causes the Navigated event to only fire once when the load is complete like it should. Is there another way to set the user agent on Android or is there some other way to get around what seems to be a bug here?
// get useragent
var userAgent = this.Control.Settings.UserAgentString;
if (!userAgent.Contains("MyApp"))
{
userAgent += " MyApp";
// set useragent
this.Control.Settings.UserAgentString = userAgent;
}