Xamarin.Forms icon indicating copy to clipboard operation
Xamarin.Forms copied to clipboard

[Bug] When using WkWebViewRenderer, certain Target="_blank" links don't work even after implementing our own CreateWebView

Open georgefoulds opened this issue 2 years ago • 0 comments

Description

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, as per #8028. 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

  1. Navigate to https://app.senecalearning.com and click login (top right of the page)
  2. Click continue with Microsoft or Google
  3. Observe that this does not work. No navigation happens. A popup blocked message appears.
  4. 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

Environment

Show/Hide Visual Studio info
Visual Studio Community 2022 for Mac
Version 17.6 (build 1575)
Installation UUID: 501d84cc-0ec9-409a-adce-fbd64a2d3e64

Runtime
.NET 7.0.3 (64-bit)
Architecture: Arm64
Microsoft.macOS.Sdk 13.1.1007; git-rev-head:8afca776a0a96613dfb7200e0917bb57f9ed5583; git-branch:release/7.0.1xx-xcode14.2

Roslyn (Language Service)
4.6.0-3.23180.6+99e956e42697a6dd886d1e12478ea2b27cceacfa

NuGet
Version: 6.4.0.117

.NET SDK (Arm64)
SDK: /usr/local/share/dotnet/sdk/7.0.304/Sdks
SDK Versions:
	7.0.304
	7.0.203
	7.0.202
	7.0.201
	7.0.200
	7.0.103
	7.0.102
	7.0.101
	7.0.100
	6.0.410
	6.0.408
	6.0.407
	6.0.406
	6.0.405
	6.0.404
	6.0.403
	6.0.402
	6.0.401
	6.0.400
	6.0.302
MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks

.NET SDK (x64)
SDK Versions:
	7.0.304
	7.0.203
	7.0.202
	7.0.201
	3.1.426
	3.1.425
	3.1.424
	3.1.423
	3.1.422
	3.1.421

.NET Runtime (Arm64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	7.0.7
	7.0.5
	7.0.4
	7.0.3
	7.0.2
	7.0.1
	7.0.0
	6.0.18
	6.0.16
	6.0.15
	6.0.14
	6.0.13
	6.0.12
	6.0.11
	6.0.10
	6.0.9
	6.0.8
	6.0.7

.NET Runtime (x64)
Runtime: /usr/local/share/dotnet/x64/dotnet
Runtime Versions:
	7.0.7
	7.0.5
	7.0.4
	7.0.3
	3.1.32
	3.1.31
	3.1.30
	3.1.29
	3.1.28
	3.1.27

Xamarin.Profiler
Version: 1.8.0.49
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Xamarin Designer
Version: 17.6.3.9
Hash: 2648399ae8
Branch: remotes/origin/d17-6
Build date: 2023-06-14 17:05:55 UTC

Apple Developer Tools
Xcode: 14.3.1 21815
Build: 14E300c

Xamarin.Mac
Version: 9.3.0.6 Visual Studio Community
Hash: 97731c92c
Branch: xcode14.3
Build date: 2023-04-11 22:38:35-0400

Xamarin.Android
Version: 13.2.0.6 (Visual Studio Community)
Commit: xamarin-android/d17-5/a200af1
Android SDK: /Users/georgefoulds/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		12.0 (API level 31)
		11.0 (API level 30)
		9.0  (API level 28)
		13.0 (API level 33)

SDK Command-line Tools Version: 7.0
SDK Platform Tools Version: 33.0.2
SDK Build Tools Version: 33.0.0

Build Information: 
Mono: 6dd9def
Java.Interop: xamarin/java.interop/d17-5@149d70fe
SQLite: xamarin/sqlite/3.40.1@68c69d8
Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@9f02d77

Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.16.1
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android SDK Manager
Version: 17.6.0.50
Hash: a715dca
Branch: HEAD
Build date: 2023-06-14 17:06:00 UTC

Android Device Manager
Version: 0.0.0.1309
Hash: 06e3e77
Branch: HEAD
Build date: 2023-06-14 17:06:00 UTC

Xamarin.iOS
Version: 16.4.0.6 Visual Studio Community
Hash: 97731c92c
Branch: xcode14.3
Build date: 2023-04-11 22:38:36-0400

Build Information
Release ID: 1706001575
Git revision: d32bcc352feed2f1f54e237e23e5c375d86eaf9e
Build date: 2023-06-14 17:04:07+00
Build branch: release-17.6
Build lane: release-17.6

Operating System
Mac OS X 13.0.1
Darwin 22.1.0 Darwin Kernel Version 22.1.0
    Sun Oct  9 20:15:52 PDT 2022
    root:xnu-8792.41.9~2/RELEASE_ARM64_T8112 arm64

Enabled user installed extensions
MFractor 5.1.0


georgefoulds avatar Jul 18 '23 14:07 georgefoulds