Download

How to clear cookies of the Unreal webbrowser?

Hi,
I’m trying to use the webbrowser to create a login for facebook/google.
However the cookies of this browser are not cleared after every session.
This is how I create my browser


	FBrowserContextSettings browserContextSettings("myID");
	browserContextSettings.bIgnoreCertificateErrors = true;
	browserContextSettings.bPersistSessionCookies = false;
	browserContextSettings.CookieStorageLocation = ServerEnvironment.BrowserCacheLocation;
	FCreateBrowserWindowSettings webBrowserSettings;
	webBrowserSettings.bUseTransparency = false;
	webBrowserSettings.Context = browserContextSettings;

	TSharedPtr<IWebBrowserWindow>  browserSP = IWebBrowserModule::Get().GetSingleton()->CreateBrowserWindow(webBrowserSettings);
	TSharedPtr<SWebBrowser> browserWidget;
	browserWidget = SAssignNew(browserWidget, SWebBrowser, browserSP)
		.ViewportSize(FVector2D(GEngine->GameViewport->Viewport->GetSizeXY()))
		.ShowControls(false)
		.ShowAddressBar(false)
		.OnUrlChanged(BIND_UOBJECT_DELEGATE(FOnTextChanged, OnBrowserUrlChanged));

	GEngine->GameViewport->AddViewportWidgetContent(browserWidget.ToSharedRef());

After I’m done I try to clear my cookies like this:


TSharedPtr<IWebBrowserCookieManager> cookieMan = IWebBrowserModule::Get().GetSingleton()->GetCookieManager();
		cookieMan->DeleteCookies("", "");

In the IWebBrowserCookieManager.h it says:

Why are my cookies not cleared? Is this a bug?

Any help would be appreciated.

I have the same Issue

i’ve tryed it but didn´t work: http://bit.ly/2Tby3rY

This worked for me


        
IWebBrowserSingleton* WebBrowserSingleton = IWebBrowserModule::Get().GetSingleton();
if (WebBrowserSingleton)
{
  TSharedPtr<IWebBrowserCookieManager> CookieManager = WebBrowserSingleton->GetCookieManager();
   if (CookieManager.IsValid())
   {
    CookieManager->DeleteCookies();
   }
}


Note in DeleteCookies() also says

So you may need some bind or delay before restart your browser.

1 Like

this works for me too, handsome code