<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Cefsharp browser JavaScript Binding not working in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/cefsharp-browser-javascript-binding-not-working/m-p/9894386#M30146</link>
    <description>&lt;P&gt;Hello Forum,&lt;/P&gt;&lt;P&gt;For the current addin I am developing I have implemented a CefSharp browser inside of a DockableDialog loading a local .html page. Currently I am trying to bind a .Net class and call its functions from the Webpage via JavaScript Binding of CefSharp (&lt;A href="https://github.com/cefsharp/cefsharp/issues/2246" target="_blank"&gt;https://github.com/cefsharp/cefsharp/issues/2246&lt;/A&gt;). But I have run into the following issues:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;When trying to bind the object via CefSharp.BindObjectAsync() from the Webpage it won't bind the object at all.&lt;/LI&gt;&lt;LI&gt;When trying to bind the object via&amp;nbsp;browser.ExecuteScriptAsync("CefSharp.BindObjectAsync();") it will bind the object but I am unable to call its functions afterwards.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;This is the code I have:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Binding the object in JS and calling the showMessage function on button click:&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="javascript"&gt;function CallAddin()
{
	(async function()
	{
		console.log("HERE");
		await CefSharp.BindObjectAsync("bound");
		bound.showMessage();
	})();
}&lt;/LI-CODE&gt;&lt;UL&gt;&lt;LI&gt;Resolve the binding of the object and check if successfully bound in C#:&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="csharp"&gt;browser = new ChromiumWebBrowser(); browser.JavascriptObjectRepository.ResolveObject += (sender, e) =&amp;gt; 
{ 
    var repo = e.ObjectRepository; 
    if (e.ObjectName == "bound") 
    { 
        repo.Register("bound", new Translate(), isAsync: true, options: new BindingOptions()); 
    } 
}; 
browser.JavascriptObjectRepository.ObjectBoundInJavascript += (sender, e) =&amp;gt; 
{ 
    var name = e.ObjectName; 
    TaskDialog.Show("Info", "Successfully bound object"); 
};&lt;/LI-CODE&gt;&lt;UL&gt;&lt;LI&gt;&amp;nbsp;The class to bind to the Webpage:&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="csharp"&gt;class Translate
{
    public void ShowMessage()
    {
        TaskDialog.Show("Info", "This was called from the Webpage");
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I use:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Revit2020&lt;/LI&gt;&lt;LI&gt;CefSharp 65.0.1&lt;/LI&gt;&lt;LI&gt;.NET Framework 4.7.2&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
    <pubDate>Wed, 25 Nov 2020 10:31:53 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-11-25T10:31:53Z</dc:date>
    <item>
      <title>Cefsharp browser JavaScript Binding not working</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/cefsharp-browser-javascript-binding-not-working/m-p/9894386#M30146</link>
      <description>&lt;P&gt;Hello Forum,&lt;/P&gt;&lt;P&gt;For the current addin I am developing I have implemented a CefSharp browser inside of a DockableDialog loading a local .html page. Currently I am trying to bind a .Net class and call its functions from the Webpage via JavaScript Binding of CefSharp (&lt;A href="https://github.com/cefsharp/cefsharp/issues/2246" target="_blank"&gt;https://github.com/cefsharp/cefsharp/issues/2246&lt;/A&gt;). But I have run into the following issues:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;When trying to bind the object via CefSharp.BindObjectAsync() from the Webpage it won't bind the object at all.&lt;/LI&gt;&lt;LI&gt;When trying to bind the object via&amp;nbsp;browser.ExecuteScriptAsync("CefSharp.BindObjectAsync();") it will bind the object but I am unable to call its functions afterwards.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;This is the code I have:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Binding the object in JS and calling the showMessage function on button click:&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="javascript"&gt;function CallAddin()
{
	(async function()
	{
		console.log("HERE");
		await CefSharp.BindObjectAsync("bound");
		bound.showMessage();
	})();
}&lt;/LI-CODE&gt;&lt;UL&gt;&lt;LI&gt;Resolve the binding of the object and check if successfully bound in C#:&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="csharp"&gt;browser = new ChromiumWebBrowser(); browser.JavascriptObjectRepository.ResolveObject += (sender, e) =&amp;gt; 
{ 
    var repo = e.ObjectRepository; 
    if (e.ObjectName == "bound") 
    { 
        repo.Register("bound", new Translate(), isAsync: true, options: new BindingOptions()); 
    } 
}; 
browser.JavascriptObjectRepository.ObjectBoundInJavascript += (sender, e) =&amp;gt; 
{ 
    var name = e.ObjectName; 
    TaskDialog.Show("Info", "Successfully bound object"); 
};&lt;/LI-CODE&gt;&lt;UL&gt;&lt;LI&gt;&amp;nbsp;The class to bind to the Webpage:&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="csharp"&gt;class Translate
{
    public void ShowMessage()
    {
        TaskDialog.Show("Info", "This was called from the Webpage");
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I use:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Revit2020&lt;/LI&gt;&lt;LI&gt;CefSharp 65.0.1&lt;/LI&gt;&lt;LI&gt;.NET Framework 4.7.2&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 10:31:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/cefsharp-browser-javascript-binding-not-working/m-p/9894386#M30146</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-11-25T10:31:53Z</dc:date>
    </item>
  </channel>
</rss>

