Home > Blockchain >  Disable runtime cache in Microsoft.Web.WebView2.Wpf
Disable runtime cache in Microsoft.Web.WebView2.Wpf

Time:12-22

I am creating a webview2 wpf application, everything works well till now, but when I tried to load HTML file which is having youtube link, It's worked well along with autoplay . But when I change the HTML file to some another site , the audio of youtube video still playing in background and webview2 load the new content. I want something to disable the cache to be stored will runtime instead of clearing the cache.

If someone is having any idea related to above issue please help

CodePudding user response:

This is the common issue faced by the webview2 when external site media player is played. To overcome this issue you have to create a new instance of webview2 before you load second content to webView, this will create new Webview Page but still the UI will not stop the audio, so use Webview.dispose() as well. WebView.Dispose()

Note : this will give you issue related to Null object reference for the 1st time . So you have the check the the object before doing dispose.

Code should be like this :

MainPage :

 WebViewPage webpage;

 private void updateNewContent ()
 {
  ...
 WebView2 webView2 = Mywebvew2;  // MYwebview2 is UI object from webviewPage, 
                               //you have to pass this object from webview Page 
            if (webView2 != null)
            {
                webView2.Dispose();
            }
            
            webpage = null;
            webpage = new WebViewPage();                
            GridPrincipal.Children.Add(webpage);
   ...
   }
  • Related