From 3e0333d4049106b239097747010f966b167b1c2e Mon Sep 17 00:00:00 2001 From: WebView2 Github Bot Date: Tue, 13 Jan 2026 04:34:02 +0000 Subject: [PATCH 1/2] Updates for Win32, WPF, WinForms, UWP and WinUI3 sample apps from 145.0.3796.0 --- SampleApps/WebView2APISample/AppWindow.h | 1 + .../WebView2APISample/ScriptComponent.cpp | 27 ------------- .../WebView2APISample/SettingsComponent.cpp | 39 +++++++++++++++++++ .../WebView2APISample/SettingsComponent.h | 2 + .../WebView2APISample/WebView2APISample.rc | 5 +++ .../WebView2APISample.vcxproj | 4 +- SampleApps/WebView2APISample/resource.h | 2 + SampleApps/WebView2WpfBrowser/MainWindow.xaml | 9 +++++ .../WebView2WpfBrowser/MainWindow.xaml.cs | 35 ++++++++++------- 9 files changed, 80 insertions(+), 44 deletions(-) diff --git a/SampleApps/WebView2APISample/AppWindow.h b/SampleApps/WebView2APISample/AppWindow.h index 92d50a12..5b1cf2ea 100644 --- a/SampleApps/WebView2APISample/AppWindow.h +++ b/SampleApps/WebView2APISample/AppWindow.h @@ -242,6 +242,7 @@ class AppWindow bool SuppressDefaultFindDialog(); bool IsCaseSensitive(); wil::com_ptr SetDefaultFindOptions(); + void SetupFindEventHandlers(wil::com_ptr webView2find); // Find on Page member std::wstring m_findOnPageLastSearchTerm; diff --git a/SampleApps/WebView2APISample/ScriptComponent.cpp b/SampleApps/WebView2APISample/ScriptComponent.cpp index 89ce9ee7..62e98745 100644 --- a/SampleApps/WebView2APISample/ScriptComponent.cpp +++ b/SampleApps/WebView2APISample/ScriptComponent.cpp @@ -649,33 +649,6 @@ void ScriptComponent::HandleCDPTargets() .Get(), &m_targetDetachedToken)); receiver.reset(); - CHECK_FAILURE( - m_webView->GetDevToolsProtocolEventReceiver(L"Target.targetCreated", &receiver)); - CHECK_FAILURE(receiver->add_DevToolsProtocolEventReceived( - Callback( - [this]( - ICoreWebView2* sender, - ICoreWebView2DevToolsProtocolEventReceivedEventArgs* args) -> HRESULT - { - // Shared worker targets are not auto attached. Have to attach it explicitly. - wil::unique_cotaskmem_string jsonMessage; - CHECK_FAILURE(args->get_ParameterObjectAsJson(&jsonMessage)); - std::wstring type = GetJSONStringField(jsonMessage.get(), L"type"); - if (type == L"shared_worker") - { - std::wstring targetId = GetJSONStringField(jsonMessage.get(), L"targetId"); - std::wstring parameters = - L"{\"targetId\":\"" + targetId + L"\",\"flatten\": true}"; - // Call Target.attachToTarget and ignore returned value, let - // Target.attachedToTarget to handle the result. - m_webView->CallDevToolsProtocolMethod( - L"Target.attachToTarget", parameters.c_str(), nullptr); - } - return S_OK; - }) - .Get(), - &m_targetCreatedToken)); - receiver.reset(); CHECK_FAILURE( m_webView->GetDevToolsProtocolEventReceiver(L"Target.targetInfoChanged", &receiver)); CHECK_FAILURE(receiver->add_DevToolsProtocolEventReceived( diff --git a/SampleApps/WebView2APISample/SettingsComponent.cpp b/SampleApps/WebView2APISample/SettingsComponent.cpp index 5e9d2cd7..c0e5ceab 100644 --- a/SampleApps/WebView2APISample/SettingsComponent.cpp +++ b/SampleApps/WebView2APISample/SettingsComponent.cpp @@ -1291,6 +1291,12 @@ bool SettingsComponent::HandleWindowMessage( case IDM_TRACKING_PREVENTION_LEVEL_STRICT: SetTrackingPreventionLevel(COREWEBVIEW2_TRACKING_PREVENTION_LEVEL_STRICT); return true; + case IDM_ENHANCED_SECURITY_MODE_LEVEL_OFF: + SetEnhancedSecurityModeLevel(COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL_OFF); + return true; + case IDM_ENHANCED_SECURITY_MODE_LEVEL_STRICT: + SetEnhancedSecurityModeLevel(COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL_STRICT); + return true; case ID_SETTINGS_NON_CLIENT_REGION_SUPPORT_ENABLED: { //![ToggleNonClientRegionSupportEnabled] @@ -1298,6 +1304,7 @@ bool SettingsComponent::HandleWindowMessage( wil::com_ptr settings; settings = m_settings.try_query(); CHECK_FEATURE_RETURN(settings); + CHECK_FAILURE( settings->get_IsNonClientRegionSupportEnabled(&nonClientRegionSupportEnabled)); if (nonClientRegionSupportEnabled) @@ -1807,6 +1814,38 @@ void SettingsComponent::SetTrackingPreventionLevel(COREWEBVIEW2_TRACKING_PREVENT } //! [SetTrackingPreventionLevel] +//! [SetEnhancedSecurityModeLevel] +void SettingsComponent::SetEnhancedSecurityModeLevel( + COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL value) +{ + wil::com_ptr webView2_13; + webView2_13 = m_webView.try_query(); + + if (webView2_13) + { + wil::com_ptr profile; + CHECK_FAILURE(webView2_13->get_Profile(&profile)); + + auto experimentalProfile9 = profile.try_query(); + if (experimentalProfile9) + { + CHECK_FAILURE(experimentalProfile9->put_EnhancedSecurityModeLevel(value)); + + const wchar_t* levelText = L"Off"; + if (value == COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL_STRICT) + { + levelText = L"Strict"; + } + + MessageBox( + nullptr, + (std::wstring(L"Enhanced Security Mode level is set to ") + levelText).c_str(), + L"Enhanced Security Mode Level", MB_OK); + } + } +} +//! [SetEnhancedSecurityModeLevel] + SettingsComponent::~SettingsComponent() { m_webView->remove_NavigationStarting(m_navigationStartingToken); diff --git a/SampleApps/WebView2APISample/SettingsComponent.h b/SampleApps/WebView2APISample/SettingsComponent.h index 6946d0f1..109328be 100644 --- a/SampleApps/WebView2APISample/SettingsComponent.h +++ b/SampleApps/WebView2APISample/SettingsComponent.h @@ -46,6 +46,8 @@ class SettingsComponent : public ComponentBase void SetTrackingPreventionLevel(COREWEBVIEW2_TRACKING_PREVENTION_LEVEL value); + void SetEnhancedSecurityModeLevel(COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL value); + ~SettingsComponent() override; private: diff --git a/SampleApps/WebView2APISample/WebView2APISample.rc b/SampleApps/WebView2APISample/WebView2APISample.rc index c3d206cb..5904d534 100644 --- a/SampleApps/WebView2APISample/WebView2APISample.rc +++ b/SampleApps/WebView2APISample/WebView2APISample.rc @@ -165,6 +165,11 @@ BEGIN MENUITEM "Balanced", IDM_TRACKING_PREVENTION_LEVEL_BALANCED MENUITEM "Strict", IDM_TRACKING_PREVENTION_LEVEL_STRICT END + POPUP "Enhanced Security Mode Level" + BEGIN + MENUITEM "Off", IDM_ENHANCED_SECURITY_MODE_LEVEL_OFF + MENUITEM "Strict", IDM_ENHANCED_SECURITY_MODE_LEVEL_STRICT + END MENUITEM "Toggle Non-Client Region Support", ID_SETTINGS_NON_CLIENT_REGION_SUPPORT_ENABLED END POPUP "&View" diff --git a/SampleApps/WebView2APISample/WebView2APISample.vcxproj b/SampleApps/WebView2APISample/WebView2APISample.vcxproj index 8f85c4e3..d346e0b9 100644 --- a/SampleApps/WebView2APISample/WebView2APISample.vcxproj +++ b/SampleApps/WebView2APISample/WebView2APISample.vcxproj @@ -1,4 +1,4 @@ - + @@ -541,4 +541,4 @@ - + \ No newline at end of file diff --git a/SampleApps/WebView2APISample/resource.h b/SampleApps/WebView2APISample/resource.h index 89dd78b8..d2474cdc 100644 --- a/SampleApps/WebView2APISample/resource.h +++ b/SampleApps/WebView2APISample/resource.h @@ -126,6 +126,8 @@ #define IDC_EDIT_SAVE_AS_FILENAME 262 #define IDC_CHECK_SAVE_AS_ALLOW_REPLACE 263 #define IDC_SAVE_AS_KIND 264 +#define IDM_ENHANCED_SECURITY_MODE_LEVEL_OFF 265 +#define IDM_ENHANCED_SECURITY_MODE_LEVEL_STRICT 266 #define IDM_TOGGLE_TOPMOST_WINDOW 300 #define IDM_PROCESS_EXTENDED_INFO 301 #define IDE_ADDRESSBAR 1000 diff --git a/SampleApps/WebView2WpfBrowser/MainWindow.xaml b/SampleApps/WebView2WpfBrowser/MainWindow.xaml index a36444fe..55d27cc8 100644 --- a/SampleApps/WebView2WpfBrowser/MainWindow.xaml +++ b/SampleApps/WebView2WpfBrowser/MainWindow.xaml @@ -78,6 +78,9 @@ found in the LICENSE file. + + + @@ -201,6 +204,12 @@ found in the LICENSE file. + + + + + + diff --git a/SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs b/SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs index a7f31cda..7d564f6f 100644 --- a/SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs +++ b/SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs @@ -83,10 +83,6 @@ public partial class MainWindow : Window public static RoutedCommand ExtensionsCommand = new RoutedCommand(); public static RoutedCommand TrackingPreventionLevelCommand = new RoutedCommand(); public static RoutedCommand EnhancedSecurityModeLevelCommand = new RoutedCommand(); - public static RoutedCommand EnhancedSecurityModeGetBypassListCommand = new RoutedCommand(); - public static RoutedCommand EnhancedSecurityModeSetBypassListCommand = new RoutedCommand(); - public static RoutedCommand EnhancedSecurityModeGetEnforceListCommand = new RoutedCommand(); - public static RoutedCommand EnhancedSecurityModeSetEnforceListCommand = new RoutedCommand(); public static RoutedCommand WebRtcUdpPortConfigCommand = new RoutedCommand(); public static RoutedCommand PrintDialogCommand = new RoutedCommand(); public static RoutedCommand PrintToDefaultPrinterCommand = new RoutedCommand(); @@ -1022,22 +1018,31 @@ void SetTrackingPreventionLevel(CoreWebView2TrackingPreventionLevel value) } // - void EnhancedSecurityModeLevelCommandExecuted(object target, ExecutedRoutedEventArgs e) { +#if USE_WEBVIEW2_EXPERIMENTAL + string level = e.Parameter.ToString(); + if (level == "Off") + { + SetEnhancedSecurityModeLevel(CoreWebView2EnhancedSecurityModeLevel.Off); + } + else + { + SetEnhancedSecurityModeLevel(CoreWebView2EnhancedSecurityModeLevel.Strict); + } +#endif } - void EnhancedSecurityModeGetBypassListCommandExecuted(object target, ExecutedRoutedEventArgs e) - { - } - void EnhancedSecurityModeSetBypassListCommandExecuted(object target, ExecutedRoutedEventArgs e) - { - } - void EnhancedSecurityModeGetEnforceListCommandExecuted(object target, ExecutedRoutedEventArgs e) - { - } - void EnhancedSecurityModeSetEnforceListCommandExecuted(object target, ExecutedRoutedEventArgs e) + +#if USE_WEBVIEW2_EXPERIMENTAL + // + void SetEnhancedSecurityModeLevel(CoreWebView2EnhancedSecurityModeLevel value) { + WebViewProfile.EnhancedSecurityModeLevel = value; + MessageBox.Show(this, "Enhanced security mode level is set successfully", "Enhanced Security Mode Level"); } + // +#endif + void WebRtcUdpPortConfigCommandExecuted(object target, ExecutedRoutedEventArgs e) { #if USE_WEBVIEW2_EXPERIMENTAL From 9cc9b4a70a892eb3030ff91e6ccd955228cb8315 Mon Sep 17 00:00:00 2001 From: WebView2 Github Bot Date: Tue, 13 Jan 2026 04:34:24 +0000 Subject: [PATCH 2/2] Updated package version for Win32, WPF and WinForms sample apps to 1.0.3796-prerelease --- SampleApps/WebView2APISample/WebView2APISample.vcxproj | 8 ++++---- SampleApps/WebView2APISample/packages.config | 2 +- .../WebView2WindowsFormsBrowser.csproj | 2 +- SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/SampleApps/WebView2APISample/WebView2APISample.vcxproj b/SampleApps/WebView2APISample/WebView2APISample.vcxproj index d346e0b9..ec3c5d66 100644 --- a/SampleApps/WebView2APISample/WebView2APISample.vcxproj +++ b/SampleApps/WebView2APISample/WebView2APISample.vcxproj @@ -1,4 +1,4 @@ - + @@ -532,13 +532,13 @@ - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + - \ No newline at end of file + diff --git a/SampleApps/WebView2APISample/packages.config b/SampleApps/WebView2APISample/packages.config index 69420a64..f3a3bf64 100644 --- a/SampleApps/WebView2APISample/packages.config +++ b/SampleApps/WebView2APISample/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/SampleApps/WebView2WindowsFormsBrowser/WebView2WindowsFormsBrowser.csproj b/SampleApps/WebView2WindowsFormsBrowser/WebView2WindowsFormsBrowser.csproj index a53e9618..a54a57ff 100644 --- a/SampleApps/WebView2WindowsFormsBrowser/WebView2WindowsFormsBrowser.csproj +++ b/SampleApps/WebView2WindowsFormsBrowser/WebView2WindowsFormsBrowser.csproj @@ -25,7 +25,7 @@ AnyCPU - + diff --git a/SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj b/SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj index 9e94ff27..ffde1d81 100644 --- a/SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj +++ b/SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj @@ -61,7 +61,7 @@ - +