Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Avoid empty screen blinking before loading a page

Post Reply
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Avoid empty screen blinking before loading a page

Post by salvadordf »

Hi,

Try this to minimize the blinking effect :
  • Set TChromium.DefaultURL to your local file URL as soon as the browser is initialized. It must be set before the TChromium.CreateBrowser call.
  • Don't call TChromium.LoadURL in the TChromium.AfterCreated event because setting TChromium.DefaultURL will load your homepage automatically.
  • Use TChromium.Reload when you need to refresh the browser contents.
  • If you still see a brief "blink" when you reload the page try this :
    • Call TChromium.TakeSnapshot to save the browser contents in a bitmap.
    • Draw that bitmap in a hidden TImage.
    • Before reloading the web page, show the TImage and call TImage.BringToFront. Then hide the TCEFWindowParent and call TCEFWindowParent.SendToBack. TImage should have the same dimensions and coordinates as TCEFWindowParent.
    • Use the TChromium.OnLoadingStateChange event and check the "isLoading" parameter to know when the web page is loaded. Send a message to the main form to show TCEFWindowParent and hide TImage when isLoading is FALSE.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Avoid empty screen blinking before loading a page

Post by salvadordf »

Depending on the contents of the web page it can be tricky to know when it's fully loaded.

If the web page has several frames or if it changes the HTML contents from JavaScript then it can be hard to tell if it ever finishes loading.

The TChromium.OnLoadingStateChange event is one of the ways to know that but you can also use TChromium.OnLoadStart and TChromium.OnLoadEnd to check if all the frames are finished.

About refreshing TCEFWindowParent, CEF creates several child "windows" inside TCEFWindowParent. (I'm using the Windows API term for "window")

Perhaps you would get better results if you send the refresh messages to TChromium.RenderHandle, TChromium.WidgetHandle or TChromium.BrowserHandle.

Please, read this post about the child "windows" that CEF creates :
https://www.briskbard.com/forum/viewtop ... 530&p=2347

Are you using the DoubleBuffered property in your app?
If you use it, please, try disabling it. It's been reported that it causes problems :
https://www.briskbard.com/forum/viewtop ... 368&p=1696
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Avoid empty screen blinking before loading a page

Post by salvadordf »

Thank you! :D

I just added your solution to CEF4Delphi and added the TCEFWinControl.InvalidateChildren procedure to invalidate all the children using RedrawWindow.
Post Reply