maui-hybridwebview

Enable bidirectional JavaScript-C# communication for local web content in .NET MAUI apps.

Updated Nov 27, 2025
One-click install
npx skills add https://github.com/seydakaratekeli/KamPay3 --skill maui-hybridwebview-seydakaratekeli
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: maui-hybridwebview
Source: https://github.com/seydakaratekeli/KamPay3/tree/main/KamPay/.github/skills/maui-hybridwebview%20-%20Kopyala
Command: npx skills add https://github.com/seydakaratekeli/KamPay3 --skill maui-hybridwebview-seydakaratekeli

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Enables .NET MAUI apps to host local HTML/JS/CSS content with robust bidirectional communication between JavaScript and C#, avoiding silent failures, lost calls, and serialization issues.

Core Features & Use Cases

  • Bridge script ordering: Ensures the required bridge script is included before any app scripts to prevent interop failures.
  • Typed interop and raw messaging: Covers when to use InvokeJavaScriptAsync with source-generated JsonSerializerContext versus SendRawMessage for simple payloads.
  • Trimming and NativeAOT guidance: Explains requirements for source-generated JSON serialization and publish settings to avoid runtime serialization issues.
  • Runtime safety: Advises on SetInvokeJavaScriptTarget timing and wrapping interop calls to capture JS exceptions.

Quick Start

Load your local index.html with the bridge script included before app scripts, register all interop types in a JsonSerializerContext, call SetInvokeJavaScriptTarget before the page runs, and wrap InvokeJavaScriptAsync calls in try/catch to surface JS errors.

Frequently Asked Questions about maui-hybridwebview

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up JavaScript C# interop in a .NET MAUI HybridWebView?

To set up JavaScript C# interop in .NET MAUI, load your local HTML with the bridge script included before app scripts, register interop types in a JsonSerializerContext, and call SetInvokeJavaScriptTarget before the page runs to prevent silent failures.

Why are my JavaScript interop calls failing silently in MAUI HybridWebView?

JavaScript interop calls fail silently when the required HybridWebView bridge script is not included before app scripts, or when SetInvokeJavaScriptTarget is not called before the page runs, losing unregistered invocations.

What is the difference between InvokeJavaScriptAsync and SendRawMessage in MAUI?

InvokeJavaScriptAsync uses source-generated JsonSerializerContext for typed interop calls, while SendRawMessage handles simple string payloads without serialization overhead, making it suitable for basic raw messaging between C# and JavaScript.

Does .NET MAUI HybridWebView work with Trimming and NativeAOT publishing?

Yes, HybridWebView works with Trimming and NativeAOT by requiring source-generated JsonSerializerContext entries for every interop type and proper publish settings to prevent runtime JSON serialization failures.

How do I catch JavaScript exceptions when calling InvokeJavaScriptAsync from C#?

To catch JavaScript exceptions from C#, wrap InvokeJavaScriptAsync calls in try/catch blocks, which surfaces JS errors directly in your C# code and avoids silent runtime failures during interop execution.