Skip to content

Conversation

davidortinau
Copy link
Contributor

@davidortinau davidortinau commented Aug 20, 2025

This PR adds .NET 10 guidance to customize initialization and access platform web views in HybridWebView.

Summary of changes:

  • Adds a new ">= net-maui-10.0" section "Customize initialization and access platform web views" to docs/user-interface/controls/hybridwebview.md.
  • Documents Windows MauiHybridWebView.RunAfterInitialize for safe access to CoreWebView2 after initialization.
  • Shows how to access and tweak the platform views on Android (android.webkit.WebView) and iOS/Mac Catalyst (WKWebView) after creation via HandlerChanged.
  • Includes an advanced custom handler example to provide a WKWebViewConfiguration at creation time when platform options must be set before the view is created.
  • Updates ms.date.

Motivation / verification:

  • HybridWebView does not expose app-facing initializing/initialized events like BlazorWebView. The recommended approach is to use platform view access and, on Windows, RunAfterInitialize.
  • Verified against MAUI net10 source (handlers for Windows/Android/iOS/macOS) and MauiHybridWebView helper.

Related upstream references:

Docs hygiene:

  • Moniker blocks are balanced.
  • Examples compile logically; no xref changes needed.

Once merged, I'll update the tracker entry to link to this PR and mark status accordingly.


Internal previews

📄 File 🔗 Preview link
docs/user-interface/controls/hybridwebview.md docs/user-interface/controls/hybridwebview

…on and platform view access; add Windows RunAfterInitialize guidance; custom handler example for WKWebViewConfiguration; update ms.date
@davidortinau davidortinau requested a review from a team as a code owner August 20, 2025 20:50
@davidortinau davidortinau requested a review from Copilot August 20, 2025 20:51
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 PR adds comprehensive .NET 10 documentation for customizing HybridWebView initialization and accessing platform-specific web views. It provides guidance for developers who need to configure the underlying web view components beyond the standard HybridWebView API.

Key changes:

  • Documents platform-specific access patterns for Windows (MauiHybridWebView), Android (WebView), and iOS/Mac Catalyst (WKWebView)
  • Provides code examples for post-initialization configuration using HandlerChanged events
  • Includes advanced custom handler approach for creation-time configuration requirements

Copy link

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

Copy link

Learn Build status updates of commit b414286:

⚠️ Validation status: warnings

File Status Preview URL Details
docs/user-interface/controls/hybridwebview.md ⚠️Warning View (>=net-maui-8.0) Details

docs/user-interface/controls/hybridwebview.md

  • Line 688, Column 44: [Warning: xref-not-found - See documentation] Cross reference not found: 'Microsoft.Maui.Platform.MauiHybridWebView'.

For more details, please refer to the build report.

Note: Your PR may contain errors or warnings or suggestions unrelated to the files you changed. This happens when external dependencies like GitHub alias, Microsoft alias, cross repo links are updated. Please use these instructions to resolve them.

@BethMassi
Copy link
Contributor

For the .NET 10 version of this article, we also need to remove the requirement that the hybridwebview.js file needs to be manually created. All you need to reference now in your web content is <script src="_framework/hybridwebview.js"></script> as this is now embedded.

I'm not sure how to structure the monikers in this doc to do this properly though.

Copy link

Learn Build status updates of commit 830c250:

✅ Validation status: passed

File Status Preview URL Details
docs/user-interface/controls/hybridwebview.md ✅Succeeded View (>=net-maui-8.0)

For more details, please refer to the build report.

Copy link

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

@BethMassi
Copy link
Contributor

@jfversluis perhaps something like this would work?

A simple app might have the following files and contents:
- Resources\Raw\wwwroot\index.html with content for the main UI:

        <!DOCTYPE html>
        <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta charset="utf-8" />
            <title></title>
            <link rel="icon" href="data:,">
            <link rel="stylesheet" href="styles/app.css">

::: moniker range="<=net-maui-9.0"
<script src="scripts/HybridWebView.js"></script>
::: moniker-end
::: moniker range=">=net-maui-10.0"
<script src="_framework/hybridwebview.js"></script>
::: moniker-end

rest of the index.html goes here....

Then for this section we just exclude it completely for .NET 10+:

::: moniker range="<=net-maui-9.0"

  • Resources\Raw\wwwroot\scripts\HybridWebView.js with the standard xref:Microsoft.Maui.Controls.HybridWebView JavaScript library:
        window.HybridWebView = {
            "Init": function Init() {
                function DispatchHybridWebViewMessage(message) {
                    const event = new CustomEvent("HybridWebViewMessageReceived", { detail: { message: message } });
                    window.dispatchEvent(event);
                }

rest of HybridWebView.js ....

::: moniker-end

Copy link

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

Copy link

Learn Build status updates of commit 189d78f:

✅ Validation status: passed

File Status Preview URL Details
docs/user-interface/controls/hybridwebview.md ✅Succeeded View (>=net-maui-8.0)

For more details, please refer to the build report.

Copy link

Learn Build status updates of commit c73c4d7:

✅ Validation status: passed

File Status Preview URL Details
docs/user-interface/controls/hybridwebview.md ✅Succeeded View (>=net-maui-8.0)

For more details, please refer to the build report.

Copy link

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

Copy link

Learn Build status updates of commit d8c318e:

✅ Validation status: passed

File Status Preview URL Details
docs/user-interface/controls/hybridwebview.md ✅Succeeded View (>=net-maui-8.0)

For more details, please refer to the build report.

Copy link

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

Copy link

Learn Build status updates of commit bffe936:

✅ Validation status: passed

File Status Preview URL Details
docs/user-interface/controls/hybridwebview.md ✅Succeeded View (>=net-maui-8.0)

For more details, please refer to the build report.

Copy link

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

Copy link

Learn Build status updates of commit 46bb2bc:

✅ Validation status: passed

File Status Preview URL Details
docs/user-interface/controls/hybridwebview.md ✅Succeeded View (>=net-maui-8.0)

For more details, please refer to the build report.

Updated HTML content for HybridWebView with new JavaScript functions for message logging and invoking C# methods. Adjusted script references for different .NET MAUI versions.
Copy link

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

Copy link

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

Copy link

Learn Build status updates of commit 9b31882:

✅ Validation status: passed

File Status Preview URL Details
docs/user-interface/controls/hybridwebview.md ✅Succeeded View (>=net-maui-8.0)

For more details, please refer to the build report.

@jfversluis jfversluis closed this Aug 28, 2025
@jfversluis jfversluis reopened this Aug 28, 2025
Copy link

Learn Build status updates of commit a9b7749:

✅ Validation status: passed

File Status Preview URL Details
docs/user-interface/controls/hybridwebview.md ✅Succeeded View (>=net-maui-8.0)

For more details, please refer to the build report.

Copy link

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

@jfversluis jfversluis merged commit d670022 into main Aug 28, 2025
8 checks passed
@jfversluis jfversluis deleted the pr11-hybridwebview-init-customization-net10-from-main branch August 28, 2025 10:53
Copy link

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

Copy link

Learn Build status updates of commit a9b7749:

✅ Validation status: passed

File Status Preview URL Details
docs/user-interface/controls/hybridwebview.md ✅Succeeded View (>=net-maui-8.0)

For more details, please refer to the build report.

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

Successfully merging this pull request may close these issues.

3 participants