Welcome Guest Search | Active Topics | Sign In | Register

QueueScriptCall going async stops honest values being returned Options
Panda
Posted: Monday, October 17, 2016 7:03:51 PM
Rank: Advanced Member
Groups: Member

Joined: 10/7/2015
Posts: 35
Hi, here's the code I've had to write to get around the changes to QueueScriptCall being async - changed a few months ago (I can check version if necessary)

It's well commented and it works where it stopped working.
Do you agree or did you realize the need for this when making the changes.

I just wanted to check you'd be aware of it and share.

public int ScrollLeft
{
// Just returning the value from the browser would be logical/easy...
// But this stopped working in a recent EO release - likely due to QueueScriptCall forced to always be async
// So now, it would not always return the current setting, if it was recently set by us (eg set to 100, get value = 0)
// So here we now memoize it to ensure we get the value that we've most recently set it to
// We don't always use the memoized value, because the case in which the scroll bar is positioned by the user ie via the UI
// requires the retrieved value, not memoized (because none was set to be memoized in this case)
// Hence the check for the actual value before resorting to memoized value
// Same principle for ScrollTop
get
{
var browserLeft = _browser.EvalScript("$(document).scrollLeft()").Int();
return browserLeft == 0 ? _lastScrollLeft : browserLeft;
}
set
{
_browser.QueueScriptCall($"$(document).scrollLeft({value})");
_lastScrollLeft = value;
}
eo_support
Posted: Tuesday, October 18, 2016 8:25:10 AM
Rank: Administration
Groups: Administration

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

Your code seems to be fine. Can you explain which part is not working as expected?

Thanks!
Panda
Posted: Tuesday, October 18, 2016 6:39:06 PM
Rank: Advanced Member
Groups: Member

Joined: 10/7/2015
Posts: 35
Thanks, I mean this code is working fine ;-)

I just wanted to point out that before the changes to async QueueScriptCall , a few months ago I didn't need any of this "memoizing" code, it used to work like this, with 1 line each:

Where the containing class is just a wrapper around your WebView object:

public int ScrollLeft {
get { return _browser.EvalScript("$(document).scrollLeft()").Int(); }
set { _browser.QueueScriptCall($"$(document).scrollLeft({value})") }
}

Anyone who uses the browser in a similar way to us, would have experienced a bug after the async changes - fixed by memozing values and not relying on what the WebView is returning, which is sometimes WRONG if it hasn't had enough time to effect the changes.
eo_support
Posted: Wednesday, October 19, 2016 8:17:21 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,225
Thanks for sharing. QueueScriptCall is always intended to be asynchronous, so you should never assume the code has already executed when QueueScriptCall returns. The difference between older builds and the current build is in older build QueueScriptCall will send the script to the browser engine immediately if the browser engine is ready to receive script, in order to do so it needs to hold an internal lock and if used improperly can cause deadlock. However in the newer build it never does that and always return immediately in order to minimize the lock time thus avoid the potential deadlock.
Panda
Posted: Sunday, August 6, 2017 11:24:53 PM
Rank: Advanced Member
Groups: Member

Joined: 10/7/2015
Posts: 35
Hi Actually I must come back to this as I don't think it's fully understood.
The problem is that even this code -> _browser.EvalScript("$(document).scrollLeft()").Int();
Does not return the current value of the scroll bars.

I can set this _browser.QueueScriptCall($"$(document).scrollLeft(100)");
And then any amount of time later, the above code still returns 0 not 100.

My workaround code above, is not quite right and is now giving me a different bug

So I'm absolutely stuck here with EO not being able to provide me reliable scroll position values, ever.

Is there any other way to get the current Scroll position from EO browser without relying on very unreliable javascript script insertions?
eo_support
Posted: Monday, August 7, 2017 9:42:18 AM
Rank: Administration
Groups: Administration

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

You can use the DevTool's console panel to evaluate document.body.scrollLeft and see if you get the right value. If your page is indeed scrolled and you don't get the correct value with that property, then you can try to isolate the problem into a test project and send the test project to us and we will be happy to investigate further.

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.