Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Problem/Bug]: NavigationCompleted is not invoked since 125.0 #4579

Open
SimonSchwendele opened this issue May 21, 2024 · 5 comments
Open

[Problem/Bug]: NavigationCompleted is not invoked since 125.0 #4579

SimonSchwendele opened this issue May 21, 2024 · 5 comments
Assignees
Labels
bug Something isn't working regression Something used to work but doesn't anymore

Comments

@SimonSchwendele
Copy link

SimonSchwendele commented May 21, 2024

What happened?

Today the WebView2 Runtime was updated from 124.0.2478.97 to 125.0.2535.51 .

I use Microsoft.Web.WebView2 in my WPF application.
When I call CoreWebView2.Navigate(uri); for the first time, the NavigationCompleted is invoked as expected.

When I call Navigate second time only the NavigationStarting event gets invoked.

Sample Code
    async Task InvokeBrowserNavigation(string uri)
    {
        WebView2.NavigationStarting += (_, args) => Console.Writeline($"Navigating to '{args.Uri}'");
        WebView2.NavigationCompleted += (_, args) =>
        {
            Console.Writeline("Navigation completed");
        };

         await WebView2.EnsureCoreWebView2Async();
         WebView2.CoreWebView2.Navigate(uri);
    }

Importance

Blocking. My app's basic functions are not working due to this issue.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

125.0.2535.51

SDK Version

1.0.2478.35

Framework

WPF

Operating System

Windows 10, Windows 11, Windows Server

OS Version

22631.3447

Repro steps

Invoke CoreWebView2.Navigate(uri); twice
only the first NavigationCompleted event is invoked

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

Regression in newer Runtime

Last working version (if regression)

SDK 1.0.1661.34, Runtime 124.0.2478.97

@SimonSchwendele SimonSchwendele added the bug Something isn't working label May 21, 2024
@github-actions github-actions bot added the regression Something used to work but doesn't anymore label May 21, 2024
@vbryh-msft
Copy link
Contributor

Is it for any url or some particular one? Are other navigation events getting called?

@SimonSchwendele
Copy link
Author

SimonSchwendele commented May 21, 2024

Is it for any url or some particular one? Are other navigation events getting called?

Hi there

Thanks for the quick reply.
As written above the event NavigationStarting gets invoked all the time.

Even when both URLs are exactly the same, NavigationCompleted is only fired the first time

I'll test the other ones in a few hours

@vbryh-msft
Copy link
Contributor

I have tried to navigate to wikipedia in our wpf sample app with runtime 125.0.2535.51 and I see NavigationCompleted events both times - there should be something else. Do you able to repro it in our sample app? Which public url do you see it?

@SimonSchwendele
Copy link
Author

I have tried to navigate to wikipedia in our wpf sample app with runtime 125.0.2535.51 and I see NavigationCompleted events both times - there should be something else. Do you able to repro it in our sample app? Which public url do you see it?

I'll try that once I'm in the office in a few hours and report back at you.
The URLs are nothing special.
The webview2 is just used to perform pkce to acquire an id and access token.

@SimonSchwendele
Copy link
Author

SimonSchwendele commented May 23, 2024

I have tried to navigate to wikipedia in our wpf sample app with runtime 125.0.2535.51 and I see NavigationCompleted events both times - there should be something else. Do you able to repro it in our sample app? Which public url do you see it?

Sorry for the late reply.
Got my hands full with deploying workarounds so our customers may actually start working again.

So heres the case.
I Can use your sample App and the BrowserNavigation works as expected.
However theres no Navigation

