Page 1 of 1

UserAgentAndMetadata Source

Posted: Wed Apr 17, 2024 6:20 pm
by sodlf159
procedure SetMobileUserAgentAndMetadata(const UserAgent: string);
var
Params, MetadataDict, BrandDict, FullVersionDict: ICefDictionaryValue;
BrandsArray, FullVersionListArray: ICefListValue;
begin
Params := TCefDictionaryValueRef.New;
MetadataDict := TCefDictionaryValueRef.New;
BrandsArray := TCefListValueRef.New;
FullVersionListArray := TCefListValueRef.New;

BrandsArray.SetSize(1);
BrandDict := TCefDictionaryValueRef.New;
BrandDict.SetString('brand', 'Chromium');
BrandDict.SetString('version', '91');
BrandsArray.SetDictionary(0, BrandDict);


FullVersionListArray.SetSize(1);
FullVersionDict := TCefDictionaryValueRef.New;
FullVersionDict.SetString('brand', 'Chromium'); //Not:A
FullVersionDict.SetString('version', '91.0.4472.114');
FullVersionListArray.SetDictionary(0, FullVersionDict);

MetadataDict.SetList('brands', BrandsArray);
MetadataDict.SetList('fullVersionList', FullVersionListArray);
MetadataDict.SetString('platform', 'Android'); //or Windows
MetadataDict.SetString('platformVersion', '12');
MetadataDict.SetString('architecture', 'arm');
MetadataDict.SetString('model', 'SM-F916N');
MetadataDict.SetBool('mobile', true);
MetadataDict.SetString('bitness', '32');


Params.SetString('userAgent', UserAgent);
Params.SetDictionary('userAgentMetadata', MetadataDict);


Chromium1.ExecuteDevToolsMethod(0, 'Emulation.setUserAgentOverride', Params);
end;

SetMobileUserAgentAndMetadata('Mozilla/5.0 (Linux; Android 12; SM-F916N Build/SP1A.210812.016; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/122.0.6261.64 Mobile Safari/537.36');

It also works for Windows, so please refer to it and change it before using.

Re: UserAgentAndMetadata Source

Posted: Thu Apr 18, 2024 10:07 am
by salvadordf
Thanks! :D

I just updated the MobileBrowser demo with your suggestion.