davidortinau/maui-skills/maui-hybridwebview
Claude Code and agent skill by davidortinau/maui-skills
- community
Checking that the SKILL.md file is still in the repository.
Guidance for embedding web content in .NET MAUI apps using HybridWebView, including JavaScript–C# interop, bidirectional communication, raw messaging, and trimming/NativeAOT considerations. USE FOR: "HybridWebView", "JavaScript interop", "embed web content", "JS to C# interop", "C# to JavaScript", "web view interop", "raw message", "InvokeJavaScriptAsync", "web content MAUI". DO NOT USE FOR: deep linking from external URLs (use maui-deep-linking), REST API calls (use maui-rest-api), or Blazor Hybrid apps (different from HybridWebView).
Install
npx vskill@latest install davidortinau/maui-skills/maui-hybridwebviewSKILL.md
HybridWebView in .NET MAUI
HybridWebView hosts HTML/JS/CSS content inside a .NET MAUI app with bidirectional C#↔JS communication. It is not a general browser control — it is designed for local web content shipped with the app.
Common gotchas
| Issue | Fix | |
|---|---|---|
| Blank white screen | Web assets missing from Resources/Raw/wwwroot or DefaultFile not set | |
| JS interop silently fails | Missing <script src="_hwv/HybridWebView.js"></script> in HTML | |
InvokeJavaScriptAsync returns null | Return type missing [JsonSerializable] attribute in JsonSerializerContext | |
| JS → C# calls do nothing | SetInvokeJavaScriptTarget not called before JS invokes C# methods | |
| Serialization crash with trimming | Not using source-generated JsonSerializerContext |
⚠️ Bridge script is mandatory
The HTML page must include the bridge script before any app scripts:
JSON serialization — every type must be registered
Every parameter type and return type used in InvokeJavaScriptAsync must have a [JsonSerializable] entry:
Rule: When you add a new type to the interop surface, you must add a[JsonSerializable(typeof(T))]attribute to the context. Forgetting this is the #1 cause of mysterious interop failures.
SetInvokeJavaScriptTarget — timing matters
⚠️ Call SetInvokeJavaScriptTarget during page construction or OnAppearing, not lazily.
Exception handling (.NET 9+)
JS exceptions thrown during InvokeJavaScriptAsync are forwarded to .NET. Always wrap interop calls:
Trimming / NativeAOT pitfalls
Trimming is disabled by default in MAUI projects. If you enable it:
- ⚠️ You must use source-generated
JsonSerializerContext(not reflection-based serialization) - ⚠️ Set
JsonSerializerIsReflectionEnabledByDefaulttofalse - Using
JsonSerializerContextas shown above is recommended regardless of trimming settings
Decision framework — typed interop vs raw messages
| Need | Use | |
|---|---|---|
| Structured data exchange with type safety | InvokeJavaScriptAsync / InvokeDotNet with JsonSerializerContext | |
| Simple string payloads, fire-and-forget | SendRawMessage / RawMessageReceived | |
| Calling C# from JS with return values | InvokeDotNet (target must be set first) | |
| Multiple JS functions to call | Typed interop — one InvokeJavaScriptAsync per function |
Quick checklist
- [ ] Web content is under
Resources/Raw/wwwroot - [ ]
index.htmlincludes<script src="_hwv/HybridWebView.js"></script>before app scripts - [ ]
DefaultFileis set (or defaults toindex.html) - [ ] Every interop type has a
[JsonSerializable]entry in aJsonSerializerContext - [ ]
SetInvokeJavaScriptTargetis called before JS invokes C# methods - [ ]
InvokeJavaScriptAsynccalls are wrapped in try/catch (.NET 9+) - [ ] If trimming enabled: source-generated JSON serialization configured
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingplugins/maui-skills/skills/maui-hybridwebview/SKILL.md
Popularity
- Repository stars
- 103
- Repository forks
- 15
- 7-day trend score
- 23
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 1 Apr 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/davidortinau/maui-skills/maui-hybridwebview)