UserAgent Property  
 

Sets or returns the user-agent string used for requests made by this instance.

Syntax

object.UserAgent [= value ]

Remarks

The UserAgent property retrieves the current user-agent string used by this browser instance. This value is the exact string sent in the user-agent header of outgoing HTTP requests and is determined by the underlying Microsoft Edge WebView2 runtime unless explicitly changed. The returned value can be used for informational purposes, such as logging the client identity or displaying diagnostic information to the user. It is also useful if your application needs to preserve the default user-agent string before setting a custom one.

Setting this property changes the string that will be sent in the user-agent header for all subsequent HTTP requests made by this browser instance. This property should always be used to modify the user-agent header value; you should not set the header directly using the SetHeader method.

Applications may want to override the default user-agent in several scenarios:

  • Requesting a mobile or tablet version of a site by providing a user-agent string that identifies as a mobile browser.
  • Emulating a different browser for testing purposes.
  • Including custom product tokens identifying the host application to the server.

The general format of a user-agent string follows the conventions described in RFC 9110:

User-Agent: product / version (comment) [ product / version ... ]

For example, a typical user-agent string might look like:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0

This value is global to the control instance. Once changed, it will remain in effect until explicitly reset or until the browser control is destroyed. When setting a custom user-agent value, developers should ensure it is a syntactically valid string. Some websites may reject requests or provide degraded functionality if the value is malformed or omits key tokens.

If you want to change the user-agent string to identify your application, it is recommended that you append your application name and version to the default value.

Data Type

String

See Also

GetHeader Method, Navigate Method, SetHeader Method