I need set custom UA and I use
httpRequestMessage.Headers.Add("User-Agent", "blahblah");
theWebView.NavigateWithHttpRequestMessage(httpRequestMessage);
But if I click any link on page this UA erased and set default UA.
I found same question WebView - Define User-Agent on every request but maybe it fixed in 1607?
WebView is not a general-purpose browser, it does have some "limitations" that not supported now. There is no API can set the default User-Agent that used in every request. As a workaround we can use WebView.NavigationStarting event along with WebView.NavigateWithHttpRequestMessage method to set User-Agent in every request.
For more information about how to do this, please refer to this answer. The key point here is removing handler for
NavigationStarting
event and cancelling navigation in the original request and then adding the handler afterNavigateWithHttpRequestMessage
to make sureNavigationStarting
event can capture next requests like following:Also, you are welcome to vote on UserVoice to share your feedback.