@@ -25,7 +25,9 @@ m_webView->add_NavigationStarting(
2525 Callback<ICoreWebView2NavigationStartingEventHandler>(
2626 [this](ICoreWebView2 *sender,
2727 ICoreWebView2NavigationStartingEventArgs *args) -> HRESULT {
28- static const PCWSTR url_compare_example = L"foo.org";
28+ static const PCWSTR url_compare_example = L"fourthcoffee.com";
29+ wil::unique_cotaskmem_string uri;
30+ CHECK_FAILURE(args->get_Uri(&uri));
2931 wil::unique_bstr domain = GetDomainOfUri(uri.get());
3032 const wchar_t *domains = domain.get();
3133 wil::com_ptr<ICoreWebView2Settings> settings;
@@ -38,6 +40,7 @@ m_webView->add_NavigationStarting(
3840 // Change the user agent back to desktop
3941 CHECK_FAILURE(settings->put_UserAgent(GetDesktopUserAgent()));
4042 }
43+ CoTaskMemFree(temp_uri);
4144 return S_OK;
4245 })
4346 .Get(),
@@ -47,9 +50,19 @@ m_webView->add_NavigationStarting(
4750## .NET and WinRT
4851
4952```c #
50- private void SetUserAgent(CoreWebView2 sender, CoreWebView2UserAgentArgs e) {
53+ webView2Control.NavigationStarting += SetUserAgent;
54+ private void SetUserAgent(CoreWebView2 sender, CoreWebView2NavigationStartingEventArgs e)
55+ {
5156 var settings = webView2Control.CoreWebView2.Settings;
52- settings.UserAgent = GetUserAgent();
57+ // Note: Oversimplified test. Need to support idn, case-insensitivity, etc.
58+ if (new Uri(e.Uri).Host == "contoso.com")
59+ {
60+ settings.UserAgent = GetMobileUserAgent();
61+ }
62+ else
63+ {
64+ settings.UserAgent = GetDesktopUserAgent();
65+ }
5366}
5467```
5568
@@ -62,15 +75,15 @@ See [API Details](#api-details) section below for API reference.
6275## Win32 C++
6376
6477``` IDL
65- // This is the ICoreWebView2Settings Staging interface.
78+ // This is the ICoreWebView2Settings interface.
6679[uuid(c79ba37e-9bd6-4b9e-b460-2ced163f231f), object, pointer_default(unique)]
67- interface ICoreWebView2StagingSettings : IUnknown {
80+ interface ICoreWebView2Settings2 : ICoreWebView2Settings {
6881 /// `UserAgent` . Returns the User Agent. The default value is the
6982 /// default User Agent of the Edge browser.
7083 [propget] HRESULT UserAgent([ out, retval ] LPWSTR * userAgent);
7184 /// Sets the `UserAgentString` property. This property may be overriden if
72- /// the User-Agent header is set in a request. If the parameter is empty
73- /// the User Agent will not be updated and the current User Agent will remain.
85+ /// the User-Agent header is set in a request. If the parameter is empty
86+ /// the User Agent will not be updated and the current User Agent will remain.
7487 [propput] HRESULT UserAgent([in] LPCWSTR userAgent);
7588}
7689```
0 commit comments