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.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Bug? And is it possible to get around it?

Post Reply
igor666
Posts: 68
Joined: Fri Feb 08, 2019 1:25 pm

Bug? And is it possible to get around it?

Post by igor666 »

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:

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;
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.
You do not have the required permissions to view the files attached to this post.
User avatar
salvadordf
Posts: 4571
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Bug? And is it possible to get around it?

Post by salvadordf »

YouTube and many other websites send different contents depending on the browser used to render their pages, operating system, preferred language, user apparent location, available browser features, etc.

That's how those websites are designed and in this case you can only use the user-agent string that works best.
igor666
Posts: 68
Joined: Fri Feb 08, 2019 1:25 pm

Re: Bug? And is it possible to get around it?

Post by igor666 »

Ok, thanks for the answer.
Post Reply