Welcome Guest Search | Active Topics | Sign In | Register

ObjectForScripting stoped working in version 20.1.45.0 with JSObject Options
Desenvolvimento
Posted: Tuesday, May 19, 2020 9:50:51 AM
Rank: Member
Groups: Member

Joined: 11/27/2018
Posts: 10
Hi

I have been using EO.Webbroser version 18.3.46.0 so far and everthing worked as expected with ObjectForScripting.
Now, i have upgraded to 20.1.45.0 and all of my methods that takes a JSObject as a parameter have stopped working.

JSObject is always receveid without properties.
I was looking at the changelog and the fix below seems to be the problem

Added code to automatically maintain reference on JavaScript objects passed from the browser engine to the .NET side;

Maybe the reference is gone when transition to unmanaged to managed code, i dont know. just sppeculating

can you help me with this?

thanks.
eo_support
Posted: Tuesday, May 19, 2020 12:49:53 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

This is a known restriction introduced in an earlier build, not specifically in 20.1.45.0. The new restriction does not allow re-entering JavaScript engine. This is necessary because the JavaScript engine can not be re-entered by design and early versions of EO.WebBrowser does not enforce this and allow it to be re-entered thus can cause all kind of problems. As a result, the new version no longer allows this.

The following code explains what re-entering is and why it is not allowed for JavaScript:

Code: JavaScript
var i = 0;
alert("hi");
console.log("i=" + i);


In any circumstance, the above code should print "i=0".

However consider in EO.WebBrowser where you can handle WebView.JSDialog to respond the JavaScript "alert" call. If you have the following code in WebView.JSDialog event hanlder:

Code: C#
webView.EvalScript("i=1;");


Then variable "i" will be changed when "alert" returns. This should not be allowed.

When you try to access a JSObject's property inside one of your ObjectForScripting function, it is similar to calling EvalScript in JSDialog handler (because it must go back to the JavaScript engine to ask for the properly value). This is no longer allowed.

In your case, this basically means you can no longer pass JSObject as arguments to your ObjectForScripting functions. You can change them to pass simple values such as string and integer, or an array of them. But you can no longer pass complex objects. Returning complex object from JavaScript to .NET side is still allowed since it does not violate the re-entering rule.

Hope this helps. Please feel free to let us know if you still have any questions.

Thanks!

Desenvolvimento
Posted: Tuesday, May 19, 2020 3:46:44 PM
Rank: Member
Groups: Member

Joined: 11/27/2018
Posts: 10
Hi

Thank you very much for the perfect explanation.
Now that I understand what happens, I changed the code and it worked again.

When my net function is called, instead of calling the jsobject property directly, generating a re-entering, I post a method invoker in the thread queue using control.begininvoke and it worked.

Do you see any problems using it that way?

thanks
eo_support
Posted: Tuesday, May 19, 2020 4:21:35 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Yes. This would work. As long as you avoid the re-entering issue.
Desenvolvimento
Posted: Tuesday, May 19, 2020 4:47:16 PM
Rank: Member
Groups: Member

Joined: 11/27/2018
Posts: 10
thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.