dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.21k stars 1.75k forks source link

Maui webview .Navigated event is not triggered #23502

Open softourS opened 4 months ago

softourS commented 4 months ago

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

github-actions[bot] commented 4 months ago

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 commented 4 months ago

Can we get a human here?

kaysho commented 3 months ago

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

yanhao1115 commented 3 months ago

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

softourS commented 2 months ago

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

hehao-ntt commented 2 months ago

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

NcaDev1 commented 2 months ago

Facing the same issue, a fix would be highly appreciated

HomeroLara commented 2 months ago

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

vikher commented 2 months ago

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

raapeer commented 2 months ago

I have the same problem and need to resolve this.

cris-her commented 2 months ago

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

NcaDev1 commented 2 months ago

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 commented 2 months ago

@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 commented 3 days ago

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.