I just added your code to the MobileBrowser demo like this :
Code: Select all
procedure TForm1.OverrideUserAgentBtnClick(Sender: TObject);
var
TempParams, TempDict : ICefDictionaryValue;
begin
try
TempParams := TCefDictionaryValueRef.New;
TempParams.SetString('userAgent', UserAgentCb.Text);
TempDict := TCefDictionaryValueRef.New;
TempDict.SetString('platform', 'Linux');
TempDict.SetString('platformVersion', '10.1.0');
TempDict.SetString('architecture', 'x86');
TempDict.SetString('model', 'Mint');
TempDict.SetBool('mobile', False);
TempParams.SetDictionary('userAgentMetadata', TempDict);
FPendingMsgID := DEVTOOLS_SETUSERAGENTOVERRIDE_MSGID;
Chromium1.ExecuteDevToolsMethod(0, 'Emulation.setUserAgentOverride', TempParams);
finally
TempParams := nil;
end;
end;
I saw this result in the LogMem control : "Successful SetUserAgentOverride".
Then I navigated to https://browserleaks.com/client-hints
These are the results :
Your Web Browser
HTTP User-Agent Mozilla/5.0 (Linux; Android 11; M2102K1G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Mobile Safari/537.36
Client Hints JavaScript API
API Support ✔True
brands [{"brand":"Chromium","version":"112"}]
mobile false
platform Linux
platformVersion 10.1.0
architecture x86
bitness empty
wow64 false
model Mint
uaFullVersion 112.0.5615.49
fullVersionList []
The new values in the "userAgentMetadata" dictionary seem to work.
The cause of this issue was an incorrect parameter name. The correct name is "
userAgentMetadata" and not "
UserAgentMetadata". The DevTools methods are case sensitive.