유원태
유원태

Reputation: 1

C# webview2 can’t loading popup page

I’m implementing a specific authentication flow using WebView2. When clicking on an HTML element on a specific domain, a new window opens, sends a session authentication request to another domain, and then redirects to a new URL. However, I’m facing an issue when trying to handle this process in WebView2.

Current Situation:

When clicking a button on a specific domain, a popup window opens. The popup window undergoes the following process: Initial URL: about:blank (blank page) Then redirects: Authentication domain → Final target domain. I attempted to handle the popup in a new WebView2 instance using the NewWindowRequested event. The issue is that when I set e.Handled = true to block the popup, and then try to load the URL in a new WebView2 instance, it stops at about:blank and doesn’t proceed with the redirection.

Issues:

The initial URL of the popup is always about:blank, and the redirection doesn’t proceed. When I set e.Handled = false to unblock the popup, the popup opens in the default Edge browser, and the authentication and redirection process works as expected. However, in the new WebView2 control, the process gets stuck at about:blank, and the redirection does not occur. Let me know if you'd like to make further adjustments! 😊

Code I Tried:

`webView2.CoreWebView2.NewWindowRequested += (s, e) =>
{
    e.Handled = true; // Block the popup

    // Create a new WebView2 instance
    var popupWebView2 = new WebView2();
    popupWebView2.Source = e.Uri; // Initial about:blank URL
    
    popupWebView2.CoreWebView2InitializationCompleted += (sender, args) =>
    {
        if (args.IsSuccess)
        {
            // Load the popup URL
            popupWebView2.CoreWebView2.Navigate(e.Uri.ToString());
        }
    };
};`

Upvotes: 0

Views: 36

Answers (0)

Related Questions