Page 1 of 1

I can't change the Webview 4 header. Please fix it.

Posted: Fri Aug 30, 2024 7:38 am
by sodlf159
procedure TBrowserFrame.WVBrowser1WebResourceRequested(Sender: TObject;
const aWebView: ICoreWebView2;
const aArgs: ICoreWebView2WebResourceRequestedEventArgs);
var
TempArgs : TCoreWebView2WebResourceRequestedEventArgs;
RequestHeaders:ICoreWebView2HttpRequestHeaders;
begin
TempArgs:= TCoreWebView2WebResourceRequestedEventArgs.Create(aArgs);
try
TempArgs.Request.Get_Headers(RequestHeaders);
RequestHeaders.SetHeader('Accept-Language','zh-cn;q=0.8,en-US;q=0.9');

finally
TempArgs.Free ;
end;
end;

No response.

Re: I can't change the Webview 4 header. Please fix it.

Posted: Fri Aug 30, 2024 1:20 pm
by salvadordf
Hi,

WebView4Delphi is just a WebView2 wrapper.

If setting a new header is not working you should contact Microsoft at the WebView2 feedback repository and report the issue :
https://github.com/MicrosoftEdge/WebView2Feedback/issues

It should be possible to set the language and the accept-languages header with TWVBrowserBase.Language before creating the browser.
You can also set GlobalWebView2Loader.Language before the GlobalWebView2Loader.StartWebView2 call.

Re: I can't change the Webview 4 header. Please fix it.

Posted: Sat Aug 31, 2024 9:01 pm
by sodlf159
So does this mean that custom headers cannot be changed?

Re: I can't change the Webview 4 header. Please fix it.

Posted: Mon Sep 02, 2024 8:20 am
by salvadordf
The documentation states that the headers are mutable at that event but it wouldn't be the first time I see that Chromium or Edge don't allow us to modify some of them.

Re: I can't change the Webview 4 header. Please fix it.

Posted: Wed Oct 16, 2024 11:44 am
by sodlf159
procedure TMainForm.WVBrowser1AfterCreated(Sender: TObject);

WVBrowser1.AddWebResourceRequestedFilter('*', COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL);
WVBrowser1.AddWebResourceRequestedFilterWithRequestSourceKinds('*',COREWEBVIEW2_WEB_RESOURCE_CONTEXT_IMAGE, COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_ALL);
WVBrowser1.AddWebResourceRequestedFilterWithRequestSourceKinds('*',COREWEBVIEW2_WEB_RESOURCE_CONTEXT_MEDIA,COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_ALL);

It is solved by putting