Search code examples
c#.netawesomium

How to get Awesomium's scroll offset?


How can I get the current horizontal and vertical scroll offset of the Web view (showing an arbitrary website)?

I want to save the UI layout and need the offset to be able to restore the viewport position after restarting my application. I´m using WebControl (WPF) with the latest Awesomium.


Solution

  • I found the solution!

    Awesomium does not handle anything scroll-related. It´s done by the underlying WebKit. Therefore, I have to use JavaScript to obtain the information:

    var xoffset = webControl.ExecuteJavascriptWithResult("window.pageXOffset");
    var yoffset = webControl.ExecuteJavascriptWithResult("window.pageYOffset");
    

    And with

    webControl.ExecuteJavascript("window.scrollTo(x, y);");
    

    I can apply a scroll offset to the view.