FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour TWebView() and Google Group Account
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView() and Google Group Account
Posted: Fri Jul 01, 2022 10:36 PM
Teoretically we can do it using javascrit, it is explained here:
https://stackoverflow.com/questions/23248525/setting-a-custom-useragent-in-html-or-javascript

trying it... :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView() and Google Group Account
Posted: Fri Jul 01, 2022 10:57 PM

I am trying this with no success yet:

oWebView:Eval( "navigator.defineGetter('userAgent', function () { return 'Chrome' } );" )

In fact, from the inspector console you can try this javacript:

console.log( navigator.userAgent );
navigator.defineGetter('userAgent', function () { return 'Chrome' } );
console.log( navigator.userAgent ); // we get Chrome here

I think we are quite close to get it... :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView() and Google Group Account
Posted: Sat Jul 02, 2022 06:40 AM
New answer from Steffen and our answer to him. Meanwhile we don't find a way to programmatically uncheck the default userAgent from the inspector, I guess that there is no other way except doing it by "hand" :-)

https://github.com/webview/webview/issues/792

this code should do the "magic" and in fact it changes the navigator.userAgent but still forces us to manually uncheck the default userAgent from the inspector:
Code (fw): Select all Collapse
function Main()

   local oWebView := TWebView():New()

   oWebView:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
   oWebView:Bind( "SendToFWH" )
   oWebView:Navigate( "http://www.google.com" ) // Html() )
   Sleep( 200 )
   oWebView:Eval( "navigator.__defineGetter__('userAgent', function () { return '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:Eval( "SendToFWH( navigator.userAgent )" )
   oWebView:Run()
   oWebView:Destroy()

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView() and Google Group Account
Posted: Sat Jul 02, 2022 07:40 AM
Miracle exists... Steffen has included a new function into webview.dll thanks to our requests:

Code (fw): Select all Collapse
https://github.com/webview/webview/issues/792#issuecomment-1172852232

While your approach may work, I suspect that it is not going to be sufficient because the user agent is sent to the server with every HTTP request, and I doubt that you can successfully intercept them all using only JavaScript. The sure way to make this work is to integrate it properly with the underlying browser engine (e.g. WebView2 as you are using Windows).


Here it is the commit he did this morning:
https://github.com/webview/webview/compare/master...SteffenL:webview:up/set-user-agent

where he is adding a new function:
Code (fw): Select all Collapse
WEBVIEW_API void webview_set_user_agent(webview_t w, const char *agent);

Now we just need to rebuild the DLL and test it... :-)
It feels simply great when you find people like Steffen...
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView() and Google Group Account
Posted: Sat Jul 02, 2022 08:24 AM
c:\>git clone --branch up/set-user-agent https://github.com/SteffenL/webview webview_useragent

Then open a "Developer command prompt for VS2022" as administrator and go to c:\webview_useragent\script\

and run build.bat

We got webview.dll properly built and it is working fine and the problem is solved !!!!!!!!!!!!!!!! :-)

Here it is the FWH code to access google.com and identify yourself with no issues at all :-)
Code (fw): Select all Collapse
#include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

   local oWebView := TWebView():New()

   oWebView:Navigate( "http://www.google.com" )
   Sleep( 200 )
   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:Run()
   oWebView:Destroy()

return nil


Working as expected !!! Great! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView() and Google Group Account
Posted: Sat Jul 02, 2022 09:04 AM

Dear Jimmy,

We have published a revised FWH 22.06 including this new method and updated DLLs and we are emailing it to you.

To all FWH users, please download FWH 22.06 again.

Please notice that both webview.dll and WebView2Loader.dll have been updated !!!

many thanks!

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: TWebView() and Google Group Account
Posted: Sat Jul 02, 2022 03:43 PM
hi Antonio,
Antonio Linares wrote:
We have published a revised FWH 22.06 including this new method and updated DLLs and we are emailing it to you.

i have download new Version, install it and build your new Sample and it WORK, GREATE :-)
now i can login to harbour Group at Google, YouTube and all Website where i can use Google Account.

Thx for you fast response to fix the Problem
greeting,

Jimmy

Continue the discussion