I tried using JavascriptMessageReceived event in c# to handle CefSharp.PostMessage called from JS within the browser. I even downloaded an example of this working from link. Ran example which was supposed to do exactly what I needed, but it didn't work, nor does my code (below). Did CefSharp remove this functionality or change it? Do I need to enable this feature within the CefSettings or ChromiumWebBrowser?
using CefSharp;
using CefSharp.WinForms;
public ChromiumWebBrowser chromeBrowser;
public Form1()
{
InitializeComponent();
string curDir = Directory.GetCurrentDirectory();
CefSettings settings = new CefSettings();
Cef.Initialize(settings);
chromeBrowser = new ChromiumWebBrowser(String.Format("file:///{0}/HelloWorld.html", curDir));
chromeBrowser.JavascriptMessageReceived += ChromeBrowser_JavascriptMessageReceived;
}
private void ChromeBrowser_JavascriptMessageReceived(object sender, JavascriptMessageReceivedEventArgs e)
{
MessageBox.Show((string)e.Message);
}
HelloWorld.html here
<!DOCTYPE html>
<html>
<body>
<script>
CefSharp.PostMessage("Hello world!");
</script>
</body>
</html>