Freigeben über


CoreWebView2CustomSchemeRegistration Class

Represents the registration of a custom scheme with the CoreWebView2Environment. This allows the WebView2 app to be able to handle CoreWebView2.WebResourceRequested event for requests with the specified scheme and be able to navigate the WebView2 to the custom scheme. Once the environment is created, the registrations are valid and immutable throughout the lifetime of the associated WebView2s' browser process and any WebView2 environments sharing the browser process must be created with identical custom scheme registrations, otherwise the environment creation will fail. Any further attempts to register the same scheme will fail during environment creation. The URIs of registered custom schemes will be treated similar to http URIs for their origins. They will have tuple origins for URIs with host and opaque origins for URIs without host as specified in 7.5 Origin - HTML Living Standard.

Example:

custom-scheme-with-host://hostname/path/to/resource has origin of custom-scheme-with-host://hostname. custom-scheme-without-host:path/to/resource has origin of custom-scheme-without-host:path/to/resource.

For CoreWebView2.WebResourceRequested event, the cases of request URIs and filter URIs with custom schemes will be normalized according to generic URI syntax rules. Any non-ASCII characters will be preserved. The registered custom schemes also participate in CORS and adheres to CSP. The app needs to set the appropriate access headers in its CoreWebView2.WebResourceRequested event handler to allow CORS requests.

Summary

Members Description
AllowedOrigins List of origins that are allowed to issue requests with the custom scheme, such as XHRs and subresource requests that have an Origin header.
HasAuthorityComponent Set this property to true if the URIs with this custom scheme will have an authority component (a host for custom schemes).
SchemeName The scheme name.
TreatAsSecure Whether the sites with this scheme will be treated as a Secure Context like an HTTPS site. This flag is only effective when CoreWebView2CustomSchemeRegistration.HasAuthorityComponent is also set to true.
CoreWebView2CustomSchemeRegistration Initializes a new instance of the CoreWebView2CustomSchemeRegistration class.

Properties

AllowedOrigins

readonly IVector<string> AllowedOrigins

List of origins that are allowed to issue requests with the custom scheme, such as XHRs and subresource requests that have an Origin header.

HasAuthorityComponent

bool HasAuthorityComponent

Set this property to true if the URIs with this custom scheme will have an authority component (a host for custom schemes). Specifically, if you have a URI of the following form you should set the HasAuthorityComponent value as listed.

URI Recommended HasAuthorityComponent value
custom-scheme-with-authority://host/path true
custom-scheme-without-authority:path false

When this property is set to true, the URIs with this scheme will be interpreted as having a scheme and host origin similar to an http URI. Note that the port and user information are never included in the computation of origins for custom schemes. If this property is set to false, URIs with this scheme will have an opaque origin similar to a data URI. This property is false by default. Note: For custom schemes registered as having authority component, navigations to URIs without authority of such custom schemes will fail. However, if the content inside WebView2 references a subresource with a URI that does not have an authority component, but of a custom scheme that is registered as having authority component, the URI will be interpreted as a relative path as specified in RFC3986. For example, custom-scheme-with-authority:path will be interpreted as custom-scheme-with-authority://host/path. However, this behavior cannot be guaranteed to remain in future releases so it is recommended not to rely on this behavior.

SchemeName

readonly string SchemeName

The scheme name.

TreatAsSecure

int TreatAsSecure

Whether the sites with this scheme will be treated as a Secure Context like an HTTPS site. This flag is only effective when CoreWebView2CustomSchemeRegistration.HasAuthorityComponent is also set to true. false by default.

Constructors

CoreWebView2CustomSchemeRegistration

CoreWebView2CustomSchemeRegistration(string schemeName)

Initializes a new instance of the CoreWebView2CustomSchemeRegistration class.