public sealed record DesktopWebContentPolicy : IEquatable<DesktopWebContentPolicy> Controls what an embedded window (WebView2, WKWebView, WebKitGTK and the WPF RunicWebView) does with navigation away from the application, new windows, downloads and developer tools.
Remarks
The application's origins are the origin of the presented surface and its DesktopSecurityPolicy.AdditionalOrigins; their documents always load in the window, and iframes are not affected. A new-window request (target="_blank", window.open) never opens a second WebView window: one for an application origin is cancelled, and other URLs follow DesktopWebContentPolicy.ExternalNavigation. Open further application windows from .NET. Installed browsers apply their own navigation and download behaviour.
Constructors
DesktopWebContentPolicy
public DesktopWebContentPolicy() No documentation.
Properties
AllowDownloads
public bool AllowDownloads { get; init; } Gets whether the page may download files. Downloads are cancelled by default.
Remarks
When true, WebView2 and WebKitGTK download with their own behaviour: WebView2 shows its download dialog; WebKitGTK saves <a download> links and Content-Disposition: attachment responses to the user's download folder and still ignores other content it cannot show. The macOS window saves <a download> links, attachments and responses WKWebView cannot show to the user's Downloads folder under the suggested name, as name (1).ext rather than replace an existing file, and marks them with the quarantine of web downloads. A sandboxed macOS application needs the com.apple.security.files.downloads.read-write entitlement for that folder.
Default
public static DesktopWebContentPolicy Default { get; } Gets the safe default: external links open in the default browser, downloads are refused, and developer tools are available only in Development.
DevTools
public bool? DevTools { get; init; } Gets whether the window's developer tools (F12, Inspect Element, Safari's Web Inspector) are available, or null, the default, for only when DOTNET_ENVIRONMENT, or else ASPNETCORE_ENVIRONMENT, is Development.
Remarks
dotnet runic dev runs the application in Development. Developer tools give whoever uses them full access to the page and its Bridge. WKWebView supports them from macOS 13.3.
ExternalNavigation
public DesktopExternalNavigation ExternalNavigation { get; init; } Gets what a navigation or new-window request outside the application's origins does.