Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Change User Agent for FireMonkey TWebBrowser



Permlink Replies: 1 - Last Post: Oct 31, 2016 11:01 PM Last Post By: Eli M
Frank Yingst

Posts: 175
Registered: 1/19/05
Change User Agent for FireMonkey TWebBrowser
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 30, 2016 7:12 PM
Anyone figured out how to do this? I would like to obtain the page as seen on the desktop while using a mobile device.
Eli M

Posts: 1,346
Registered: 11/9/13
Re: Change User Agent for FireMonkey TWebBrowser
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 31, 2016 11:01 PM   in response to: Frank Yingst in response to: Frank Yingst
http://stackoverflow.com/questions/5586197/android-user-agent

https://gist.github.com/freeonterminate/303c2910d96f871bd5db

procedure TWebBrowserHelper.SetUserAgent(const iUA: String);
{$IFDEF ANDROID}
var
  WebBrowser: JWebBrowser;
begin
    WebBrowser := GetField<JWebBrowser>('FJWebBrowser');
    if (WebBrowser <> nil) then
      WebBrowser.getSettings.setUserAgentString(StringToJString(iUA));
end;
{$ELSE}
begin
end;
{$ENDIF}


Patch in FMX.WebBrowser.Android.pas in this function maybe:

procedure TAndroidWebBrowserService.InitUIThread;
begin
  FJWebBrowser := TJWebBrowser.JavaClass.init(TAndroidHelper.Activity);
  FJWebBrowser.getSettings.setJavaScriptEnabled(True);
  FListener := TWebBrowserListener.Create(Self);
  FJWebBrowser.SetWebViewListener(FListener);
  FJNativeLayout := TJNativeLayout.JavaClass.init(TAndroidHelper.Activity,
    MainActivity.getWindow.getDecorView.getWindowToken);
  FJNativeLayout.setPosition(100,100);
  FJNativeLayout.setSize(300,300);
  FJNativeLayout.setControl(FJWebBrowser);
  FFocusChangeListener := TFocusChangeListener.Create(Self);
  FJNativeLayout.setOnFocusChangeListener(FFocusChangeListener);
  FJWebBrowser.getSettings.setGeolocationEnabled(True);
  FJWebBrowser.getSettings.setAppCacheEnabled(True);
  FJWebBrowser.getSettings.setDatabaseEnabled(True);
  FJWebBrowser.getSettings.setDomStorageEnabled(True);
  FJWebBrowser.getSettings.setBuiltInZoomControls(True);
  FJWebBrowser.getSettings.setDisplayZoomControls(False);
end;
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02