FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour TWebView2 question.
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
TWebView2 question.
Posted: Wed Jul 09, 2025 12:18 PM
Hi,

I was using the standard TWebView class until now. I am trying to switch to the TWebView2 class. In the old class, we were doing the following to read information from the web page. I couldn't find how to do these operations in the new class.
  oWebView:bOnBind = { | cJson, nCalls |  GetDataFrom_WebView( cJson, nCalls ) }
  oWebView:Bind( "SendToFWH" )	   
  oWebView:Navigate(cHtml)
  oWebView:Run()
oWebView:Eval('SendToFWH( document.getElementById( "username" ).value )')	
? cResultVar
PROCEDURE GetDataFrom_WebView(cJson, nCalls)
	cResultVar := cJson
RETURN
Is there anybody to help me reading from current active webview? any example.
Thanks.
Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: TWebView2 question.
Posted: Thu Jul 10, 2025 01:55 AM

Hello Hakam

Show type and value of cResultVar

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView2 question.
Posted: Thu Jul 10, 2025 04:06 AM

Dear Hakan,

Could you provide a small self contained PRG example to test here ?

This is not needed for Class TWebView2 as SendToFWH is binded by default:

oWebView:Bind( "SendToFWH" )

many thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: TWebView2 question.
Posted: Fri Jul 11, 2025 12:01 PM
cnavarro wrote: Hello Hakam
Show type and value of cResultVar
Sorry for delay.

My Test code is below.
#include "FiveWin.ch"
#include "ribbon.ch"
	

function Main()
local oWnd, oWebView, oRBar, oBtn, oGrp11
LOCAL cResultVar := ""
	
	DEFINE WINDOW oWnd TITLE "Using a webview from an existing window "+FWVERSION
	oWnd:Show()
   
	DEFINE RIBBONBAR oRBar WINDOW oWnd ;
	PROMPT "Folder1", "Folder2" ;
	HEIGHT 133 TOPMARGIN 25   
	
	ADD GROUP oGrp11  RIBBON oRBar TO OPTION 1 PROMPT "" WIDTH 200
		@ 3, 3 ADD BUTTON oBtn GROUP oGrp11 ;
			SIZE 80, 82 PROMPT "Test1";
			ACTION (MyAction1(oWebView))
	
		@ 3, 83 ADD BUTTON oBtn GROUP oGrp11 ;
			SIZE 80, 82 PROMPT "Test2";
			ACTION (MyAction2(oWebView))
			
	//oWebView = TWebView2():New(oWnd)
	oWebView = TWebView():New( , oWnd:hWnd  )
	oWebView:SetUserAgent( "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Mobile Safari/537.36" )
	
	oWebView:bOnBind = { | cJson, nCalls |  GetDataFrom_WebView( cJson, nCalls, @cResultVar ) }
	oWebView:Bind( "SendToFWH" )
	//  oWebView:OpenDevToolsWindow(.T.)
	oWebView:Navigate( "http://www.google.com" )
	
	ACTIVATE WINDOW oWnd CENTER MAXIMIZED ;
	  ON RESIZE oWebView:SetSize( nWidth, nHeight )
	
	oWebView:End()
	
return nil

PROCEDURE GetDataFrom_WebView(cJson, nCalls, cResultVar)
	cResultVar := cJson
	? "TWebView - Result", cJson, VALTYPE(cJson), PROCNAME(),PROCLINE()
RETURN

PROCEDURE MyAction1(oWebView)
LOCAL cScript
	cScript := "document.getElementsByName('btnK')[0].value"
	oWebView:Eval('SendToFWH('+cScript+')')
//	? cScript, "Result = ",cResultVar, VALTYPE(cResultVar), PROCNAME(),PROCLINE()
RETURN
My Test result is TWebView
http://www.objekt.com.tr/fwh_test/WebView_Test1.jpg
http://www.objekt.com.tr/fwh_test/WebView_Test2.png
http://www.objekt.com.tr/fwh_test/WebView2_Test1.png
http://www.objekt.com.tr/fwh_test/WebView2_Test2.png

