Thanks in advance.
I am unable to communicate from JavaScript code to the WebView2 control embedded in WPF application as I am seeing errors like - 'Access is denied', 'Promise Pending' etc. I am not sure what is wrong as everything seems to be correct here.
Here is my piece of code:
The COM Object:
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class NativeMethods
{
public string SendMessage(string message)
{
return message;
}
}
The WPF User Control that contains WebView2
public partial class WebView2Control : UserControl
{
public WebView2Control()
{
InitializeAsync();
}
async void InitializeAsync()
{
await webView.EnsureCoreWebView2Async(null);
WebView_CoreWebView2Ready();
}
private void WebView_CoreWebView2Ready()
{
webView.CoreWebView2.AddHostObjectToScript("nativeMethods", new NativeMethods());
}
}