Native Browser interop
Overview
The Avalonia WebView component provides cross-platform web content rendering capabilities by utilizing native platform web view. However, sometimes you need to access platform-specific APIs that aren't exposed through the Avalonia WebView abstraction layer.
This document explains how to obtain native handles and perform interop with the underlying browser implementations on each supported platform.
Getting handle
To access native browser functionality, you first need to obtain the platform-specific handle from your WebView control.
For WebView Controls
Use the TryGetPlatformHandle() method on your WebView instance:
if (myWebView.TryGetPlatformHandle() is IWindowsWebView2PlatformHandle handle)
{
// Cast to platform-specific interface and use
}
For WebView Dialogs
Use the TryGetWebViewPlatformHandle() method on your WebView dialog instance:
if (myWebViewDialog.TryGetWebViewPlatformHandle() is IWindowsWebView2PlatformHandle handle)
{
// Cast to platform-specific interface and use
}