However I still only get the NavigationStarting in our application.

        WebView2.CoreWebView2InitializationCompleted += (_, arg) =>
        {
            if (WebView2?.CoreWebView2 is null)
            {
                RedirectToWebviewDownload();
                return;
            }

            WebView2.CoreWebView2.Settings.AreDevToolsEnabled = false;
            WebView2.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
            WebView2.CoreWebView2.Settings.IsStatusBarEnabled = false;
            WebView2.CoreWebView2.Profile.PreferredColorScheme = CoreWebView2PreferredColorScheme.Light;
            
            WebView2.CoreWebView2.SourceChanged += (_, _) => log.WriteLine("---> SourceChanged");
            WebView2.CoreWebView2.ContentLoading += (_, args) => log.WriteLine($"---> ({args.NavigationId}) ContentLoading {(args.IsErrorPage ? string.Empty : "(ErrorPage)")}");
            WebView2.CoreWebView2.HistoryChanged += (_, _) => log.WriteLine("---> HistoryChanged");
            WebView2.CoreWebView2.DOMContentLoaded += (_, args) => log.WriteLine($"---> ({args.NavigationId}) DOMContentLoaded");
            WebView2.CoreWebView2.NavigationCompleted += (_, args) => log.WriteLine($"---> ({args.NavigationId}) NavigationComplete "
                                                                                    + $"{(args.IsSuccess ? "(success)" : "(error)")} - {args.WebErrorStatus.ToString()} - {args.HttpStatusCode}");
            
            initWebview2.TrySetResult(arg);
        };
        
        ...
        public Uri InvokeBrowserNavigation(string uri, string callbackUri, StreamWriter logger)
    {
        log ??= logger;
        var navigationTask = new TaskCompletionSource<CoreWebView2NavigationStartingEventArgs>();
        var taskCanceled = false;
        
        WebView2.NavigationStarting += WaitForNavigationCallback;

        Dispatcher.InvokeAsync(async () =>
        {
            environment ??= await WebView2.CreateUserEnvironment();
            if (environment is null)
            {
                RedirectToWebviewDownload();
                return;
            }
            await WebView2.EnsureCoreWebView2Async(environment);
            await initWebview2.Task.ConfigureAwait(false);
            WebView2.CoreWebView2.Navigate(uri);
        });

        // This block waits for the navigating event without
        // blocking the ui thread. (Source: Mark Zachmann)
        var frame = new DispatcherFrame();
        new Thread(() =>
        {
            try
            {
                navigationTask.Task.Wait(cancellationTokenSource.Token);
                Dispatcher.Invoke(() => Hide());
                Task.Delay(500).Wait(cancellationTokenSource.Token);
            }
            catch (OperationCanceledException e)
            {
                Log.GetLog().Warning(e, "Navigation canceled.");
                taskCanceled = true;
            }
            finally
            {
                frame.Continue = false;
            }
        }).Start();
        Dispatcher.PushFrame(frame);
        
        WebView2.NavigationStarting -= WaitForNavigationCallback;
        if (taskCanceled)
            throw new OperationCanceledException("Authentication canceled by user.");

        return new Uri(currentNavigatioTarget);
        
        void WaitForNavigationCallback(object sender, CoreWebView2NavigationStartingEventArgs e)
        {
            log.WriteLine($"NavigationStarting{(e.IsRedirected ? " (redirect)" : string.Empty)} '{e.Uri}'");
            if (!e.Uri.StartsWith(callbackUri))
                return;
            
            currentNavigatioTarget = e.Uri;
            navigationTask.TrySetResult(e);
        }
    }
log
-- IdToken --
Url: https://sts.cmiag.dev/dev/identity/connect/authorize?client_id=metatool&response_type=id_token&scope=openid+profile&redirect_uri=oob%3A%2F%2Fmetatool%2Fcallback&state=7e998b8f0d1f404a8f2edca02459eb2e&nonce=6fdf4f8bdbc04f6786aa356399a5f405&acr_values=tenant%3Adev+manual_scheme_selection%3AFalse

