Compartilhar via


CoreWebView2.AddWebResourceRequestedFilter Method

Definition

Overloads

AddWebResourceRequestedFilter(String, CoreWebView2WebResourceContext)

Warning: This method is deprecated and does not behave as expected for iframes. Please use AddWebResourceRequestedFilter(String, CoreWebView2WebResourceContext, CoreWebView2WebResourceRequestSourceKinds) instead. Adds a URI and resource context filter for the WebResourceRequested event.

AddWebResourceRequestedFilter(String, CoreWebView2WebResourceContext, CoreWebView2WebResourceRequestSourceKinds)

AddWebResourceRequestedFilter(String, CoreWebView2WebResourceContext)

Warning: This method is deprecated and does not behave as expected for iframes. Please use AddWebResourceRequestedFilter(String, CoreWebView2WebResourceContext, CoreWebView2WebResourceRequestSourceKinds) instead. Adds a URI and resource context filter for the WebResourceRequested event.

public void AddWebResourceRequestedFilter (string uri, Microsoft.Web.WebView2.Core.CoreWebView2WebResourceContext ResourceContext);
member this.AddWebResourceRequestedFilter : string * Microsoft.Web.WebView2.Core.CoreWebView2WebResourceContext -> unit
Public Sub AddWebResourceRequestedFilter (uri As String, ResourceContext As CoreWebView2WebResourceContext)

Parameters

uri
String

An URI to be added to the WebResourceRequested event.

ResourceContext
CoreWebView2WebResourceContext

A resource context filter to be added to the WebResourceRequested event.

Remarks

A web resource request with a resource context that matches this filter's resource context and a URI that matches this filter's URI wildcard string will be raised via the WebResourceRequested event.

The uri parameter value is a wildcard string matched against the URI of the web resource request. This is a glob style wildcard string in which a * matches zero or more characters and a ? matches exactly one character. These wildcard characters can be escaped using a backslash just before the wildcard character in order to represent the literal * or ?.

The matching occurs over the URI as a whole string and not limiting wildcard matches to particular parts of the URI. The wildcard filter is compared to the URI after the URI has been normalized, any URI fragment has been removed, and non-ASCII hostnames have been converted to punycode.

Specifying a nullptr for the uri is equivalent to an empty string which matches no URIs.

For more information about resource context filters, navigate to CoreWebView2WebResourceContext.

| URI Filter String | Request URI | Match | Notes | | ---- | ---- | ---- | ---- | | `*` | `https://contoso.com/a/b/c` | Yes | A single * will match all URIs | | `*://contoso.com/*` | `https://contoso.com/a/b/c` | Yes | Matches everything in contoso.com across all schemes | | `*://contoso.com/*` | `https://example.com/?https://contoso.com/` | Yes | But also matches a URI with just the same text anywhere in the URI | | `example` | `https://contoso.com/example` | No | The filter does not perform partial matches | | `*example` | `https://contoso.com/example` | Yes | The filter matches across URI parts | | `*example` | `https://contoso.com/path/?example` | Yes | The filter matches across URI parts | | `*example` | `https://contoso.com/path/?query#example` | No | The filter is matched against the URI with no fragment | | `*example` | `https://example` | No | The URI is normalized before filter matching so the actual URI used for comparison is `https://example.com/` | | `*example/` | `https://example` | Yes | Just like above, but this time the filter ends with a / just like the normalized URI | | `https://xn--qei.example/` | `https://❤.example/` | Yes | Non-ASCII hostnames are normalized to punycode before wildcard comparison | | `https://❤.example/` | `https://xn--qei.example/` | No | Non-ASCII hostnames are normalized to punycode before wildcard comparison |

See also

Applies to

AddWebResourceRequestedFilter(String, CoreWebView2WebResourceContext, CoreWebView2WebResourceRequestSourceKinds)

