Can you set the webview header before doing a LoadURL in an easy way?
I want to be able to do this with the cef:
http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=11716
So, I have created a class that inherits from UWebBrowser and this contains, in the protected section, a TSharedPtr WebBrowserWidget, which is used from the LoadURL call ,and inside of this there is another call , that is defined in the interface IWebBrowserWindow that calls SWebBrowser::BrowserView->LoadURL, i think there is some point where it is detecting the platform and finally calling this
void FCEFWebBrowserWindow::LoadURL(FString NewURL)
i don’t know where, but i see that the CefString is being created in the WebBrowserSingleton using this
FString ProductVersion = FString::Printf( TEXT("%s UnrealEngine/%s"), FApp::GetGameName(), *FEngineVersion::Current().ToString());
CefString(&Settings.product_version) = *ProductVersion;
which results in a header, in an apache server like this:
HTTP_USER_AGENT=Mozilla/5.0+(Windows+NT+6.2;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+MyGame+UnrealEngine/4.14.0-3195953+++UE4+Release-4.14+Safari/537.36
and I would like to change it with something like this:
HTTP_USER_AGENT=Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/55.0.2883.87+Safari/537.36
Can I change it directly or do I need some kind of trick?
You have to recompile the whole engine using parameters
//bool bVerboseLogging = FParse::Param(FCommandLine::Get(), TEXT("cefverbose")) || FParse::Param(FCommandLine::Get(), TEXT("debuglog"));
// CEFBrowserApp implements application-level callbacks.
CEFBrowserApp = new FCEFBrowserApp;
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
command_line->AppendSwitchWithValue("ppapi-flash-path", "pepflashplayer.dll");
command_line->AppendSwitchWithValue("ppapi-flash-version", "24.0 r0");
command_line->AppendSwitchWithValue("plugin-policy", "allow");
command_line->AppendSwitchWithValue("enable-system-flash", "1");
FCommandLine::Append(TEXT(" --enable-system-flash=1 --plugin-policy=allow "));
change also the ProductVersion FString to be able to change the user agent depending on your compilation constants:
#if PLATFORM_ANDROID
FString ProductVersion = FString::Printf(TEXT("Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36"));
#elif PLATFORM_IOS
FString ProductVersion = FString::Printf(TEXT("Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1"));
#else
FString ProductVersion = FString::Printf(TEXT("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"));
#endif
in Engine\Source\Runtime\WebBrowser\Private\WebBrowserSingleton.cpp and
CommandLine->AppendSwitchWithValue(
"ppapi-flash-path",
CefString(
TCHAR_TO_UTF8(
*FString::Printf(
TEXT("%s\\pepflashplayer.dll"),
*FPaths::GameDir()
)
)
)
//that could be "\Engine\\Source\\ThirdParty\\CEF3\\pepflashplayer.dll" instead
);
in Engine\Source\Runtime\WebBrowser\Private\CEF\CEFBrowserApp.cpp at void FCEFBrowserApp::OnBeforeCommandLineProcessing