Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VB6: AddWebResourceRequestedFilter and ico, svg not blocked
#1
Hi. 

I started using the AddWebResourceRequestedFilter method on v1.1.270 build OCX.
It seems to be super for my needs. However, I noticed that when it blocks rcImage and rcMedia
it still downloads graphics in ICO and SVG format.

I use code like this:

antView.AddWebResourceRequestedFilter "*", rcImage
antView .AddWebResourceRequestedFilter "*", rcMedia


Private Sub antView_OnWebResourceRequested(ByVal Args As AntViewAx.IAntViewWebResourceRequestedEventArgs)

  Dim NewResponse As AntViewWebResourceResponse
  If Args.ResourceContext = rcImage Then
    Set NewResponse = wbEdge.CreateWebResourceResponse("", 403, "Blocked", "")
    Args.Response = NewResponse
    Exit Sub
  End If

  If Args.ResourceContext = rcMedia Then
    Set NewResponse = wbEdge.CreateWebResourceResponse("", 403, "Blocked", "")
    Args.Response = NewResponse
  End If

End Sub

Results preview code

Private Sub AntView_OnWebResourceResponseReceived(ByVal Request As AntViewAx.IAntViewWebResourceRequest, ByVal Response As AntViewAx.IAntViewWebResourceResponseView)

 If Response.StatusCode <> 403 Then
    Debug.Print Response.StatusCode & " - " & Request.URI
     'Status: 200 - https://www.interia.pl/favicon.svg
     'Status: 200 - https://www.interia.pl/favicon.ico
End If

End Sub

Am I doing something wrong or maybe favicon can't be blocked through rcImage/rcMedia?

Best regards
Przemek
Reply
#2
Hi Przemek,

Looks like Microsoft determined those are not image or media files.

In order to figure that out I adjusted your code a bit like so:
Code:
Private Sub EdgeWebBrowser_OnWebResourceRequested(ByVal Args As AntViewAx.IAntViewWebResourceRequestedEventArgs)

  Dim NewResponse As AntViewWebResourceResponse
  If Args.ResourceContext = rcImage Then
    Set NewResponse = EdgeWebBrowser.CreateWebResourceResponse("", 403, "Blocked", "")
    Args.Response = NewResponse
    Exit Sub
  End If

  If Args.ResourceContext = rcMedia Then
    Set NewResponse = EdgeWebBrowser.CreateWebResourceResponse("", 403, "Blocked", "")
    Args.Response = NewResponse
    Exit Sub
  End If

  If Args.ResourceContext = rcScript Then
    Set NewResponse = EdgeWebBrowser.CreateWebResourceResponse("", 403, "Blocked", "")
    Args.Response = NewResponse
    Exit Sub
  End If

  If Args.ResourceContext = rcStylesheet Then
    Set NewResponse = EdgeWebBrowser.CreateWebResourceResponse("", 403, "Blocked", "")
    Args.Response = NewResponse
    Exit Sub
  End If

  If Args.ResourceContext = rcFont Then
    Set NewResponse = EdgeWebBrowser.CreateWebResourceResponse("", 403, "Blocked", "")
    Args.Response = NewResponse
    Exit Sub
  End If

  'If Args.ResourceContext = rcOther Then
  '  Set NewResponse = EdgeWebBrowser.CreateWebResourceResponse("", 403, "Blocked", "")
  '  Args.Response = NewResponse
  '  Exit Sub
  'End If
 
  Debug.Print Args.Request.URI & " - " & Args.ResourceContext
 
End Sub

Private Sub EdgeWebBrowser_OnWebResourceResponseReceived(ByVal Request As AntViewAx.IAntViewWebResourceRequest, ByVal Response As AntViewAx.IAntViewWebResourceResponseView)
If Response.StatusCode <> 403 Then
    Debug.Print Response.StatusCode & " - " & Request.URI
     'Status: 200 - https://www.interia.pl/favicon.svg
     'Status: 200 - https://www.interia.pl/favicon.ico
End If
End Sub

Private Sub TestButton_Click()
  EdgeWebBrowser.WebResourceResponseReceivedEnabled = True
  EdgeWebBrowser.AddWebResourceRequestedFilter "*", rcAll
End Sub

So basically I'm using the first debug.print to find out what the resourceContext is that Microsoft assigned for the file type.

This tells me that an svg file is declared as rcOther as is a favicon.ico.

You can see this as it reports the following in the output window:
Code:
https://www.antwise.com/ - 1
200 - https://www.antwise.com/
200 - https://www.antwise.com/css/reset.css
200 - https://www.antwise.com/css/screen.css
200 - https://www.antwise.com/images/siteid.png
200 - https://www.antwise.com/images/opensource.png
200 - https://www.antwise.com/images/banner.png
200 - https://www.antwise.com/images/footer.png
https://www.antwise.com/favicon.ico - 16
200 - https://www.antwise.com/favicon.ico
So code 16 for the favicon.
If you look at up here: https://doc.antview.dev/hs335.htm then you'll notice that 16 = rcOther.

Same thing if you go to your website and look for the .svg file in the debug output.

Also note that you can't seem to block images if they are streamed as imagedata.
--
Wil
Reply
#3
(2023-08-08, 13:45:13)wila Wrote: Also note that you can't seem to block images if they are streamed as imagedata.
--
Wil

Hi Wil.

Thank you for providing accurate information.
As usual, the level of help from your side is great :-)

By the way do you know how many domains can be added for filtering?
I could not find such information on Microsoft's website.

I would like to implement a function to block ads and trackers.
The example list of tracking server domains contains about 4 thousand items.

How do you think adding so many items will not affect
the performance of the ActiveX?

Best regards
Przemek
Reply
#4
Przemek,

Sorry I don't know if there are any limits and how it would impact performance. For the ActiveX part there is no difference if you filter on one or on 4000 domains. For the underlying WebView2 control things might be different.

It shouldn't be an issue to filter for 4000 domains from my point of view. I guess it depends on how it has been implemented underneath. FWIW I haven't seen any complaints about bad performance in this area at their github feedback site.

I suppose it is going to be a matter of try & see how it behaves.
--
Wil
Reply
#5
(2023-08-11, 09:50:20)wila Wrote: I suppose it is going to be a matter of try & see how it behaves.

Hi. I'm just testing domain filtering with over 2k items
and I don't see any problems :-)

Thanks for providing the answers

Regards Przemek
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)