Contents - Index - Top


AddWebResourceRequestedFilter

Interface AntView 

 

Type: Method

Parameters: String uri TxResourceContext resourceContext

Returns: Nothing

 

 

Add a resource filter for a specified URI.

The URI can be a wildcard, such as "*" if you want to filter every website.

Via resourceContext you can identify what kind of web resource should be filtered.

You can remove the filter again via RemoveWebResourceRequestedFilter.

When a filter has been added you can act on it via the OnWebResourceRequested event.

 

Here's an example in VB6 on how you can use AddWebResourceRequestedFilter.

 

Suppose you want to filter out all images for every URL so that you do not have to load them.

Start by adding a filter on completing creation of the WebView2 control.

 

Private Sub EdgeWebBrowser_OnCreateWebviewCompleted(ByVal HResult As Long)

  EdgeWebBrowser.AddWebResourceRequestedFilter "*", rcImage

End Sub

 

This will then trigger the OnWebResourceRequested event when a page is requested with an image.

We check the ResourceContext property on the Args object to see if it matches the filter for an image.

 

Private Sub EdgeWebBrowser_OnWebResourceRequested(ByVal Args As AntViewAx2.IAntViewWebResourceRequestedEventArgs)

  Dim NewResponse As AntViewWebResourceResponse

  

  If Args.ResourceContext = rcImage Then

    Set NewResponse = EdgeWebBrowser.CreateWebResourceResponse("", 403, "Blocked", "")

    Args.Response = NewResponse

  End If

End Sub

 

If the filter is matched we then proceed by creating our own response with HTTP status code 403 via the CreateWebResourceResponse method. 

Followed by passing that as the Response object back to the WebView2 control.

 

Introduced in AntView release 1.1.236

 

 


AntView - The MS Edge WebView2 ActiveX control Date last changed: 09/30/2024