|
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; }
|
|
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!
|
|
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.
|
|
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.
|
|
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?
|
|
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!
|
|