You've already forked CEF4Delphi
mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-07-12 22:30:17 +02:00
Improved function to emulate the user agent thanks to 김케이 KimK-Hack
This commit is contained in:
@ -110,7 +110,7 @@ implementation
|
||||
{$R *.lfm}
|
||||
|
||||
uses
|
||||
uCEFApplication, uCEFMiscFunctions;
|
||||
uCEFApplication, uCEFMiscFunctions, uCEFListValue;
|
||||
|
||||
// This demo allows you to emulate a mobile browser using the "Emulation" namespace of the DevTools.
|
||||
// It's necesary to reload the browser after using the controls in the right panel.
|
||||
@ -305,10 +305,42 @@ end;
|
||||
procedure TForm1.OverrideUserAgentBtnClick(Sender: TObject);
|
||||
var
|
||||
TempParams : ICefDictionaryValue;
|
||||
TempMetadataDict, TempBrandDict, TempFullVersionDict: ICefDictionaryValue;
|
||||
TempBrandsArray, TempFullVersionListArray: ICefListValue;
|
||||
begin
|
||||
try
|
||||
TempParams := TCefDictionaryValueRef.New;
|
||||
|
||||
TempMetadataDict := TCefDictionaryValueRef.New;
|
||||
TempBrandsArray := TCefListValueRef.New;
|
||||
TempFullVersionListArray := TCefListValueRef.New;
|
||||
|
||||
TempBrandsArray.SetSize(1);
|
||||
TempBrandDict := TCefDictionaryValueRef.New;
|
||||
TempBrandDict.SetString('brand', 'Chromium');
|
||||
TempBrandDict.SetString('version', '91');
|
||||
TempBrandsArray.SetDictionary(0, TempBrandDict);
|
||||
|
||||
|
||||
TempFullVersionListArray.SetSize(1);
|
||||
TempFullVersionDict := TCefDictionaryValueRef.New;
|
||||
TempFullVersionDict.SetString('brand', 'Chromium'); //Not:A
|
||||
TempFullVersionDict.SetString('version', '91.0.4472.114');
|
||||
TempFullVersionListArray.SetDictionary(0, TempFullVersionDict);
|
||||
|
||||
TempMetadataDict.SetList('brands', TempBrandsArray);
|
||||
TempMetadataDict.SetList('fullVersionList', TempFullVersionListArray);
|
||||
TempMetadataDict.SetString('platform', 'Android'); //or Windows
|
||||
TempMetadataDict.SetString('platformVersion', '12');
|
||||
TempMetadataDict.SetString('architecture', 'arm');
|
||||
TempMetadataDict.SetString('model', 'SM-F916N');
|
||||
TempMetadataDict.SetBool('mobile', true);
|
||||
TempMetadataDict.SetString('bitness', '32');
|
||||
|
||||
TempParams.SetString('userAgent', UserAgentCb.Text);
|
||||
// Setting the userAgentMetadata value is optional and can be omited.
|
||||
// All the values in TempMetadataDict are just an example and they should be customized for each use case.
|
||||
TempParams.SetDictionary('userAgentMetadata', TempMetadataDict);
|
||||
|
||||
FPendingMsgID := DEVTOOLS_SETUSERAGENTOVERRIDE_MSGID;
|
||||
Chromium1.ExecuteDevToolsMethod(0, 'Emulation.setUserAgentOverride', TempParams);
|
||||
|
Reference in New Issue
Block a user