Welcome Guest Search | Active Topics | Sign In | Register

Something has changed with document.body.scrollTop Options
DylanT
Posted: Tuesday, June 5, 2018 9:56:30 PM
Rank: Member
Groups: Member

Joined: 6/5/2018
Posts: 14
We were employing a method in our code to allow our blind users to upload files via various websites by clicking the file upload button for them. In order to do this, we needed to locate the button within the browser window.

We were using EO.WebBrowser.Wpf version 17.3.13.0

The following Javascript code was being used within the page to determine the control location:
Code: JavaScript
function GetElementPos(psXPath) {
    try {
        var els = document.evaluate(psXPath, document, null, XPathResult.ANY_TYPE, null);
        if (els == null) return "NotFound";
        var el = els.iterateNext();
        if (el == null) return "NotFound";

        el.scrollIntoView();

        var rect = el.getBoundingClientRect();
        var ttop = rect.top + window.scrollY - document.body.scrollTop;
        var tleft = rect.left + window.scrollX - document.body.scrollLeft;
        console.log("rect.top: " +
            rect.top +
            " window.scrollY: " +
            window.scrollY +
            " document.body.scrollTop: " +
            document.body.scrollTop +
            " ttop: " +
            ttop);

        return "OK," + tleft + "," + ttop + "," + rect.width + "," + rect.height;
    }
    catch (ex) {
        console.log("** ERROR " + Date.now.toLocaleString() + " (KiraGetElementPos) " + ex.message);
        return ex.message;
    }
}


When we run the above code using version 17.3.13.0 we got the following console output:
rect.top: 0 window.scrollY: 467 document.body.scrollTop: 467 ttop: 0

When we upgrade to version 18.1.75.0 we get the following output:
rect.top: 0 window.scrollY: 467 document.body.scrollTop: 0 ttop: 467

And as a result, we are clicking in the wrong place.

Note that document.body.scrollTop is now returning 0 instead of 467.

Question: Is this a bug in the new version of EO.Browser? We have had to work around it, but if it were to change back in the future our software will break again.

Question: If this is a bug, is there a prior version of EO.Browser 2018 that doesn't have this problem?

eo_support
Posted: Wednesday, June 6, 2018 8:37:52 AM
Rank: Administration
Groups: Administration

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

We do not do anything special about document.body.scrollTopor any other regular JavaScript programming interface ---- those come as is with the Chromium browser engine. It is possible that different versions of the Chromium browser engine has different implementations (or even bugs) on certain JavaScript interface. In that case those differences will be carried over to different version of EO.WebBrowser product. We neither investigate nor track such differences. The best way for you to resolve such issues is to debug your page with the latest Google Chrome browser since our goal is to be as close to the official current Chrome browser as possible.

Thanks!
DylanT
Posted: Thursday, June 7, 2018 12:58:19 AM
Rank: Member
Groups: Member

Joined: 6/5/2018
Posts: 14
This is indeed a problem with a deprecated javascript method.

For the reference of anyone else who might have this issue, I replaced the code with the following to fix it. (This version is both backward and forward compatible.)

Code: C#
var st = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;


eo_support
Posted: Thursday, June 7, 2018 9:23:41 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,258
Glad to hear that you found out the root cause. Thanks for sharing!


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.