Emulate a mobile browser
Posted: Mon Aug 21, 2023 6:37 pm
I'm using the code below to emulate an Android web browser, it works well !
But after i run the code below, what if i want to go back to the 'default' browser ?
var
TempParams, TempDict: ICefDictionaryValue;
TempFormatSettings: TFormatSettings;
TempOrientation: string;
begin
try
TempParams := TCefDictionaryValueRef.New;
TempParams.SetInt('width', 480);
TempParams.SetInt('height', 800);
TempFormatSettings := TFormatSettings.Create;
TempFormatSettings.DecimalSeparator := '.';
TempParams.SetDouble('deviceScaleFactor', StrToFloat('1', TempFormatSettings));
TempParams.SetBool('mobile', true);
TempDict := TCefDictionaryValueRef.New;
TempDict.SetString('type', 'portraitPrimary');
TempDict.SetInt('angle', 0);
TempParams.SetDictionary('screenOrientation', TempDict);
ExecuteDevToolsMethod(5, 'Emulation.setDeviceMetricsOverride', TempParams);
TempParams := TCefDictionaryValueRef.New;
TempParams.SetString('userAgent', uaAndroid);
ExecuteDevToolsMethod(1, 'Emulation.setUserAgentOverride', TempParams);
finally
TempDict := nil;
TempParams := nil;
end;
end;
But after i run the code below, what if i want to go back to the 'default' browser ?
var
TempParams, TempDict: ICefDictionaryValue;
TempFormatSettings: TFormatSettings;
TempOrientation: string;
begin
try
TempParams := TCefDictionaryValueRef.New;
TempParams.SetInt('width', 480);
TempParams.SetInt('height', 800);
TempFormatSettings := TFormatSettings.Create;
TempFormatSettings.DecimalSeparator := '.';
TempParams.SetDouble('deviceScaleFactor', StrToFloat('1', TempFormatSettings));
TempParams.SetBool('mobile', true);
TempDict := TCefDictionaryValueRef.New;
TempDict.SetString('type', 'portraitPrimary');
TempDict.SetInt('angle', 0);
TempParams.SetDictionary('screenOrientation', TempDict);
ExecuteDevToolsMethod(5, 'Emulation.setDeviceMetricsOverride', TempParams);
TempParams := TCefDictionaryValueRef.New;
TempParams.SetString('userAgent', uaAndroid);
ExecuteDevToolsMethod(1, 'Emulation.setUserAgentOverride', TempParams);
finally
TempDict := nil;
TempParams := nil;
end;
end;