interface ICoreWebView2Profile3

Note

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

interface ICoreWebView2Profile3
  : public ICoreWebView2Profile2

This is an extension of the ICoreWebView2Profile interface to control levels of tracking prevention.

Summary

Members Descriptions
get_PreferredTrackingPreventionLevel Gets the PreferredTrackingPreventionLevel property.
put_PreferredTrackingPreventionLevel The PreferredTrackingPreventionLevel property allows you to control levels of tracking prevention for WebView2 which are associated with a profile.

Applies to

Product Introduced
WebView2 Win32 1.0.1661.34
WebView2 Win32 Prerelease 1.0.1619

Members

get_PreferredTrackingPreventionLevel

Gets the PreferredTrackingPreventionLevel property.

public HRESULT get_PreferredTrackingPreventionLevel(COREWEBVIEW2_TRACKING_PREVENTION_LEVEL * value)

put_PreferredTrackingPreventionLevel

The PreferredTrackingPreventionLevel property allows you to control levels of tracking prevention for WebView2 which are associated with a profile.

public HRESULT put_PreferredTrackingPreventionLevel(COREWEBVIEW2_TRACKING_PREVENTION_LEVEL value)

This level would apply to the context of the profile. That is, all WebView2s sharing the same profile will be affected and also the value is persisted in the user data folder.

See COREWEBVIEW2_TRACKING_PREVENTION_LEVEL for descriptions of levels.

If tracking prevention feature is enabled when creating the WebView2 environment, you can also disable tracking prevention later using this property and COREWEBVIEW2_TRACKING_PREVENTION_LEVEL_NONE value but that doesn't improves runtime performance.

There is ICoreWebView2EnvironmentOptions5::EnableTrackingPrevention property to enable/disable tracking prevention feature for all the WebView2's created in the same environment. If enabled, PreferredTrackingPreventionLevel is set to COREWEBVIEW2_TRACKING_PREVENTION_LEVEL_BALANCED by default for all the WebView2's and profiles created in the same environment or is set to the level whatever value was last changed/persisted to the profile. If disabled PreferredTrackingPreventionLevel is not respected by WebView2. If PreferredTrackingPreventionLevel is set when the feature is disabled, the property value get changed and persisted but it will takes effect only if ICoreWebView2EnvironmentOptions5::EnableTrackingPrevention is true.

See ICoreWebView2EnvironmentOptions5::EnableTrackingPrevention for more details.

void SettingsComponent::SetTrackingPreventionLevel(COREWEBVIEW2_TRACKING_PREVENTION_LEVEL value)
{
    wil::com_ptr<ICoreWebView2_13> webView2_13;
    webView2_13 = m_webView.try_query<ICoreWebView2_13>();

    if (webView2_13)
    {
        wil::com_ptr<ICoreWebView2Profile> profile;
        CHECK_FAILURE(webView2_13->get_Profile(&profile));

        auto profile3 = profile.try_query<ICoreWebView2Profile3>();
        if (profile3)
        {
            CHECK_FAILURE(profile3->put_PreferredTrackingPreventionLevel(value));
            MessageBox(
                nullptr, L"Tracking prevention level is set successfully",
                L"Tracking Prevention Level", MB_OK);
        }
    }
}