Page 1 of 3

Help about TWebView class. reading something from website.

Posted: Wed Jun 29, 2022 7:45 pm
by Horizon
Hi,

I have read this result in DevTools console.

Code: Select all | Expand

document.getElementById("dosya_listesi_result")


Result

Code: Select all | Expand

<tbody id="dosya_listesi_result">
    <tr role="row" class="odd">
        <td>Sanık</td>
        <td>Erzurum Bölge Adliye Mahkemesi 6. Ceza Dairesi</td>
        <td>2022/487</td>
        <td>Ceza Dava Dosyası</td>
        <td data-order="1654865877000" class="sorting_1">10.06.2022 15:57:57</td>
        <td>Açık</td>
        <td>
            <button class="btn btn-default btn-sm pull-left" onclick="javascript&#058; void(0);">
                <i class="fa fa-eyes"></i> Dosya Görüntüle</button>
        </td>
    </tr>
    <tr role="row" class="even">
        <td>Sanık</td>
        <td>Erzurum Bölge Adliye Mahkemesi 6. Ceza Dairesi</td>
        <td>2022/348</td>
        <td>Ceza Dava Dosyası</td>
        <td data-order="1650025383000" class="sorting_1">15.04.2022 15:23:03</td>
        <td>Kapalı ( 16.05.2022 11:26:22 )</td>
        <td>
            <button class="btn btn-default btn-sm pull-left" onclick="javascript&#058; void(0);">
                <i class="fa fa-eyes"></i> Dosya Görüntüle</button>
        </td>
    </tr>
    <tr role="row" class="odd">
        <td>Sanık</td>
        <td>Erzurum Bölge Adliye Mahkemesi 6. Ceza Dairesi</td>
        <td>2021/250</td>
        <td>Ceza Dava Dosyası</td>
        <td data-order="1613999200000" class="sorting_1">22.02.2021 16:06:40</td>
        <td>Kapalı ( 23.03.2021 16:31:28 )</td>
        <td>
            <button class="btn btn-default btn-sm pull-left" onclick="javascript&#058; void(0);">
                <i class="fa fa-eyes"></i> Dosya Görüntüle</button>
        </td>
    </tr>
    <tr role="row" class="even">
        <td>Sanık</td>
        <td>Erzurum Bölge Adliye Mahkemesi 6. Ceza Dairesi</td>
        <td>2019/207</td>
        <td>Ceza Dava Dosyası</td>
        <td data-order="1548421164000" class="sorting_1">25.01.2019 15:59:24</td>
        <td>Kapalı ( 28.04.2022 08:48:50 )</td>
        <td>
            <button class="btn btn-default btn-sm pull-left" onclick="javascript&#058; void(0);">
                <i class="fa fa-eyes"></i> Dosya Görüntüle</button>
        </td>
    </tr>
</tbody>


Code: Select all | Expand

    xml := oWebView:Eval('document.getElementById("dosya_listesi_result")')  


How Can I read this xml from oWebView? There is not anything in xml var.

Re: Help about TWebView class. reading something from website.

Posted: Wed Jun 29, 2022 8:16 pm
by Antonio Linares
Dear Hakan,

With Method oWebView:Eval() you can execute javascript but you can not get the return value.

To get a return value you have to use oWebView:bOnBind, so to get a returned value you should do:

oWebView:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
oWebView:Bind( "SendToFWH" )
oWebView:Eval( [SendToFWH( 'document.getElementById("dosya_listesi_result" )' ] )

Sometimes you have to call Sleep( nMillisecs ) to give the browse enough time to process it.

Please review FWH\samples\webviewuni.prg to review a working example :-)

Re: Help about TWebView class. reading something from website.

Posted: Thu Jun 30, 2022 9:49 am
by Horizon
Hi Antonio,

I have changed that you describe.

Code: Select all | Expand

  PROCEDURE XBROWSER_Show(cJson, nCalls)
    XBROWSER cJson slnum TITLE "cJson - Calls:"+NTRIM(nCalls)
RETURN

    oWebView:bOnBind = { | cJson, nCalls | XBROWSER_Show( cJson, nCalls ) }
    oWebView:Bind( "SendToFWH" )
....
....

oWebView:Eval( "SendToFWH( 'I am here' )" )
      aaa := "document.getElementById('dosya_listesi_result' )"
    oWebView:Eval( "SendToFWH( "+aaa+" )" )    


"I am here" message is comes. but next line just comes "[{}]"

Re: Help about TWebView class. reading something from website.

Posted: Thu Jun 30, 2022 3:11 pm
by Antonio Linares
Dear Hakan,

Please try it this way:

oWebView:Eval( "SendToFWH( '" + aaa + "' )" )

Please notice the "red" single quote that I have added at both sides

Re: Help about TWebView class. reading something from website.

Posted: Thu Jun 30, 2022 4:00 pm
by Horizon
Antonio Linares wrote:Dear Hakan,

