diff --git a/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs b/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs index 6668d014a..5e471525f 100644 --- a/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs +++ b/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs @@ -25,13 +25,37 @@ namespace CefSharp.Wpf.Example.Views InitializeComponent(); browser.RequestHandler = new RequestHandler(); - browser.JavascriptObjectRepository.Register("bound", new BoundObject(), isAsync:false, options: BindingOptions.DefaultBinder); + + //See https://github.com/cefsharp/CefSharp/issues/2246 for details on the two different binding options + if(CefSharpSettings.LegacyJavascriptBindingEnabled) + { + browser.RegisterJsObject("bound", new BoundObject(), options: BindingOptions.DefaultBinder); + } + else + { + //Register the new way + browser.JavascriptObjectRepository.Register("bound", new BoundObject(), isAsync:false, options: BindingOptions.DefaultBinder); + } + var bindingOptions = new BindingOptions() { Binder = BindingOptions.DefaultBinder.Binder, MethodInterceptor = new MethodInterceptorLogger() // intercept .net methods calls from js and log it }; - browser.JavascriptObjectRepository.Register("boundAsync", new AsyncBoundObject(), isAsync: true, options: bindingOptions); + + //See https://github.com/cefsharp/CefSharp/issues/2246 for details on the two different binding options + if(CefSharpSettings.LegacyJavascriptBindingEnabled) + { + browser.RegisterAsyncJsObject("boundAsync", new AsyncBoundObject(), options: bindingOptions); + } + else + { + //Register the new way + browser.JavascriptObjectRepository.Register("boundAsync", new AsyncBoundObject(), isAsync: true, options: bindingOptions); + } + + //If you call CefSharp.BindObjectAsync in javascript and pass in the name of an object which is not yet + //bound, then ResolveObject will be called, you can then register it browser.JavascriptObjectRepository.ResolveObject += (sender, e) => { var repo = e.ObjectRepository;