interface ICoreWebView2Settings2

Note

This reference is no longer being maintained. For the latest API reference, see WebView2 API Reference.

interface ICoreWebView2Settings2
  : public ICoreWebView2Settings

A continuation of the ICoreWebView2Settings interface that manages the user agent.

Summary

Members Descriptions
get_UserAgent Returns the User Agent.
put_UserAgent Sets the UserAgent property.

Applies to

Product Introduced
WebView2 Win32 1.0.864.35
WebView2 Win32 Prerelease 1.0.824

Members

get_UserAgent

Returns the User Agent.

public HRESULT get_UserAgent(LPWSTR * userAgent)

The default value is the default User Agent of the Microsoft Edge browser.

                if (m_settings2)
                {
                    static const PCWSTR url_compare_example = L"fourthcoffee.com";
                    wil::unique_bstr domain = GetDomainOfUri(uri.get());
                    const wchar_t* domains = domain.get();

                    if (wcscmp(url_compare_example, domains) == 0)
                    {
                        SetUserAgent(L"example_navigation_ua");
                    }
                }

put_UserAgent

Sets the UserAgent property.

public HRESULT put_UserAgent(LPCWSTR userAgent)

This property may be overridden if the User-Agent header is set in a request. If the parameter is empty the User Agent will not be updated and the current User Agent will remain.