KEMBAR78
[BlazorWebView] Implement web request interception by mattleibow · Pull Request #30037 · dotnet/maui · GitHub
Skip to content

Conversation

@mattleibow
Copy link
Member

@mattleibow mattleibow commented Jun 17, 2025

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

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:

  • 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 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)

PureWeen
PureWeen previously approved these changes Jun 20, 2025
@github-project-automation github-project-automation bot moved this from Todo to Approved in MAUI SDK Ongoing Jun 20, 2025
Copy link
Member

@rmarinho rmarinho left a comment

Choose a reason for hiding this comment

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

Failing tests not related.

@rmarinho rmarinho merged commit 700fd80 into net10.0 Jun 23, 2025
130 of 132 checks passed
@rmarinho rmarinho deleted the dev/blazorwebview-interception branch June 23, 2025 10:52
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Jun 23, 2025
@mattleibow mattleibow linked an issue Jun 24, 2025 that may be closed by this pull request
@github-actions github-actions bot locked and limited conversation to collaborators Jul 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Intercepting requests from BlazorWebView

3 participants