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.

Page Loading

Post Reply
amiran6543
Posts: 15
Joined: Sun Dec 05, 2021 12:07 pm

Page Loading

Post by amiran6543 »

Hello, how do I check if the page is fully loaded or not?
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Page Loading

Post by salvadordf »

Use the TChromium.OnLoadingStateChange event and check the "isLoading" parameter.
amiran6543
Posts: 15
Joined: Sun Dec 05, 2021 12:07 pm

Re: Page Loading

Post by amiran6543 »

I did it as written but it doesn't work
What is the problem?

Code: Select all

       procedure tform1.Chromium1LoadingStateChange(Sender: TObject;
  const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean);
begin
  if not(Chromium1.IsSameBrowser(browser)) or FClosing then exit;

  if isLoading then
    begin
        showmessage('Page loaded!');
    end

end;
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Page Loading

Post by salvadordf »

The "IsLoading" parameter is true while the document is still being loaded. That event is triggered with the "IsLoading" parameter set to false when Chromium considers that the document is no longer being loaded.

Avoid calling any function related to visual controls or dialogs inside the TChromium events.

Most of the TChromium events are executed in the context of a CEF thread that is not the same as the main application thread.
VCL and many Windows API methods are not thread safe and using them inside TChromium events might cause problems.

Some of the CEF4Delphi demos are oversimplified and they still modify VCL controls inside those events but it's recommended to save the information you need from those events and then send a message to the main form to use that information with VCL controls in the main application thread.
Post Reply