TWebView() and Google Group Account

User avatar
Antonio Linares
Site Admin
Posts: 42597
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 40 times
Been thanked: 86 times
Contact:

Re: TWebView() and Google Group Account

Post by Antonio Linares »

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
User avatar
Antonio Linares
Site Admin
Posts: 42597
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 40 times
Been thanked: 86 times
Contact:

Re: TWebView() and Google Group Account

Post by Antonio Linares »

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
User avatar
Antonio Linares
Site Admin
Posts: 42597
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 40 times
Been thanked: 86 times
Contact:

Re: TWebView() and Google Group Account

Post by Antonio Linares »

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: Select all | Expand

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
User avatar
Antonio Linares
Site Admin
Posts: 42597
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 40 times
Been thanked: 86 times
Contact:

Re: TWebView() and Google Group Account

Post by Antonio Linares »

Miracle exists... Steffen has included a new function into webview.dll thanks to our requests:

Code: Select all | Expand

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: Select all | Expand

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
User avatar
Antonio Linares
Site Admin
Posts: 42597
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 40 times
Been thanked: 86 times
Contact:

Re: TWebView() and Google Group Account

Post by Antonio Linares »

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 !!!!!!!!!!!!!!!! :-D

Here it is the FWH code to access google.com and identify yourself with no issues at all ;-)

Code: Select all | Expand

#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
User avatar
Antonio Linares
Site Admin
Posts: 42597
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 40 times
Been thanked: 86 times
Contact:

Re: TWebView() and Google Group Account

Post by Antonio Linares »

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
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: TWebView() and Google Group Account

Post by Jimmy »

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 :D
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
Post Reply