Share via


CoreWebView2Profile.GetNonDefaultPermissionSettingsAsync Method

Definition

Invokes the handler with a collection of all nondefault permission settings.

public System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<Microsoft.Web.WebView2.Core.CoreWebView2PermissionSetting>> GetNonDefaultPermissionSettingsAsync ();
member this.GetNonDefaultPermissionSettingsAsync : unit -> System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<Microsoft.Web.WebView2.Core.CoreWebView2PermissionSetting>>
Public Function GetNonDefaultPermissionSettingsAsync () As Task(Of IReadOnlyList(Of CoreWebView2PermissionSetting))

Returns

Examples

async void WebView_PermissionManager_DOMContentLoaded(object sender,
    CoreWebView2DOMContentLoadedEventArgs arg)
{
    if (_iWebView2.CoreWebView2.Source !=
        "https://appassets.example/ScenarioPermissionManagement.html")
    {
        return;
    }
    try
    {
        // Gets the nondefault permission collection and updates a
        // custom permission management page.
        IReadOnlyList<CoreWebView2PermissionSetting> permissionList =
            await WebViewProfile.GetNonDefaultPermissionSettingsAsync();
        foreach (CoreWebView2PermissionSetting setting in permissionList)
        {
            string reply = "{\"PermissionSetting\": \"" +
                            NameOfPermissionKind(setting.PermissionKind) + ", " +
                            setting.PermissionOrigin + ", " +
                            PermissionStateToString(setting.PermissionState) +
                            "\"}";
            _iWebView2.CoreWebView2.PostWebMessageAsJson(reply);
        }
    }
    catch (NotImplementedException exception)
    {
        System.Threading.SynchronizationContext.Current.Post((_) =>
        {
            MessageBox.Show(this,
                "Permission manager not supported: " + exception.Message,
                "Permission Manager");
        }, null);
    }
}

Remarks

Use this method to get the permission state set in the current and previous sessions.

Applies to