TWebView() and Google Group Account

Re: TWebView() and Google Group Account

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42059
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: TWebView() and Google Group Account

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42059
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: TWebView() and Google Group Account

Postby Antonio Linares » Sat Jul 02, 2022 6: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: Select all  Expand view
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: 42059
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: TWebView() and Google Group Account

Postby Antonio Linares » Sat Jul 02, 2022 7:40 am

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

Code: Select all  Expand view
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 view
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: 42059
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: TWebView() and Google Group Account

Postby Antonio Linares » Sat Jul 02, 2022 8: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 !!!!!!!!!!!!!!!! :-D

Here it is the FWH code to access google.com and identify yourself with no issues at all ;-)
Code: Select all  Expand view
#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: 42059
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: TWebView() and Google Group Account

Postby Antonio Linares » Sat Jul 02, 2022 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42059
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: TWebView() and Google Group Account

Postby Jimmy » Sat Jul 02, 2022 3: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 :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
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 69 guests