You can use WebResourceRequested event which raises when the WebView is performing a URL request to a matching URL and resource context filter that was added with AddWebResourceRequestedFilter.
Example
In the following example, a message box will be displayed whenever an image is loading from any uri. To do so, drop a WebView2 on the Window and assign it a name webView21
and handle the Loaded event of the window with the following code:
//using Microsoft.Web.WebView2.Core;
//using System.Windows;
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
await webView21.EnsureCoreWebView2Async();
webView21.CoreWebView2.AddWebResourceRequestedFilter(
"*",
CoreWebView2WebResourceContext.Image);
webView21.CoreWebView2.WebResourceRequested += (obj, args) =>
{
MessageBox.Show(args.Request.Uri);
};
webView21.CoreWebView2.Navigate("https://www.google.com");
}
You can find another example here: Edit HTTP Request header with WebView2.