CefSharp icon indicating copy to clipboard operation
CefSharp copied to clipboard

Cannot Load with web_view.load(url)

Open NaderHamzei opened this issue 13 years ago • 3 comments

I have a WinForm Application. I have created a working example of CefSharp as a test. However, now I need to include it into my program to replace a IE web Control.

The issue is when I load the form, in the form constructor I am forced to place the following,

        var settings = new CefSharp.Settings
        {
            PackLoadingDisabled = true,
        };

        if (CEF.Initialize(settings))
        {
            //web_view = new WebView();
            web_view = new WebView("http://www.yahoo.com", new BrowserSettings());
            web_view.Dock = DockStyle.Fill;
            web_view.RequestHandler = this;

            toolStripContainer1.ContentPanel.Controls.Add(web_view);
        }

I have a method called Navigate(string url) the first statement in this method is:

web_view.Load(url);

CefSharp failes with error Browser is not Initialized.

HOW do you load a url? the example in the forum posts talk about PropertyChange and checking for IsBrowserInitialized, but in my case it is always false.

yes I have all the files and locales in the bin/Debug folder

any ideas?

NaderHamzei avatar Oct 21 '13 21:10 NaderHamzei

See #158 - it's the same issue you're running into. In your Form_Load() or similar, you need to hook the webView.PropertyChanged. When that event is raised and the property name is IsBrowserInitialized, then you can call the Load() method with the proper URL.

Closing for the time being - please reopen if this does not help.

perlun avatar Oct 22 '13 04:10 perlun

Can you please quote a code sample please?? I tried to do the below in my form load which did not work. What is wrong with it. And it is never reaching the web_view.Reload. It is going into infinite loop.

while (!web_view.IsBrowserInitialized)
{
    //Count Time
}
web_view.Reload();

sriharshakolluru avatar Mar 26 '14 09:03 sriharshakolluru

The best code samples are the CefSharp.Wpf.Example and (in the case of CefSharp3) the CefSharp.MinimalExample - the latter can be found here. WPF only at the moment.

In the case of your code, you cannot sit and spin on the UI thread like that; it will never work since you are blocking the CEF code from actually running.

Instead, you must hook the OnPropertyChanged event and check when the IsBrowserInitialized is changed to true. All of that can be seen in the WPF/WinForms examples.

perlun avatar Mar 26 '14 10:03 perlun