Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
UserAgentAndMetadata Source
UserAgentAndMetadata Source
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.
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.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: UserAgentAndMetadata Source
Thanks! 
I just updated the MobileBrowser demo with your suggestion.

I just updated the MobileBrowser demo with your suggestion.
Re: UserAgentAndMetadata Source
And how do I change the formFactors?
https://browserleaks.com/client-hints
Mobile
Emulate
https://browserleaks.com/client-hints
Mobile
Code: Select all
formFactors ["Mobile"]
Code: Select all
formFactors []
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: UserAgentAndMetadata Source
I tried several user agent values and command line switches but I couldn't change that value.
I guess some of those detection scripts require patching Chromium in CEF.
I guess some of those detection scripts require patching Chromium in CEF.
Re: UserAgentAndMetadata Source
Google Chrome doesn't seem to be able to do this either(
One more question, what is the difference between the methods?
They seem to work the same way, what's the catch?
One more question, what is the difference between the methods?

Code: Select all
Emulation.setUserAgentOverride
and
Network.setUserAgentOverride
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: UserAgentAndMetadata Source
I don't know the internal implementation details of those methods but they seem to be identical. 

Re: UserAgentAndMetadata Source
Nothing comes from the CDP formula.dilfich wrote: Fri Jan 24, 2025 5:57 am And how do I change the formFactors?
https://browserleaks.com/client-hints
MobileEmulateCode: Select all
formFactors ["Mobile"]
Code: Select all
formFactors []
There is no problem at all even if it is treated as [].
No security reference yet
Re: UserAgentAndMetadata Source
F12dilfich wrote: Sat Jan 25, 2025 11:32 pm Google Chrome doesn't seem to be able to do this either(
One more question, what is the difference between the methods?
They seem to work the same way, what's the catch?Code: Select all
Emulation.setUserAgentOverride and Network.setUserAgentOverride
Network or
Emulation
It's just a difference.
What would be more accurate would be to apply both.
Additionally, CDP must be reapplied every time the page is moved.
CDP > ExecuteDevToolsMethod
https://chromedevtools.github.io/devtools-protocol/
Re: UserAgentAndMetadata Source
About reuse, it is not entirely clear how to check that it is necessary?
And the question is probably not quite on the topic, how do I change the cursor to the touchpad?
OSR
Emulation.setEmitTouchEventsForMouse (Online tests are impossible without this emulation.)
TCefCursorType - It doesn't seem to be here.
circle, I can't take a screenshot
It's just not clear when emulation is enabled and when it's not.

And the question is probably not quite on the topic, how do I change the cursor to the touchpad?
OSR
Emulation.setEmitTouchEventsForMouse (Online tests are impossible without this emulation.)
Code: Select all
OnCursorChange
Cursor := CefCursorToWindowsCursor(cursorType);
circle, I can't take a screenshot
It's just not clear when emulation is enabled and when it's not.
Re: UserAgentAndMetadata Source
https://chromedevtools.github.io/devtools-protocol/tot/Emulation/#method-setEmitTouchEventsForMouse