Antwise community forums
VB6: RunAnonymousFunctionSync to retrieve the height of page - Printable Version

+- Antwise community forums (https://forums.antwise.com)
+-- Forum: Antview (https://forums.antwise.com/forumdisplay.php?fid=11)
+--- Forum: Antview for Windows (https://forums.antwise.com/forumdisplay.php?fid=12)
+--- Thread: VB6: RunAnonymousFunctionSync to retrieve the height of page (/showthread.php?tid=169)



VB6: RunAnonymousFunctionSync to retrieve the height of page - MrPrzemek - 2023-10-01

Hi. I try to retrieve the height of the scroll bar of a page that is fully loaded to AntView

I use bellow vb6 code

Code:
Set myDocumentHTML = New AntViewDocument
myDocumentHTML.BrowserDispatch wbEdge.IDispatchPointer

Dim strRes As String
Dim intRes As Integer

intRes = myDocumentHTML.RunAnonymousFunctionSync(1, "", "window.innerHeight;", strRes) 

Debug.Print "Result: " & intRes '22 functon timeout
Debug.Print "Data result: " & strRes 'String is empty

Unfortunately, I do not manage to get a result. All the time, the function returns the value 22 which means timeout

Can you point out how to retrieve the height of the loaded page?

To scroll the page I use this function

Code:
 wbEdge.ExecuteScript "window.scrollTo(0,0);"

and it works very well but I can't get the height of the page

Best regards Przemek


RE: VB6: RunAnonymousFunctionSync to retrieve the height of page - wila - 2023-10-01

Hi Przemek,

The following works for me:
Code:
  Set myDocumentHTML = New AntViewDocument
  myDocumentHTML.BrowserDispatch EdgeWebBrowser.IDispatchPointer

  Dim strRes As String
  Dim intRes As Integer

  intRes = myDocumentHTML.RunAnonymousFunctionSync(1, "", "() => {return window.innerHeight;}", strRes)

  Debug.Print "Result: " & intRes '22 functon timeout
  Debug.Print "Data result: " & strRes 'String is empty

IOW, you did not write a function.
Sadly it does not completely behave like the javascript console.

The returned error 22 is confusing. I will raise a ticket for that and see if it can be improved somehow.
--
Wil


RE: VB6: RunAnonymousFunctionSync to retrieve the height of page - MrPrzemek - 2023-10-02

(2023-10-01, 16:16:24)wila Wrote: Hi Przemek,

The following works for me:
Code:
  Set myDocumentHTML = New AntViewDocument
  myDocumentHTML.BrowserDispatch EdgeWebBrowser.IDispatchPointer

  Dim strRes As String
  Dim intRes As Integer

  intRes = myDocumentHTML.RunAnonymousFunctionSync(1, "", "() => {return window.innerHeight;}", strRes)

  Debug.Print "Result: " & intRes '22 functon timeout
  Debug.Print "Data result: " & strRes 'String is empty

IOW, you did not write a function.
Sadly it does not completely behave like the javascript console.

The returned error 22 is confusing. I will raise a ticket for that and see if it can be improved somehow.
--
Wil

It works for me also :-) Thank you very much for your reply


In the future, you might consider adding a property to scroll and get the height/width of the scroll bar

Code:
antView.Document.ScrollHeight - Returns the height of the page's scroll bar
antView.Document.ScrollWidth - Returns the Width of the page's scroll bar
antView.Document.ScrollTop - Scrolls the vertical bar to the position X
antView.Document.ScrollLeft - Scrolls the horizontal bar to the position X