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

Maui webview .Navigated event is not triggered #23502

Open
softourS opened this issue Jul 9, 2024 · 16 comments
Open

Maui webview .Navigated event is not triggered #23502

softourS opened this issue Jul 9, 2024 · 16 comments
Labels
area-controls-webview WebView migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 platform/iOS 🍎 t/bug Something isn't working
Milestone

Comments

@softourS
Copy link

softourS commented Jul 9, 2024

Description

I think the title explains it all. When using a WebView on Maui and adding the Navigated event, this event is not triggered when is reached. Specifically, it occurs when using WebViewHandlers, or at least it used to work when we used a simple WebView, and after we learned about Handlers instead of Renderers and changed the code accordingly, it stopped working.

We used this sample for an example of Custom WebViewHandler (both iOS and Android):
https://github.com/nmoschkin/MAUIWebViewExample.git

It's on the latest version, .net MAUI 8.0 (VS for Mac doesn't tell us more, thank you VS).

Steps to Reproduce

The sample code should suffice but just in case:

1.- Create MAUI app (VS for Mac)
2.- Create both a HybridWebView (inherits from WebView, the example of handlers had View, but that way the WebView did not recognize the .Navigated event as belonging to WebView) and 2 WebViewHandlers (Android & iOS).
3.- On the MainPage, create a variable for the HybridWebView:
private static HybridWebView browser = new();
4.- Add a source (browser = new HybridWebView { Source = url };) on the public MainPage
5.- Add the .Navigated event, like this:
browser.Navigated += async (sender, e) => {
//Write something here
};
6.- Set a breakpoint inside the event
7.- Nothing happens

Link to public reproduction project repository

https://github.com/softourS/regulares-netmaui-app-public.git

Version with bug

Unknown/Other

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android

Affected platform versions

Android min version 21 to target 34; iOS min version 14 to target 17.2

Did you find any workaround?

Everywhere we search they'd say it's solved, but the issue is usually forgotten or ignored, so no.

Relevant log output

No response

@softourS softourS added the t/bug Something isn't working label Jul 9, 2024
Copy link
Contributor

github-actions bot commented Jul 9, 2024

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@softourS
Copy link
Author

softourS commented Jul 9, 2024

Can we get a human here?

@PureWeen PureWeen added platform/iOS 🍎 migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 area-controls-webview WebView labels Jul 9, 2024
@PureWeen PureWeen added this to the Backlog milestone Jul 9, 2024
@kaysho
Copy link

kaysho commented Jul 24, 2024

Experiencing this also, it gets fired when I use out of the box WebView, but doesn't when using custom WebViews with WebViewHandler.

@yanhao1115
Copy link

@softourS @kaysho
I’m encountering the same issue. Is there a solution available?

@softourS
Copy link
Author

@yanhao1115 As far as I am concerned they just don't care

@hehao-ntt
Copy link

I’m encountering the same issue. Is there a solution available?

@NcaDev1
Copy link

NcaDev1 commented Aug 13, 2024

Facing the same issue, a fix would be highly appreciated

@HomeroLara
Copy link

HomeroLara commented Aug 26, 2024

Any updates on this issue? I'm seeing the same behavior on Android and iOS for both Navigating & Navigated events.

@vikher
Copy link

vikher commented Aug 28, 2024

Any news on this? I'm having the same problem with the Navigating and Navigated events on both Android and iOS.

@raapeer
Copy link

raapeer commented Aug 29, 2024

I have the same problem and need to resolve this.

@cris-her
Copy link

I am recently facing the same issue, any update on this?

@NcaDev1
Copy link

NcaDev1 commented Sep 2, 2024

We found the issue in our code: We are using a custom NavigationDelegate delegate, that wasn't overriding DidFinishNavigation. We now override this method and call DidFinishNavigation on the NavigationDelegate created by MAUI.

We are now getting the Navigated event on Android and iOS (MAUI Version 8.0.61).

@HomeroLara
Copy link

@NcaDev1 thanks for the info! Question: Your work around appears to only be for iOS, is this correct? Also, were you having this problem on Android as well? If so, can you share any details on what you did to address this?

Thanks!

@NikaRadosinska
Copy link

NikaRadosinska commented Nov 7, 2024

I had this problem too. My handler is only overriding functions "ConnectHandler" and "CreatePlatformView". I solved it like this:

    protected override WKWebView CreatePlatformView()
    {
        var view = new WKWebView(new CoreGraphics.CGRect(), new WKWebViewConfiguration());
        view.NavigationDelegate = new MauiWebViewNavigationDelegate(this);
        return view;
    }

Before i returned unmodified WKWebView.

@AidanOrton
Copy link

Any update on this issue? I'm facing it too on 9.0.10

@blmiles
Copy link

blmiles commented Jan 12, 2025

ANY resolution to this?
Seeing this in iOS, Android and Windows... pretty sure this is an issue introduced handling events in WebView control.

This never triggers and no code-change, was triggering before upgrading and targeting .Net 9.0

            _webView.Navigated += (sender, e) =>
            {
                if (e.Url.StartsWith(options.EndUrl))
                {
                    if (tcs.Task.Status != TaskStatus.RanToCompletion)
                    {
                        tcs.SetResult(new BrowserResult
                        {
                            ResultType = BrowserResultType.Success,
                            Response = e.Url.ToString()
                        });
                    }
                }
            };

            _webView.Source = new UrlWebViewSource{ Url = options.StartUrl };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-webview WebView migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 platform/iOS 🍎 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests