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.

Accept-Language I can't change it.

Post Reply
sodlf159
Posts: 13
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: 13
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: 4079
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: 13
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: 4079
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.
Post Reply