Bug? And is it possible to get around it?
Posted: Fri Dec 06, 2019 10:48 am
Using old cef4delphi, something strange happens when replacing the User-Agent. I will explain with the example of simplebrower2 and the site youtube.com.
User-Agent spoofing code:
When you download youtube, I get what is lower in the ATTACHMENT. And when you try to install any Chrome Windows User-Agent, youtube does not load. But if you substitute the User-Agent of any other browser or Chrome, but mobile, for example, then there are no problems. And if you substitute the native User-Agent - "Mozilla / 5.0 (Windows NT 6.1; WOW64) AppleWebKit / 537.36 (KHTML, like Gecko) Chrome / 49.0.2623.110 Safari / 537.36", then there are no problems either, everything loads fine. The problem is pronounced precisely on the youtube website, most of the other sites load normally during this substitution.
Could you help to understand what this may be connected with and how to fix it? Thanks in advance.
User-Agent spoofing code:
Code: Select all
procedure TForm1.Chromium1BeforeResourceLoad(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; const callback: ICefRequestCallback;
out Result: TCefReturnValue);
var
header, header_new: ICefStringMultimap;
i: NativeUInt;
uaset: boolean;
begin
header := TCefStringMultimapOwn.Create;
header_new := TCefStringMultimapOwn.Create;
request.GetHeaderMap(header);
for i := 0 to header.Size - 1 do
begin
if AnsiLowerCase(header.Key[i]) = 'user-agent' then
begin
header_new.Append(header.Key[i],'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36');
uaset := true;
end
else
header_new.Append(header.Key[i],header.Value[i]);
end;
if not uaset then
header_new.Append('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36');
request.SetHeaderMap(header_new);
end;
Could you help to understand what this may be connected with and how to fix it? Thanks in advance.