0

We have a need where in we need to query image server for image and display it on CEF web browser control within Windows form.

public partial class CustomerWindow : Form
{
     private string image_url;
     private ChromiumWebBrowser _browser;  
     private bool _browserInitialised = false;   

     public CustomerWindow()
     {
           browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged;
     }

     // calls to server for validating user credentials and get cookie
     public LoadData()
     {        
          if(_browserInitialised)
          {
              browser.Load(_imsContextualImageUrl);
          }         
     }

     public void OnIsBrowserInitializedChanged(object sender, EventArgs e)
     {
         var chromeWebBrowser = (ChromiumWebBrowser)sender;            
         if (!chromeWebBrowser.IsBrowserInitialized) return;            
         chromeWebBrowser.Load(_imsContextualImageUrl);          
         _browserInitialised = true;
     }
 }

We are creating CEF browser only once per application and disposing it at the close event of form.

Code is working and displaying image for the urls which has data, when there is no data , we need to clear the previous image displayed on CEF browser and shown empty CEF browser.

Is there any solution other than disposing CEF browser and recreating it for every launch request?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

0

Load an empty HTML page, just put this,

 <html><body></body></html> 

that would do fine.. you can use following API to load a string in CEF,

 ChromiumWebBrowser.LoadString(string html, string url);

I got this fragment from SO, Working with locally built web page in CefSharp

Goodies
  • 1,951
  • 21
  • 26
  • 1
    From memory LoadString was removed quite some time ago. You can call LoadHtml to achieve the same result. See https://github.com/cefsharp/CefSharp/wiki/General-Usage#loading-htmlcssjavascriptetc-from-diskdatabaseembedded-resourcestream for a list of options for loading resources from memory. – amaitland Feb 09 '21 at 02:09
  • Thanks for the remark amaitland.. it was some time ago I worked with it,, – Goodies Feb 09 '21 at 08:57
0

ChromiumWebBrowser.LoadString(string html, string url) is helpful but then chrome browser getting rendered with client's (company) proxy-server response as well in addition to html response.

Tried, Load() API ie ChromiumWebBrowser.Load("https:////somestring/someurl"), it rendered like charm with empty content.Thanks for the suggestion.