Hari
Hari

Reputation: 19

CEF browser showing old content on the window

I was creating a browser window for my WPF application. During the visibility change I am loading the URL, but when I change the URL content and load the same URL it is showing previous content first, then after a blinking it shows the updated data.

        void OnWindowVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (!IsBrowserInitialized) return;
            if (window.Visibility == Visibility.Visible)
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    LoadNewUrl();
                    window.Activate();
                }));
            }
            else
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    ChromeBrowser.LoadHtml("<html><body><h1></h1></body></html>");
                }));
            }
        }

Suppose the URL contains "ABCD" as data. First time it is showing the correct content. After the update the data becomes "ABCDEF". Now on Load() the initial content is showing then the updated content.

Is there anything else I need to do for avoiding this issue?

Upvotes: 0

Views: 248

Answers (1)

3CxEZiVlQ
3CxEZiVlQ

Reputation: 38773

I'm not sure what LoadHtml() does, it's not a part of the native CEF API. In any case the blank page is about:blank, i.e. ChromeBrowser.Load("about:blank").

Are you aware of stopping all activities in the hidden browser? It seems to be the issue - you load an empty page and hide the window, the browser stops any activities, then you activate the window and still see an old content, then an empty page causes "blinking", and finally a new content is shown.

You should catch change visibility request, cancel it, load about:blank and hide the window on load completion. The client handler has appropriate events.

Upvotes: 1

Related Questions