Xamarin.Forms Target="_blank" links not working WkWebViewRenderer
We are trying to open a certain link that is set to open in a new window. We have set the UIDelegate to 'this' in OnElementChanged in our WkWebViewRenderer and implemented CreateWebView, telling it to open in the current webview if the action.Request.URL is null, This works, but only the second time the link is tapped. The first time produces an error saying that popups are blocked by the browser. Our WkWebViewRenderer CreateWebView looks like this:
[Export("webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:")]
public WKWebView CreateWebView(WKWebView webView, WKWebViewConfiguration configuration, WKNavigationAction action, WKWindowFeatures features)
{
if (action.Request.Url != null)
{
webView.LoadRequest(action.Request);
}
return null;
}
And we set the WeakUIDelegate in OnElementChanged like this:
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
try
{
base.OnElementChanged(e);
if (NativeView != null)
{
WeakUIDelegate = this;
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
Steps to Reproduce
- Navigate to https://app.senecalearning.com and click login (top right of the page)
- Click continue with Microsoft or Google
- Observe that this does not work. No navigation happens. A popup blocked message appears.
- Tap the same link again and CreateWebView is hit this time and the link is followed in the same webview.
Expected Behavior
The link to sign in via Google or Microsoft is followed the first time the link is tapped.
Actual Behavior
The link to sign in via Google or Microsoft is followed the second time the link is tapped.
Basic Information
- Version with issue: Xamarin.Forms 5.0.0.2545
- Platform Target Frameworks:
- iOS: 16.4