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.
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.
I can't change the Webview 4 header. Please fix it.
- salvadordf
- Posts: 4563
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: I can't change the Webview 4 header. Please fix it.
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.
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.
So does this mean that custom headers cannot be changed?
- salvadordf
- Posts: 4563
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: I can't change the Webview 4 header. Please fix it.
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.
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
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