NavigationStarting 'https://sts.cmiag.dev/dev/identity/connect/authorize?client_id=metatool&response_type=id_token&scope=openid+profile&redirect_uri=oob%3A%2F%2Fmetatool%2Fcallback&state=7e998b8f0d1f404a8f2edca02459eb2e&nonce=6fdf4f8bdbc04f6786aa356399a5f405&acr_values=tenant%3Adev+manual_scheme_selection%3AFalse'
NavigationStarting (redirect) 'https://sts.cmiag.dev/dev/identity/Account/Login?ReturnUrl=%2Fdev%2Fidentity%2Fconnect%2Fauthorize%2Fcallback%3FauthzId%3D737A20F82C84D443603BBAE81F8DE96E83227BCDA9580AAD1F178FA6A9E31050'
---> SourceChanged
---> (2) ContentLoading (ErrorPage)
---> HistoryChanged
---> (2) DOMContentLoaded
---> (2) NavigationComplete (success) - Unknown - 200
NavigationStarting 'https://sts.cmiag.dev/dev/identity/External/Challenge?scheme=oaw&returnUrl=%2Fdev%2Fidentity%2Fconnect%2Fauthorize%2Fcallback%3FauthzId%3D737A20F82C84D443603BBAE81F8DE96E83227BCDA9580AAD1F178FA6A9E31050'
NavigationStarting (redirect) 'https://login.microsoftonline.com/2ded1acc-3f72-4a03-8acd-3fc55e03cbd6/oauth2/v2.0/authorize?client_id=b7d4c071-e087-40cf-82a7-fec40a3defaa&redirect_uri=https%3A%2F%2Fsts.cmiag.dev%2Fdev%2Fidentity%2Fsignin-oidc-oaw&response_type=id_token&scope=openid%20profile%20email&response_mode=form_post&nonce=638520624502126042.NTc0ZmQ5NGYtNWMzZi00M2U4LTk2YmUtNGNjN2Q5YzgwNWVkZGE3ODUzNjUtYTg1NC00ZDQ2LWIyZmMtMzliMDQ2NmQ3Mjdk&state=CfDJ8M3io48A4eVKrICxxfJsvi-UWiY6pDeEGhCUy0IkJayjtx7bqV9C0zHLWETVVszGB-X4UFxdtWQfsMvH87W8hJblScRmXnPE9p9BsO79AOViZbhXhV6oFE-a35H8yAKc-YTB40XA0XGXJzRZy9_tdHpowfAH2n93nLyu6MH_N_60Smd8vj-8vTdeOZFfSHZx48-hBw0EvfFy9ea0WG5uS2aKwReH1gR_PvvDj6O5T94N1-WqQ1SAo9w8kPBZcmEb224JR5zUByXFmr-t36aBNkZbn0mFHGQ3hzggCONnz2UKjNOLCY1zIcGovOyigvS4846oU3jNQkwObzobWfnkepUM_ujVLcEwfzY73zF2FwEHeBOXyQE8aywfQjZPAKXTAkW7btumpS7mFMRlensezyAYF60EWWNPdObMbKATE8P9CAFUDEJx_lDtlrVHHLWweTJELSpTq6Jt4N9XjzbmRrMSPmh8qLx9E6EBI5UxTt603qjtdcziG2hmwiojgHRmj2sa9-lGoF7x4O1jYyXBZPY&x-client-SKU=ID_NET8_0&x-client-ver=7.4.1.0'
---> SourceChanged
---> (3) ContentLoading (ErrorPage)
---> HistoryChanged
---> (3) NavigationComplete (success) - Unknown - 200
NavigationStarting 'https://sts.cmiag.dev/dev/identity/signin-oidc-oaw'
NavigationStarting (redirect) 'https://sts.cmiag.dev/dev/identity/External/Callback'
---> SourceChanged
---> (4) ContentLoading (ErrorPage)
---> HistoryChanged
---> (4) NavigationComplete (success) - Unknown - 200
NavigationStarting 'https://sts.cmiag.dev/dev/identity/connect/authorize/callback?authzId=737A20F82C84D443603BBAE81F8DE96E83227BCDA9580AAD1F178FA6A9E31050'
NavigationStarting (redirect) 'oob://metatool/callback#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IkUzN0U2NDg2MDVERkREMzRFNzhFRkQ2ODFGRjhBODFGIiwieDV0IjoiRXR2OGNoem1LcHZZc2QyQlpBbzV5d1c5Z1NNIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL3N0cy5jbWlhZy5kZXYvZGV2L2lkZW50aXR5IiwibmJmIjoxNzE2NDY1NjUxLCJpYXQiOjE3MTY0N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f404a8f2edca02459eb2e&session_state=yWAgUQ6NDDDehlIFZdykb-UBc7VbQCWpZ0Sq8I1gWl0.1EA36E86BD422A19CB184D6C26F01035'
---> (5) NavigationComplete (error) - ConnectionAborted - 0

-- AccessToken --
Url: https://sts.cmiag.dev/dev/identity/connect/authorize?client_id=metatool&response_type=token&scope=metatool&redirect_uri=oob%3A%2F%2Fmetatool%2Fcallback&state=e98b832686ff4d98afbfa6c9707c86ed&acr_values=tenant%3Adev+manual_scheme_selection%3AFalse

