If the method succeeds, the return value is the number of
characters in the User-Agent string, not including the terminating null
character. If the method fails, the return value is zero. To
get extended error information, call GetLastError.
The GetUserAgent method 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
with SetUserAgent.
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 capture and preserve the default
User-Agent string before setting a custom one.
If the lpszUserAgent parameter is NULL, the method
returns the length of the string in characters. This allows the caller to
allocate a buffer of the appropriate size before retrieving the value. When
a valid buffer is provided, the string copied to it will always be
null-terminated.
The User-Agent value applies to the entire lifetime of the
browser instance. Once it has been changed, all subsequent navigations will
use the new string until explicitly reset or the instance is destroyed.