Setting a WebView2 UserAgent isn't updated in the NavigationStarting event

Shipwreck Software 0 Reputation points
2025-07-29T23:23:11.3133333+00:00

I'm creating a simple C# WinUI3 app that uses WebView2 to connect to OpenStreetMaps. When I set a custom UserAgent on the WebView2.CoreWebView2, it doesn't get reflected in the RequestHeaders in the CoreWebView2NavigationStartingEventArgs object in the NavigationStarting event.

It's critical that I verify that I'm actually set the user agent (it's a requirement using OpenStreetMaps that I have a custom User-Agent in the headers).

What I expected is that when I look at the headers, the user-agent is set correctly. What I actually see is the default User-Agent (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0)

Windows development | Windows App SDK
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.