[BlazorWebView] Implement web request interception#30037
Merged
Conversation
This also refactors the code a bit and disconnects it from the HybridWebView since the concept is a base idea.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request enhances the BlazorWebView component by adding web resource request interception, detailed logging, and expanded device tests. Key changes include:
- Introducing the WebResourceRequested event and corresponding interception logic in BlazorWebView and platform-specific handlers.
- Enhancing logging to provide detailed debug information when handling web requests.
- Expanding and improving device tests to validate the new interception functionality.
Reviewed Changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/MauiDeviceTests/WebViewHelpers.* | Refactored retry logic and added new helper methods for asynchronous script execution. |
| tests/MauiDeviceTests/Elements/* | Added new test classes for component, navigation, logging, and service behavior while removing redundant test files. |
| src/Maui/iOS/BlazorWebViewHandler.iOS.cs | Added request interception and logging logic for iOS. |
| src/Maui/Windows/WinUIWebViewManager.cs | Updated request handling to integrate interception and improved logging. |
| src/Maui/IBlazorWebView.cs & BlazorWebView.cs | Extended the public API with a new WebResourceRequested event and corresponding interface implementation. |
| src/Maui/Android/WebKitWebViewClient.cs | Enhanced interception logic and logging for Android. |
| src/Maui/Microsoft.AspNetCore.Components.WebView.Maui.csproj | Removed an unused file reference to streamline the project. |
Comments suppressed due to low confidence (1)
…otnet/maui into dev/blazorwebview-interception
This reverts commit c86cf1e.
This reverts commit e14c75a.
PureWeen
previously approved these changes
Jun 20, 2025
PureWeen
reviewed
Jun 20, 2025
PureWeen
reviewed
Jun 20, 2025
mattleibow
commented
Jun 20, 2025
PureWeen
approved these changes
Jun 20, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11382
This pull request introduces significant enhancements to the BlazorWebView component, focusing on adding request interception capabilities, improving logging, and expanding test coverage. Key changes include implementing a new event for handling web resource requests, integrating logging for intercepted requests, and adding device tests to validate the new functionality.
Enhancements to Request Interception:
WebResourceRequestedevent toBlazorWebView, enabling applications to intercept and handle web resource requests. This includes methods for setting custom responses. (src/BlazorWebView/src/Maui/BlazorWebView.cs, [1] [2]IBlazorWebViewto implement theIWebRequestInterceptingWebViewinterface, supporting request interception. (src/BlazorWebView/src/Maui/IBlazorWebView.cs, src/BlazorWebView/src/Maui/IBlazorWebView.csL11-R11)src/BlazorWebView/src/Maui/Android/WebKitWebViewClient.cs, [1] [2];src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs, [3] [4];src/BlazorWebView/src/Maui/Windows/WinUIWebViewManager.cs, [5] [6] [7]Logging Improvements:
src/BlazorWebView/src/Maui/Android/WebKitWebViewClient.cs, [1];src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs, [2];src/BlazorWebView/src/Maui/Windows/WinUIWebViewManager.cs, [3]Test Coverage Expansion:
BlazorWebViewComponentTeststests interactions with Razor components. (src/BlazorWebView/tests/MauiDeviceTests/Elements/BlazorWebViewComponentTests.cs, src/BlazorWebView/tests/MauiDeviceTests/Elements/BlazorWebViewComponentTests.csR1-R59)BlazorWebViewLoggingTestsverifies that request logs are generated correctly. (src/BlazorWebView/tests/MauiDeviceTests/Elements/BlazorWebViewLoggingTests.cs, src/BlazorWebView/tests/MauiDeviceTests/Elements/BlazorWebViewLoggingTests.csR1-R59)BlazorWebViewNavigationTestsensures theStartPathproperty is respected during navigation. (src/BlazorWebView/tests/MauiDeviceTests/Elements/BlazorWebViewNavigationTests.cs, src/BlazorWebView/tests/MauiDeviceTests/Elements/BlazorWebViewNavigationTests.csR1-R42)Minor Updates:
src/BlazorWebView/src/Maui/Microsoft.AspNetCore.Components.WebView.Maui.csproj, src/BlazorWebView/src/Maui/Microsoft.AspNetCore.Components.WebView.Maui.csprojL36)usingdirectives to improve code clarity. (src/BlazorWebView/src/Maui/Android/WebKitWebViewClient.cs, [1];src/BlazorWebView/src/Maui/BlazorWebView.cs, [2];src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs, [3]These changes significantly enhance the extensibility and debugging capabilities of BlazorWebView while ensuring robust test coverage for the new features.