NavigationStarting 'https://sts.cmiag.dev/dev/identity/connect/authorize?client_id=metatool&response_type=token&scope=metatool&redirect_uri=oob%3A%2F%2Fmetatool%2Fcallback&state=e98b832686ff4d98afbfa6c9707c86ed&acr_values=tenant%3Adev+manual_scheme_selection%3AFalse'
NavigationStarting (redirect) 'oob://metatool/callback#access_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IkUzN0U2NDg2MDVERkREMzRFNzhFRkQ2ODFGRjhBODFGIiwieDV0IjoiRXR2OGNoem1LcHZZc2QyQlpBbzV5d1c5Z1NNIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL3N0cy5jbWlhZy5kZXYvZGV2L2lkZW50aXR5IiwibmJmIjoxNzE2NDY1NjUyLCJpYXQiOjE3MTY0NjU2NTIsImV4cCI6MTcxNjUwODg1MiwiYXVkIjoiaHR0cHM6Ly9zdHMuY21pYWcuZGV2L2Rldi9pZGVudGl0eS9yZXNvdXJjZXMiLCJzY29wZSI6WyJtZXRhdG9vbCJdLCJhbXIiOlsiY21pX2V4dGVybmFsX29hdyJdLCJjbGllbnRfaWQiOiJtZXRhdG9vbCIsInN1YiI6ImRldiQ3MmJmOTU0YWFjY2Y0ODM4OTMxOTQ2MTA5MGFhYzg3MyIsImF1dGhfdGltZSI6MTcxNjQ2NTY1MSwiaWRwIjoib2F3IiwibmFtZSI6WyJkZXYkNzJiZjk1NGFhY2NmNDgzODkzMTk0NjEwOTBhYWM4NzMiLCJTY2h3ZW5kZWxlIl0sInVzZXJfaWQiOiJTU0MiLCJnaXZlbm5hbWUiOiJTaW1vbiIsImVtYWlsIjoic2ltb24uc2Nod2VuZGVsZUBjbWlhZy5jaCIsIm5hbWVpZGVudGlmaWVyIjoiNzJiZjk1NGFhY2NmNDgzODkzMTk0NjEwOTBhYWM4NzMiLCJ1c2VyX2d1aWQiOiI3MmJmOTU0YWFjY2Y0ODM4OTMxOTQ2MTA5MGFhYzg3MyIsImZ1bGxuYW1lIjoiU2ltb24gU2Nod2VuZGVsZSIsImFwaV9zZXJ2ZXIiOiJkZXYiLCJ0ZW5hbnQiOiJkZXYiLCJzaWQiOiJCRTJDMkZERkM0ODVDNDZGQ0MwNDc5MDA0QTU1MUJBNyIsImp0aSI6IkU4MERGNEI1NzA1NjQ3N0JGQjJDRkYwRjVFMjk1RjcwIn0.pPgHpdehu1PzJf4O-TzkZYKNzD029tDxsyDKjCXTmRfU58KAM0P42wyW9dnbm-BxaEp72FrlT9R-MiDUfqTXuDQ3B3Lgj9vfDZYlMo9VfTFO0HRgKJOSdxVvSvxxvipadb32krxf5B-0D_YevInyrpjtJb0DtJcNt6ovL5EViUkEk0UNiIphwOPhDTqJ_BJwsZpvA7y1_a_PMxiE-5h8gF7WRg8Kpk4J-9et2rF9Hu53CvqZPZX9XEb5FBnTQdjIbiTqgWugOlGEtak1EFF55Vk0Whk614XWP6iRU8bJVT-sS0ThVpcBoX2g5e7n2VKialGLbanF9kOPu4ipNY7SVA&token_type=Bearer&expires_in=43200&scope=metatool&state=e98b832686ff4d98afbfa6c9707c86ed'

When I try the navigations within the SampleRepo both events occur

private void ExecutePkce(object sender,
                         ExecutedRoutedEventArgs e)
{
    var token = "idToken";
    webView.CoreWebView2.NavigationStarting += (_, args) => Console.WriteLine($"{args.NavigationId} NavigationStarting {token} {args.Uri} ");
    webView.CoreWebView2.NavigationCompleted += (_, args) => Console.WriteLine($"{args.NavigationId} NavigationComplete {token}");

    const string urlId = "https://sts.cmiag.dev/dev/identity/connect/authorize?client_id=metatool&response_type=id_token&scope=openid+profile&redirect_uri=oob%3A%2F%2Fmetatool%2Fcallback&state=7e998b8f0d1f404a8f2edca02459eb2e&nonce=6fdf4f8bdbc04f6786aa356399a5f405&acr_values=tenant%3Adev+manual_scheme_selection%3AFalse";
    const string urlToken =
        "https://sts.cmiag.dev/dev/identity/connect/authorize?client_id=metatool&response_type=token&scope=metatool&redirect_uri=oob%3A%2F%2Fmetatool%2Fcallback&state=e98b832686ff4d98afbfa6c9707c86ed&acr_values=tenant%3Adev+manual_scheme_selection%3AFalse";
    
    webView.CoreWebView2.Navigate(urlId);
    token = "accessTOken";
    webView.CoreWebView2.Navigate(urlToken);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression Something used to work but doesn't anymore
Projects
None yet
Development

No branches or pull requests

3 participants