Please try it this way:

oWebView:Eval( "SendToFWH( '" + aaa + "' )" )

Please notice the "red" single quote that I have added at both sides


Hi Antonio,

Tried. There is not any message.

Re: Help about TWebView class. reading something from website.

Posted: Thu Jun 30, 2022 8:11 pm
by Antonio Linares
Dear Hakan,

Please right click on the webview, open the inspector and check if there is any error or warning

Re: Help about TWebView class. reading something from website.

Posted: Thu Jun 30, 2022 9:11 pm
by Horizon
Antonio Linares wrote:Dear Hakan,

Please right click on the webview, open the inspector and check if there is any error or warning


Hi Antonio,

without above code there is only 2 warning.

Code: Select all | Expand

oWebView:Eval( "SendToFWH( '"+aaa+"' )" )   

Code: Select all | Expand

Audit usage of navigator.userAgent, navigator.appVersion, and navigator.platform
A page or script is accessing at least one of navigator.userAgent, navigator.appVersion, and navigator.platform. Starting in Chrome 101, the amount of information available in the User Agent string will be reduced.
To fix this issue, replace the usage of navigator.userAgent, navigator.appVersion, and navigator.platform with feature detection, progressive enhancement, or migrate to navigator.userAgentData.
Note that for performance reasons, only the first access to one of the properties is shown.
1 source
jquery-migrate-1.2.1.js:1
 

Code: Select all | Expand

Deprecated Feature Used
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help, check https://xhr.spec.whatwg.org/ .
1 source
pace.min.js:188
 


with above code there is no more error and warnings.

Code: Select all | Expand

oWebView:Eval( "SendToFWH( '"+aaa+"' )" )   

Re: Help about TWebView class. reading something from website.

Posted: Fri Jul 01, 2022 5:30 am
by Antonio Linares
Dear Hakan,

many thanks for all your feedback about webview

We are all learning about it and its really usefull that we share our findings

Re: Help about TWebView class. reading something from website.

Posted: Fri Jul 01, 2022 7:52 am
by Horizon
Antonio Linares wrote:Dear Hakan,

many thanks for all your feedback about webview

We are all learning about it and its really usefull that we share our findings


So, we are waiting.

Where is te WV_SENDTOFWH() function?. Is it internal?

Re: Help about TWebView class. reading something from website.

Posted: Fri Jul 01, 2022 7:59 am
by Antonio Linares
Dear Hakan,

Yes, it is internal, but as you have checked it works on many other cases. So it seems to me as the sent javascript is not correct.

Have you been able to inspect it (right click on webview) and see if you get any warning or errors there ?

You can trace the javascript code from such inspector. It is very powerful.

Re: Help about TWebView class. reading something from website.

Posted: Mon Jul 04, 2022 9:03 am
by Horizon
Hi Antonio,

I have insert log messages like below.

Code: Select all | Expand

 oWebView:Eval( "SendToFWH( 'I am here' )" )
   
  oWebView:Eval('console.log( "Antonio, Starting here" )')  

  aaa := "document.getElementById('dosya_listesi_result' )"
  oWebView:Eval( "SendToFWH( "+aaa+" )" ) 
  oWebView:Eval('console.log( '+aaa+' )')  

  aaa := 'document.getElementById("yargiTuru").value'
  oWebView:Eval( "SendToFWH( "+aaa+" )" ) 
  oWebView:Eval('console.log( yargiTuru = '+aaa+' )')  
   
    oWebView:Eval('console.log( "Antonio, Finished" )')


The console shows
Image

My app shows like this.
Image

I think javascript is not wrong. there is something wrong getting array variable from twebview.

Any help?

Re: Help about TWebView class. reading something from website.

Posted: Mon Jul 04, 2022 2:04 pm
by Antonio Linares
Dear Hakan,

From the inspector console please type this and press return:

document.getElementById('dosya_listesi_result' ); (you may try it with or without the ;

and let me know what you get in the console

Re: Help about TWebView class. reading something from website.

Posted: Mon Jul 04, 2022 2:42 pm
by Horizon
Antonio Linares wrote:Dear Hakan,

From the inspector console please type this and press return:

document.getElementById('dosya_listesi_result' ); (you may try it with or without the ;

and let me know what you get in the console


Hi Antonio,

As I said it in first thread I can read it from console with same javascript.
Image

Re: Help about TWebView class. reading something from website.

Posted: Mon Jul 04, 2022 2:51 pm
by Antonio Linares
Please try it like this:

oWebView:Eval( 'SendToFWH( ' + aaa + ' )' )

Re: Help about TWebView class. reading something from website.

Posted: Mon Jul 04, 2022 3:07 pm
by Horizon
Antonio Linares wrote:Please try it like this:

oWebView:Eval( 'SendToFWH( ' + aaa + ' )' )


Hi Antonio,

Same.
Image