SWebBrowser's GetSource() appends source to URL on Android

Hello everyone,

I am currently trying to access the content of a SWebBrowser when the right URL is loaded, by using the GetSource() function.

I got my code to work for Windows and it was bulletproof. Now, I want to move to Android. And shortly after the GetSource() gets called my SWebBrowers brings up a error message not being able to load the Page.

I debugged a little and found out, that shortly after the GetSource() function call my URL changes for no apparent reason from https://oidcdebugger.com/debug to https://oidcdebugger.com/GetSource/%3Chead%3E%0A%20%20%20%20%3Cmeta%20charset%3D%22....

(Reminder: The same code worked very fine on Windows and triggered my callback function with the page content as intended).

For me it seems, that GetSource(), for whatever reason, appends the page content to the URL which results in my SWebBrowser not to being able to load the page (because it does not exist obviously).

Here is my code:

if (sBrowser.Get()->IsLoaded()) //gets called every 0.1 seconds
	{
		FString currURL = sBrowser.Get()->GetUrl();
		UE_LOG(LogTemp, Warning, TEXT("Current URL: %s"), *currURL);

		if (sBrowser.Get()->GetUrl() == "https://oidcdebugger.com/debug")
		{
			if (!m_SourceRequested) {
                           TFunction<void(const FString&)> MyProcessFunction = ([&](const FString& content) {
                                ...
			        });

				sBrowser.Get()->GetSource(MyProcessFunction);
				UE_LOG(LogTemp, Warning, TEXT("GetSource was Called"));

				m_SourceRequested = true;
			}
                    ...
		}

I really hope someone can help me to figure out what I am doing wrong.

BR,
Florian

I finally made this workaround (if get source writes the source into the URL, I extract it from the URL):

//...

void UMyClass::OpenBrowser(FString url){
    sBrowser = SNew(SWebBrowser)
        .OnURLChanged_UObject(this, &UMyClass::HandleURLChnage);
    //...
    sBrowser.Get()->LoadURL(url);
    //...
}

void UMyClass::Tick(float DeltaTime){
    //...
    if (sBrowser.Get()->IsLoaded())
    {
        //..
        sBrowser.Get()->GetSource(MyProcessFunction);
        //..
    }

   //...
}

//...

void UMyClass::HandleURLChange(const FText & text) {
    FStringView encodedURL = text.ToString();
    FString decodedURL = FGenericPlatformHttp::UrlDecode(encodedURL);
    //...
}
//...

It works, but I am still very confused why this is happening on Android and not on Windows!?

I used the following method, but it return null.

FString UWebBrowser::GetSource()
{
	if (WebBrowserWidget.IsValid())
	{
		FString cache; // used to get the value in lambda function below.
		TFunction<void(const FString& content)>lambda_func = [&](const FString& source) 
		{
			cache = source;
		};
		WebBrowserWidget->GetSource(lambda_func);
		return cache;
	}

	return FString();
}

I think there is no problem with my thinking, so I use a function to extract the value in lambda, it looks like a detour. (avoid assigning values to external variables in lambda function)

FString result = "";
void UpdateResult(const FString& source)
{
	result = source;
}

FString UWebBrowser::GetSource() const
{
	if (WebBrowserWidget.IsValid())
	{
		TFunction<void(const FString& content)>lambda_func = [&](const FString& content) 
		{
			UpdateResult(content);
		};
		WebBrowserWidget->GetSource(lambda_func);
		return result;
	}

	return FString();
}

then it works well.