Accept-Language I can't change it.

Post Reply
sodlf159
Posts: 14
Joined: Thu Nov 09, 2023 1:55 pm

Accept-Language I can't change it.

Post by sodlf159 »

ICefRequest POST > Chromium1.LoadRequest(TempRequest); >

The first request changes, but

In the case of GET and POST, which are rendered the second time, there is no change.

Chromium1BeforeResourceLoad

request.SetHeaderByName('Accept-Language', 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7',True);

It's the same even if you do it.

map := TCefStringMultimapOwn.Create;
try
request.GetHeaderMap(map);
map.Append('Accept-Language', 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7');
request.SetHeaderMap(map);
finally
map := nil;
end;

Even so, it doesn't change.
What is the reason?
sodlf159
Posts: 14
Joined: Thu Nov 09, 2023 1:55 pm

Re: Accept-Language I can't change it.

Post by sodlf159 »

GlobalCEFApp.ChromeRuntime := True;
It doesn't respond when turned on.
User avatar
salvadordf
Posts: 4087
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Accept-Language I can't change it.

Post by salvadordf »

If I remember correctly, Chromium doesn't allow to change some headers in certain events.

Try setting GlobalCEFApp.AcceptLanguageList before the GlobalCEFApp.StartMainProcess or set TChromiumCore.AcceptLanguageList for each browser.

If you set TChromiumCore.AcceptLanguageList then call TChromiumCore.UpdatePreferences to update the preferences immediately.
sodlf159
Posts: 14
Joined: Thu Nov 09, 2023 1:55 pm

Re: Accept-Language I can't change it.

Post by sodlf159 »

TempElement := TCefPostDataElementRef.New;
TempElement.SetToBytes(length(TempParams), @TempParams[1]);
TempPostData := TCefPostDataRef.New;
TempPostData.AddElement(TempElement);

TempRequest.PostData := TempPostData;
Chromium1.AcceptLanguageList := 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7';
Chromium1.UpdatePreferences;
Chromium1.LoadRequest(TempRequest);

It seems like it can't be changed.

GlobalCEFApp.AcceptLanguageList := 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7';

GlobalCEFApp.ChromeRuntime := True;
if GlobalCEFApp.StartMainProcess then
Even so, there is no response.
User avatar
salvadordf
Posts: 4087
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Accept-Language I can't change it.

Post by salvadordf »

I did several tests with GlobalCEFApp.AcceptLanguageList and also setting TChromiumCore.AcceptLanguageList in TChromiumCore.OnAfterCreated.

The MiniBrowser demo shows the custom Accept-Language value when you visit and in the "Show server headers" context menu option.

It's also possible to see the HTML headers that the browser is using when you navigate to :
https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending

I also added a custom menu item with this code :

Code: Select all

procedure TMiniBrowserFrm.LoadRequest1Click(Sender: TObject);
var
  Request: ICefRequest;
begin
  Request := TCefRequestRef.New;
  Request.Url := 'https://www.briskbard.com/images/logo.png';
  Request.Method := 'GET';

  Chromium1.LoadRequest(Request);
end;
The "Show server headers" context menu option also showed the custom Accept-Language value after loading that request.

TChromiumCore.UpdatePreferences is asynchronous but the preferences are automatically updated internally in the TChromiumCore.OnBeforeBrowse

The code comments for TChromiumCore.LoadResource mention that this function will fail with bad IPC message reason INVALID_INITIATOR_ORIGIN (213) unless you first navigate to the request origin using some other mechanism (LoadURL, link click, etc).

Try setting the GlobalCEFApp.AcceptLanguageList value, then navigate to the same domain using TChromiumCore.LoadURL and after that you can call TChromiumCore.LoadResource safely.
sodlf159
Posts: 14
Joined: Thu Nov 09, 2023 1:55 pm

Accept-Language I can't change it.

Post by sodlf159 »

https://www.briskbard.com/forum/viewtopic.php?t=2289&sid=aefe847efd406ee071e79a18275382d3

It comes out as a duplicate together with the existing one.

ko-KR","ko;q=0.9","en-US;q=0.8","en;q=0.7

F12
accept-language: ko-KR,ko;q=0.9,ko;q=0.9;q=0.8,en-US;q=0.8;q=0.7,en;q=0.6,en;q=0.7;q=0.5

"en;q=0.6,en;q=0.7;q=0.5" << default I want to delete this.

Image

https://ibb.co/k0NgJbX

accept-encoding: gzip, deflate, br

"br" < I want to delete this too br
User avatar
salvadordf
Posts: 4087
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Accept-Language I can't change it.

Post by salvadordf »

I merged the forum topics.

In order to solve the issue with the Accept-Language header replace the TMiniBrowserFrm.Chromium1AfterCreated procedure in MiniBrowser with this :

Code: Select all

procedure TMiniBrowserFrm.Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
begin
  Chromium1.AcceptLanguageList := 'ko-KR,ko';

  if Chromium1.IsSameBrowser(browser) then
    PostMessage(Handle, CEF_AFTERCREATED, 0, 0)
   else
    SendMessage(browser.Host.WindowHandle, WM_SETICON, 1, application.Icon.Handle); // Use the same icon in the popup window
end;
With that fix browserleaks.com shows "ko-KR,ko;q=0.9" in the Accept-Language header.

I searched about the Accept-Encoding header and I found this CEF issue :
https://github.com/chromiumembedded/cef/issues/2303

The Brotli encoding should be working in CEF browsers.

I also found this old support answer about disabling it in Chrome :
https://support.google.com/websearch/thread/13460143/how-do-i-disable-brotli-content-encoding-in-chrome-ver-76-0-3809-100?hl=en

I would try replacing the Accept-Encoding HTTP header in the TChromium.OnBeforeResourceLoad event like this :
https://github.com/salvadordf/CEF4Delphi/blob/5ae265e9d3ce7076bda56c6429a642d5c76b83ef/source/uCEFChromiumCore.pas#L8308
Post Reply