Due to Chromium changes starting with 63.0.0 , significant changes to Javascript Binding occurring. Inherited behavior still works for Single Page Applications and where only one domain is used.
New binding method
The new binding method has many advantages:
- Snap and untie objects by name
- Link a subset of objects to various pages (including pop-ups)
- Delete / untie method
- Dynamically solves a related object
A simple example:
public class BoundObject { public void showMessage(string msg) { MessageBox.Show(msg); } } browser.JavascriptObjectRepository.Register("boundAsync", new BoundObject(), true);
<script type="text/javascript"> (async function() { await CefSharp.BindObjectAsync("boundAsync", "bound"); boundAsync.showMessage('Message from JS'); })(); </script>
See Javascript Binding v2 # 2246 and How do you show the .NET class for JavaScript?
Outdated binding
If you perform cross-site navigation, you can no longer use this method to snap objects.
You need to set CefSharpSettings.LegacyJavascriptBindingEnabled = true before registering your first object ( RegisterAsyncJsObject ).
A simple example:
public class BoundObject { public void showMessage(string msg) { MessageBox.Show(msg); } } CefSharpSettings.LegacyJavascriptBindingEnabled = true; browser.RegisterAsyncJsObject("boundAsync", new BoundAsyncObject());
<script type="text/javascript"> boundAsync.showMessage('Message from JS'); </script>
See Javascript Binding v2 # 2246 and How do you show the .NET class for JavaScript?
Oleg Markelov
source share