-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[BlazorWebView] Implement web request interception #30016
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
Conversation
This also refactors the code a bit and disconnects it from the HybridWebView since the concept is a base idea.
There was a problem hiding this 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 PR implements web request interception for BlazorWebView by reusing the existing interception types from MAUI and updating various platform‐specific implementations. Key changes include making platform event argument constructors public, refactoring naming from HybridWebView to WebView, and extending web view interfaces to support request interception.
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/PublicAPI.targets | Commenting out the PublicApiAnalyzers PackageReference. |
| src/Core/src/Properties/AssemblyInfo.cs | Adding an InternalsVisibleTo attribute for ASP.NET Core Blazor integration. |
| src/Core/src/Primitives/WebResourceRequestedEventArgs.cs | Changing constructor access from internal to public for platform-specific event args. |
| src/Core/src/Platform/* | Updating web request interception methods across iOS, Android, and Windows. |
| src/Core/src/Core/IHybridWebView.cs | Extending IHybridWebView to implement IWebRequestInterceptingWebView. |
| src/Controls/src/Core/WebRequestInterceptingWebView/* | Renaming types to reflect the new WebView naming. |
| src/BlazorWebView/* | Adapting BlazorWebView handlers and related APIs to use the updated interception logic. |
| src/BlazorWebView/src/Maui/IBlazorWebView.cs | Extending IBlazorWebView to implement IWebRequestInterceptingWebView. |
Comments suppressed due to low confidence (5)
src/Core/src/Primitives/WebResourceRequestedEventArgs.cs:10
- Changing the accessibility of the constructor from 'internal' to 'public' in this platform-specific event args class is a breaking change. Please confirm that this change is intentional and documented.
public WebResourceRequestedEventArgs(global::Microsoft.Web.WebView2.Core.CoreWebView2 sender,
src/Core/src/Primitives/WebResourceRequestedEventArgs.cs:36
- Changing the constructor accessibility from 'internal' to 'public' for the iOS/MacCatalyst version represents a breaking API change. Please ensure this is clearly documented.
public WebResourceRequestedEventArgs(global::WebKit.WKWebView sender,
src/Core/src/Primitives/WebResourceRequestedEventArgs.cs:61
- Promoting the constructor from 'internal' to 'public' for the Android platform is a breaking change. Please verify that the corresponding documentation and clients are updated accordingly.
public WebResourceRequestedEventArgs(global::Android.Webkit.WebView sender,
src/Core/src/Core/IHybridWebView.cs:8
- Extending IHybridWebView to implement IWebRequestInterceptingWebView is a public API breaking change. Please ensure that this alteration is well documented for consumers of the API.
public interface IHybridWebView : IView, IWebRequestInterceptingWebView
src/BlazorWebView/src/Maui/IBlazorWebView.cs:11
- Having IBlazorWebView extend IWebRequestInterceptingWebView constitutes a breaking change in the public API. Please verify that any consumers are aware of this change.
public interface IBlazorWebView : IView, IWebRequestInterceptingWebView
rmarinho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems tests are failing
9ecbd07 to
213813f
Compare
Description of Change
This pull request introduces support for intercepting and handling web resource requests across multiple platforms in the Blazor WebView framework. The primary changes include adding new event hooks for request interception, enhancing logging for debugging purposes, and refactoring existing classes to support the new functionality. Below is a summary of the most significant changes, grouped by theme:
Web Resource Interception and Event Handling
Added a new
WebResourceRequestedevent to theBlazorWebViewandHybridWebViewcomponents, allowing applications to intercept web resource requests and provide custom responses. This includes setting theHandledproperty and invoking appropriate methods to define the response. (src/BlazorWebView/src/Maui/BlazorWebView.cs[1] [2];src/Controls/src/Core/HybridWebView/HybridWebView.cs[3]Updated the
IBlazorWebViewinterface to inherit fromIWebRequestInterceptingWebView, enabling web resource interception as part of the Blazor WebView contract. (src/BlazorWebView/src/Maui/IBlazorWebView.cssrc/BlazorWebView/src/Maui/IBlazorWebView.csL11-R11)Logging Enhancements
src/BlazorWebView/src/Maui/Android/WebKitWebViewClient.cs[1] [2];src/BlazorWebView/src/Maui/Windows/WinUIWebViewManager.cs[3] [4];src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs[5] [6]Platform-Specific Web Resource Handling
src/BlazorWebView/src/Maui/Android/WebKitWebViewClient.cs[1] [2];src/BlazorWebView/src/Maui/Windows/WinUIWebViewManager.cs[3] [4];src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs[5] [6]Refactoring and Renaming
PlatformHybridWebViewWebResourceRequestedEventArgstoPlatformWebViewWebResourceRequestedEventArgsto generalize its usage and align with the newWebResourceRequestedevent. Updated all references accordingly. (src/Controls/src/Core/WebRequestInterceptingWebView/PlatformWebViewWebResourceRequestedEventArgs.cs[1] [2] [3] [4] [5] [6]Miscellaneous
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 enhance the flexibility and extensibility of the Blazor WebView framework, enabling developers to customize how web resources are handled across different platforms.
Issues Fixed
Fixes #11382