public void AddWebResourceRequestedFilter (string uri, Microsoft.Web.WebView2.Core.CoreWebView2WebResourceContext ResourceContext, Microsoft.Web.WebView2.Core.CoreWebView2WebResourceRequestSourceKinds RequestSourceKinds);
public void AddWebResourceRequestedFilter (string uri, Microsoft.Web.WebView2.Core.CoreWebView2WebResourceContext ResourceContext, Microsoft.Web.WebView2.Core.CoreWebView2WebResourceRequestSourceKinds requestSourceKinds);
member this.AddWebResourceRequestedFilter : string * Microsoft.Web.WebView2.Core.CoreWebView2WebResourceContext * Microsoft.Web.WebView2.Core.CoreWebView2WebResourceRequestSourceKinds -> unit
member this.AddWebResourceRequestedFilter : string * Microsoft.Web.WebView2.Core.CoreWebView2WebResourceContext * Microsoft.Web.WebView2.Core.CoreWebView2WebResourceRequestSourceKinds -> unit
Public Sub AddWebResourceRequestedFilter (uri As String, ResourceContext As CoreWebView2WebResourceContext, RequestSourceKinds As CoreWebView2WebResourceRequestSourceKinds)
Public Sub AddWebResourceRequestedFilter (uri As String, ResourceContext As CoreWebView2WebResourceContext, requestSourceKinds As CoreWebView2WebResourceRequestSourceKinds)

Parameters

uri
String

A URI to be added to the WebResourceRequested event.

ResourceContext
CoreWebView2WebResourceContext

A resource context filter to be added to the WebResourceRequested event.

RequestSourceKindsrequestSourceKinds
CoreWebView2WebResourceRequestSourceKinds

A request source filter to be added to the WebResourceRequested event.

Remarks

The uri parameter value is a wildcard string matched against the URI of the web resource request. This is a glob style wildcard string in which a * matches zero or more characters and a ? matches exactly one character. These wildcard characters can be escaped using a backslash just before the wildcard character in order to represent the literal * or ?. The matching occurs over the URI as a whole string and not limiting wildcard matches to particular parts of the URI. The wildcard filter is compared to the URI after the URI has been normalized, any URI fragment has been removed, and non-ASCII hostnames have been converted to punycode. Specifying a null for the uri is equivalent to an empty string which matches no URIs. For more information about resource context filters, navigate to CoreWebView2WebResourceContext.

| URI Filter String | Request URI | Match | Notes | | ---- | ---- | ---- | ---- | | `*` | `https://contoso.com/a/b/c` | Yes | A single * will match all URIs | | `*://contoso.com/*` | `https://contoso.com/a/b/c` | Yes | Matches everything in contoso.com across all schemes | | `*://contoso.com/*` | `https://example.com/?https://contoso.com/` | Yes | But also matches a URI with just the same text anywhere in the URI | | `example` | `https://contoso.com/example` | No | The filter does not perform partial matches | | `*example` | `https://contoso.com/example` | Yes | The filter matches across URI parts | | `*example` | `https://contoso.com/path/?example` | Yes | The filter matches across URI parts | | `*example` | `https://contoso.com/path/?query#example` | No | The filter is matched against the URI with no fragment | | `*example` | `https://example` | No | The URI is normalized before filter matching so the actual URI used for comparison is `https://example.com/` | | `*example/` | `https://example` | Yes | Just like above, but this time the filter ends with a / just like the normalized URI | | `https://xn--qei.example/` | `https://❤.example/` | Yes | Non-ASCII hostnames are normalized to punycode before wildcard comparison | | `https://❤.example/` | `https://xn--qei.example/` | No | Non-ASCII hostnames are normalized to punycode before wildcard comparison | To form the requestSourceKinds parameter OR operation(s) can be applied to multiple CoreWebView2WebResourceRequestSourceKinds to create a mask representing those source kinds. API will fail with E_INVALIDARG if requestSourceKinds equals to zero. Because service workers and shared workers run separately from any one HTML document their WebResourceRequested will be raised for all CoreWebView2s that have appropriate filters added in the corresponding CoreWebView2Environment. You should only add a WebResourceRequested filter for ServiceWorker or SharedWorker on one CoreWebView2 to avoid handling the same WebResourceRequested event multiple times.

Applies to