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...
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
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).
WEBVIEW_API void webview_set_user_agent(webview_t w, const char *agent);
#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
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.
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 43 guests