1

I'm currently developing an app on Android using Delphi, and a part of the authentification is done using the native TWebBrowser component, which as I'm understanding pulls from android's native chrome webkit.

I need to clear cookies specific to my TWebBrowser component upon the press of a "log-off" button and upon exit of the application, however I'm finding it quite difficult as there doesn't seem to be any procedure within TWebBrowser which ressembles a cookie manager of any sort. Whilst I have EnableCaching set to false, the app remembers my credentials upon exit and restart, which is problematic for my use case...

Is there a way to access or delete cookies created by Delphi's Android TWebBrowser FMX component? I've thought of maybe importing this class :https://developer.android.com/reference/android/webkit/CookieManager with the JNI bridge, but I'm unsure on how to do so exactly and would like to try a native option if possible...

P.S : I've tried running chrome queries such as chrome://settings/clearBrowserData but it doesn't seem like TWebBrowser recognizes it, but if there's a similar option then I'm also open to it.

Any help is appreciated!

Surox
  • 25
  • 2

1 Answers1

0

You can try this to clear all cookies for the TWebBrowser running in your app (tested on Delphi 11 and inspired by this answer written for Java):

TJCookieManager.JavaClass.getInstance.removeAllCookies(nil);
TJCookieManager.JavaClass.getInstance.flush();

The same answer has code to access the cookies for some site given its URL, which in Delphi equals to:

Cookie := TJCookieManager.JavaClass.getInstance.getCookie('siteURL');

Where Cookie is a variable of type JString. Don't forget to add unit Androidapi.JNI.WebKit to your uses clause.

Alex Sawers
  • 636
  • 4
  • 11