[Android][iOS] WebView Navigated event not triggered when using HtmlWebViewSource#28354
Conversation
|
Hey there @Tamilarasan-Paranthaman! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where the WebView Navigated event was not being triggered when using HtmlWebViewSource without a BaseUrl on Android and iOS. The changes remove conditions that prevented the event from firing when default asset URLs were used.
- Removed conditional checks for default asset URLs in the Navigated event on Android and iOS.
- Added new UI test cases in TestCases.HostApp and automated tests in TestCases.Shared.Tests to verify the fix.
- Updated platform-specific code in MauiWebViewClient.cs, WebViewHandler.Android.cs, and MauiWebViewNavigationDelegate.cs to align with the intended behavior.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Controls/tests/TestCases.HostApp/Issues/Issue23502.cs | Added UI test page demonstrating WebView events. |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue23502.cs | Added automated test to verify WebView events. |
| src/Core/src/Platform/Android/MauiWebViewClient.cs | Removed check for AssetBaseUrl in OnPageStarted and OnPageFinished to ensure proper event triggering. |
| src/Core/src/Handlers/WebView/WebViewHandler.Android.cs | Removed condition checking AssetBaseUrl in NavigatingCanceled. |
| src/Core/src/Platform/iOS/MauiWebViewNavigationDelegate.cs | Removed early return when URL equals the default asset URL to allow the Navigated event to trigger. |
Comments suppressed due to low confidence (2)
src/Core/src/Handlers/WebView/WebViewHandler.Android.cs:146
- Ensure that removing the check for AssetBaseUrl in NavigatingCanceled is fully validated so that asset-based URLs are handled appropriately without unintended side effects.
if (VirtualView == null || string.IsNullOrWhiteSpace(url))
src/Core/src/Platform/iOS/MauiWebViewNavigationDelegate.cs:43
- The removal of the early return for the default asset URL in iOS is appropriate for resolving the issue; please ensure that this change does not adversely affect valid file-based navigations.
if (url == "file://{NSBundle.MainBundle.BundlePath}/")
| public override void OnPageStarted(WebView? view, string? url, Bitmap? favicon) | ||
| { | ||
| if (!_handler.TryGetTarget(out var handler) || handler.VirtualView == null || url == WebViewHandler.AssetBaseUrl) | ||
| if (!_handler.TryGetTarget(out var handler) || handler.VirtualView == null) |
There was a problem hiding this comment.
Removal of the AssetBaseUrl check in OnPageStarted appears intentional for fixing the bug; please ensure that this change does not introduce regressions when handling local asset URLs.
| public override void OnPageFinished(WebView? view, string? url) | ||
| { | ||
| if (!_handler.TryGetTarget(out var handler) || handler.VirtualView == null || string.IsNullOrWhiteSpace(url) || url == WebViewHandler.AssetBaseUrl) | ||
| if (!_handler.TryGetTarget(out var handler) || handler.VirtualView == null || string.IsNullOrWhiteSpace(url)) |
There was a problem hiding this comment.
Confirm that the removal of the AssetBaseUrl condition in OnPageFinished does not affect scenarios where asset-based URLs might be used, ensuring consistency with the Android behavior.
…ebViewSource (#28354) * WebView navigated event fix * Test sample changes.
…ebViewSource (dotnet#28354) * WebView navigated event fix * Test sample changes.
…ebViewSource (dotnet#28354) * WebView navigated event fix * Test sample changes.
…ebViewSource (dotnet#28354) * WebView navigated event fix * Test sample changes.
…ebViewSource (dotnet#28354) * WebView navigated event fix * Test sample changes.
…ebViewSource (#28354) * WebView navigated event fix * Test sample changes.
…ebViewSource (#28354) * WebView navigated event fix * Test sample changes.
…ebViewSource (dotnet#28354) * WebView navigated event fix * Test sample changes.
Root Cause of the issue
Description of Change
Issues Fixed
Fixes #23502
Fixed #21800
Tested the behaviour in the following platforms
Screenshot
Before-Fix-Android.mov
After-Fix-Android.mov
Before-Fix-iOS.mov
After-Fix-iOS.mov