Skip to content

Conversation

@mattleibow
Copy link
Member

@mattleibow mattleibow commented Jun 16, 2025

Description of Change

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

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 WebResourceRequested event to the BlazorWebView and HybridWebView components, allowing applications to intercept web resource requests and provide custom responses. This includes setting the Handled property 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 IBlazorWebView interface to inherit from IWebRequestInterceptingWebView, enabling web resource interception as part of the Blazor WebView contract. (src/BlazorWebView/src/Maui/IBlazorWebView.cs src/BlazorWebView/src/Maui/IBlazorWebView.csL11-R11)

Logging Enhancements

  • Introduced detailed logging in the web resource interception flow to aid debugging. Log messages are added to indicate when requests are intercepted, handled, or passed through unmodified. (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

  • Implemented platform-specific logic for intercepting and handling web resource requests on Android, iOS, and Windows. This includes checking if requests should be overridden, handling Blazor-specific resources, and falling back to default behavior if necessary. (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

  • Renamed PlatformHybridWebViewWebResourceRequestedEventArgs to PlatformWebViewWebResourceRequestedEventArgs to generalize its usage and align with the new WebResourceRequested event. Updated all references accordingly. (src/Controls/src/Core/WebRequestInterceptingWebView/PlatformWebViewWebResourceRequestedEventArgs.cs [1] [2] [3] [4] [5] [6]

Miscellaneous

  • Added missing namespace imports and minor adjustments to ensure compatibility with the new functionality. (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

This also refactors the code a bit and disconnects it from
the HybridWebView since the concept is a base idea.
Copilot AI review requested due to automatic review settings June 16, 2025 21:29
@mattleibow mattleibow requested a review from a team as a code owner June 16, 2025 21:29
@mattleibow mattleibow moved this from Todo to Ready To Review in MAUI SDK Ongoing Jun 16, 2025
@mattleibow mattleibow moved this from Ready To Review to In Progress in MAUI SDK Ongoing Jun 16, 2025
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 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

@mattleibow mattleibow added this to the .NET 10.0-preview6 milestone Jun 16, 2025
@mattleibow mattleibow self-assigned this Jun 16, 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.

Seems tests are failing

@github-project-automation github-project-automation bot moved this from In Progress to Changes Requested in MAUI SDK Ongoing Jun 17, 2025
@mattleibow mattleibow closed this Jun 17, 2025
@github-project-automation github-project-automation bot moved this from Changes Requested to Done in MAUI SDK Ongoing Jun 17, 2025
@mattleibow mattleibow force-pushed the dev/blazorwebview-interception branch from 9ecbd07 to 213813f Compare June 17, 2025 19:55
@github-actions github-actions bot locked and limited conversation to collaborators Jul 18, 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.

3 participants