As you can see, TWebView's result type is "C", example ['complete'], TWebView2's result type is "A", example {'complete'}
Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView2 question.
Posted: Sat Jul 12, 2025 04:51 PM

Dear Hakan,

Both classes are not identical.

Do you plan to use TWebView2 ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: TWebView2 question.
Posted: Sat Jul 12, 2025 07:07 PM
Antonio Linares wrote: Dear Hakan,

Both classes are not identical.

Do you plan to use TWebView2 ?
Yes.
Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView2 question.
Posted: Sun Jul 13, 2025 05:02 AM
Dear Hakan,

I would do it this way. Not sure if this is what you are looking for:
#include "FiveWin.ch"
#include "ribbon.ch"
	

function Main()
local oWnd, oWebView, oRBar, oBtn, oGrp11, oPanel
LOCAL cResultVar := ""
	
	DEFINE WINDOW oWnd TITLE "Using a webview from an existing window "+FWVERSION
	oWnd:Show()
   
	DEFINE RIBBONBAR oRBar WINDOW oWnd ;
	PROMPT "Folder1", "Folder2" ;
	HEIGHT 133 TOPMARGIN 25   
	
	ADD GROUP oGrp11  RIBBON oRBar TO OPTION 1 PROMPT "" WIDTH 200
		@ 3, 3 ADD BUTTON oBtn GROUP oGrp11 ;
			SIZE 80, 82 PROMPT "Test1";
			ACTION (MyAction1(oWebView))
	
		@ 3, 83 ADD BUTTON oBtn GROUP oGrp11 ;
			SIZE 80, 82 PROMPT "Test2";
			// ACTION (MyAction2(oWebView))
			
	oPanel = TPanel():New( 0, 0, 10, 10, oWnd )
	oWnd:oClient = oPanel
	oWebView = TWebView2():New( oPanel  )
	oWebView:SetUserAgent( "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Mobile Safari/537.36" )
	// oWebView:OpenDevToolsWindow( .T. )

	oWebView:bOnEval = { | cJson, nCalls |  GetDataFrom_WebView( cJson, nCalls, @cResultVar ) }
	oWebView:Navigate( "http://www.google.com" )
	
	ACTIVATE WINDOW oWnd CENTER MAXIMIZED ;
	  ON RESIZE oWebView:SetSize( nWidth, nHeight )
	
	oWebView:End()
	
return nil

PROCEDURE GetDataFrom_WebView(cJson, nCalls, cResultVar)
	cResultVar := cJson
	? "TWebView - Result", cJson, VALTYPE(cJson), PROCNAME(),PROCLINE()
RETURN

PROCEDURE MyAction1(oWebView)
LOCAL cScript
	cScript := "document.getElementsByName('btnK')[0].value"
	oWebView:Eval( cScript )
RETURN
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: TWebView2 question.
Posted: Sun Jul 13, 2025 09:17 AM

Thank you Antonio

Is the SendtoFWH function the same in both classes? The types of variables it returns are also different. This is my main problem.

Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView2 question.
Posted: Sun Jul 13, 2025 08:17 PM

You are right, they are not exactly the same. Previously we were using a third party DLL with ots own rules.

Now we have full source code our own and the implementation is a little different.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: TWebView2 question.
Posted: Sun Jul 13, 2025 09:09 PM
Hi Antonio,

I did some comparisons and made some changes to the GetDataFrom_WebView function and for now I got the same results as the old version.
PROCEDURE GetDataFrom_WebView(cJson, nCalls, oWebView)
	IF VALTYPE(cJson)="A"
		cJson := hb_JsonEncode(cJson)
	ENDIF
	cResultVar := cJson
	//oWebView:cResultVar := cResultVar
RETURN
Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06

Continue the discussion