MicrosoftEdge/WebView2Feedback

[Feature]: Setting a custom User Agent before a WebView navigates

Opened this issue · 0 comments

Describe the feature/enhancement you need

I'm trying to add a custom string to the end of the User Agent by using the property CoreWebView2Settings.UserAgent, but since this property can only be used after the CoreWebView2 is already created, the user agent won't be updated when a WebView2 control is created, and it navigates to a webpage. So, if a webpage gets the User Agent while it is loading, it will just be the default User Agent from WebView2.

Having a way to set the User Agent while creating the WebView2 control will cover this case so the webpage will always get the correct User Agent string.

The scenario/use case where you would use this feature

This is useful for when you are creating a new WebView to a webpage that gets and uses the User Agent right away. Like creating a new window while launching a url.

How important is this request to you?

Nice to have. There are other ways to tackle this, but having official API support would be beneficial.

Suggested implementation

There could be an option for a custom User Agent in the constructor of either the WebView2 or the CoreWebView2 used to set the property before the WebView starts navigating.

What does your app do? Is there a pending deadline for this request?

No response