-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
I mentioned this briefly previously but I think it might be of value to have a .net side task that you could await for an object to be bound into existence. This can be partially accomplished with the nice ObjectBoundInJavascript event but as it doesn't fire if already bound it cannot be done as easily.
This may make it easier for people to move from the old binding to the new binding system if they only
use bound objects to exfil data from JS and not get results of methods.
It allows for something like:
helper = new Helper(browser);
browser.JavascriptObjectRepository.Register("Tester", new TestClass(), true, CefSharp.BindingOptions.DefaultBinder);
await helper.EnsureRegistered("Tester");
browser.ExecuteScriptAsync("Tester.test('hi there');");
Attached is a .net helper class that emulates the process that I could see being used. It has added complexity as we cannot tell from .net if an object is already bound (I guess could call EvaluateScriptAsync to test each window object). This could be resolved with another event handler of ObjectAlreadyBoundInJavascript called for any time bindobjectasync is called with an already bound object.
Let me know thoughts or if worthwhile. This helper works for me (and actually could be simplified to just wait for BindObjectAsync rather than resolving after each bound object). Part of the current flow is to show what would be possible with the additional event handler, just one line of code with no helper class bound into the JS namespace. It could be taken a step further with no JS injection if the bind call was possible from .net code.