Skip to content

[BlazorWebView] Implement web request interception #30037

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

Open
wants to merge 28 commits into
base: net10.0
Choose a base branch
from

Conversation

mattleibow
Copy link
Member

@mattleibow mattleibow commented Jun 17, 2025

This is the same work as #28876, but for BlazorWebView.

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:

  • Added the WebResourceRequested event to BlazorWebView, enabling applications to intercept and handle web resource requests. This includes methods for setting custom responses. (src/BlazorWebView/src/Maui/BlazorWebView.cs, [1] [2]
  • Updated IBlazorWebView to implement the IWebRequestInterceptingWebView interface, supporting request interception. (src/BlazorWebView/src/Maui/IBlazorWebView.cs, src/BlazorWebView/src/Maui/IBlazorWebView.csL11-R11)
  • Enhanced platform-specific implementations (Android, iOS, Windows) to handle intercepted requests by checking if the app wants to override them, processing Blazor-specific resources, or letting the request proceed as usual. (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:

  • Introduced detailed logging for intercepted requests, including debug messages for handling, modifying, or bypassing requests. (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:

Minor Updates:

  • Removed an unused file reference from the project file. (src/BlazorWebView/src/Maui/Microsoft.AspNetCore.Components.WebView.Maui.csproj, src/BlazorWebView/src/Maui/Microsoft.AspNetCore.Components.WebView.Maui.csprojL36)
  • Added missing using directives 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.

This also refactors the code a bit and disconnects it from
the HybridWebView since the concept is a base idea.
@mattleibow mattleibow added this to the .NET 10.0-preview6 milestone Jun 17, 2025
@Copilot Copilot AI review requested due to automatic review settings June 17, 2025 19:58
@mattleibow mattleibow requested a review from a team as a code owner June 17, 2025 19:58
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

1 participant