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.

How to avoid to wait more than 1 second when loading page for the first time? How to restart a browser session?

Post Reply
francesco.faleschini
Posts: 22
Joined: Tue Nov 09, 2021 9:08 am

How to avoid to wait more than 1 second when loading page for the first time? How to restart a browser session?

Post by francesco.faleschini »

Hi.

FIRST QUESTION: webpage loaded with 2 seconds delay, how to avoid?

I notice that when I call LoadUrl, the first time I open a URL the embedded chromium takes around 2-3 seconds to load the page, if the page is opened from Google Chrome this delay is not noticeable.

Is it possible to avoid this delay? Since in my application I attach a chromium tabpage at runtime and then as a user clicks on the tab, the URL is loaded and the delay is noticed, resulting in a negative user experience.

I attach a sample (V3 of a sample i previously sent you) for other questions.

To be able to run the sample please open uCEFLoader.pas and set the paths to the installed DCEF version in the following three lines of code:

Code: Select all

  GlobalCEFApp.FrameworkDirPath     := '..\dcef';
  GlobalCEFApp.ResourcesDirPath     := '..\..\..\dcef';
  GlobalCEFApp.LocalesDirPath       := '..\..\..\dcef\locales';
Once this is done it is possible to run the app:
1) pass the login by clicking on login
2) as the main form appears click on the Brower tab (attached at runtime): briskbard.com is immediately loaded, notice that it takes around 2 seconds to load,while it should be istantanious, why?

Is there a way to avoid this delay or is it an intrinsic DCEF behavior?

SECOND QUESTION: how to force the restart of a browser session?

Is there a way to reset a browser session? When DCEF is used in a Delphi app, all the embedded chromium instances refer to the same browser session.

I made a simple webapp that shows the current time and a session ID (initialized at every browser session start).

This app is published at https://qvm-dev.my.qualibus.it/TimeInSession/TimeInSession.htm

and the Delphi app calls it when clicking on Session Time button inside the Browser tab.

How to start a new session? I would like that every time i click on the Session Time button a new session of the TimeInSession app is started

I hope you can help me with both my questions.

Thanks a lot.

Best regards.
You do not have the required permissions to view the files attached to this post.
zaqaz
Posts: 15
Joined: Wed Nov 30, 2022 8:59 pm

Re: How to avoid to wait more than 1 second when loading page for the first time? How to restart a browser session?

Post by zaqaz »

1. load abiout blank
2. to restart session make new browser with new cookies folder / proxy
francesco.faleschini
Posts: 22
Joined: Tue Nov 09, 2021 9:08 am

Re: How to avoid to wait more than 1 second when loading page for the first time? How to restart a browser session?

Post by francesco.faleschini »

hi, thanks for the reply, could you please restate your answers in a "less zipped" way?

Thank you.
zaqaz
Posts: 15
Joined: Wed Nov 30, 2022 8:59 pm

Re: How to avoid to wait more than 1 second when loading page for the first time? How to restart a browser session?

Post by zaqaz »

2.

Code: Select all

procedure Object_WebBrowser_Base21.CreateNewBrowser(aCookieFolder : string; aProxy : object_ProxyData);

var

  cefContext          : ICefRequestContext;

  TempValue: ICefValue;
  s : ustring;
  rr : boolean;

  TempCache  : string;
begin


  if not(ContainsText(aCookieFolder, GlobalCEFApp.RootCache))  then
  begin
     log('ERROR // other root folder // ')
  end;

  TempCache := GlobalCEFApp.RootCache + '\' + aCookieFolder + '\';


  cefContext := TCefRequestContextRef.New(TempCache, '', '', False, False, False, BrowserCrm.ReqContextHandler);

{
  TempValue := TCefValueRef.New;
  TempValue.SetBool(false);
  cefContext.SetPreference('webkit.webprefs.loads_images_automatically', TempValue, s);
  cefContext.SetPreference('loads_images_automatically', TempValue, s);
  cefContext.SetPreference('webkit.webprefs.loads_images_automatically', TempValue, s);

  TempValue.SetBool(false);
  cefContext.SetPreference('webrtc.multiple_routes_enabled', TempValue, s);
  TempValue.SetBool(false);
  cefContext.SetPreference('webrtc.nonproxied_udp_enabled', TempValue, s);
  TempValue.SetInt(0);
  cefContext.SetPreference('enable-media-stream', TempValue, s);
  TempValue.SetInt(0);

  cefContext.SetPreference('enable_webrtc', TempValue, s);

  TempValue.SetString('disable_non_proxied_udp');
  cefContext.SetPreference('webrtc.ip_handling_policy', TempValue, s);
{}


  // страница для загрузки
  BrowserCrm.DefaultUrl := 'about:blank';


  // прокси
  if not(aProxy.isNullProxy) then
  begin
    self.Proxy_Set(aProxy);
  end;





  log('BROWSER Initialized 001 // ', BrowserCrm.Initialized);

  f062_BrowserCRM_BeforeInitialize;

  while True do
  begin
      f010_pause(2);
//      if not(BrowserCrm.CreateBrowser(nil, '', cefContext)) and not(BrowserCrm.Initialized) then
      if not(BrowserCrm.CreateBrowser(ControlList.currentCefWindow, '', cefContext)) and not(BrowserCrm.Initialized) then
      begin
         log('BROWSER CREATED 002', BrowserCrm.Initialized);
         continue;
      end
      else
      begin
        log('BROWSER CREATED 003', not(BrowserCrm.CreateBrowser(ControlList.currentCefWindow, '', cefContext)) and not(BrowserCrm.Initialized));
        break;
      end;

  end;

  while True do
  begin
      rr := BrowserCrm.Initialized;
      log('BrowserCrm.Initialized', rr);
      if rr then
         break;
      f010_pause(2);
  end;



  log('BrowserCrm.Initialized', BrowserCrm.Initialized);

  ControlList.currentCefWindow.Visible   := true;
//  LoadURL_Wait('https://www.google.com/');
//BrowserCrm.SetNewBrowserParent(cefWindow.Handle);
//  f001_BaseObj_SetProcedures;

end;




1.

Code: Select all

  BrowserCrm.DefaultUrl := 'about:blank';


ok?

ps. it is not optimized shit code
User avatar
salvadordf
Posts: 4056
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to avoid to wait more than 1 second when loading page for the first time? How to restart a browser session?

Post by salvadordf »

Hi,
francesco.faleschini wrote: Wed Dec 21, 2022 9:59 am FIRST QUESTION: webpage loaded with 2 seconds delay, how to avoid?
I notice that when I call LoadUrl, the first time I open a URL the embedded chromium takes around 2-3 seconds to load the page, if the page is opened from Google Chrome this delay is not noticeable.
This looks like a networking issue. Perhaps the browser needs to resolve the website address and the DNS server takes some time to return some result the first time.

Other users also report some initial delays when Windows uses a proxy to connect to Internet.

Run the MiniBrowser demo and open the DevTools. Switch to the networking tab and try to load the initial web page to see what could be happening.
francesco.faleschini wrote: Wed Dec 21, 2022 9:59 am SECOND QUESTION: how to force the restart of a browser session?
Is there a way to reset a browser session? When DCEF is used in a Delphi app, all the embedded chromium instances refer to the same browser session.
There are several ways to do that.

If you know that certain website uses cookies from a given URL then you can call TChromium.DeleteCookies. See the CookieVisitor demo for all the details.

You can also use TChromium.ClearCache to delete all the cache contents, including the session cookies.

If you prefer to keep several independent browsers running at the same time then you need to create a new request context with a different cache directory for the new browser. See the MDIBrowser demo for all the details.
francesco.faleschini
Posts: 22
Joined: Tue Nov 09, 2021 9:08 am

Re: How to avoid to wait more than 1 second when loading page for the first time? How to restart a browser session?

Post by francesco.faleschini »

salvadordf wrote: Sun Jan 01, 2023 7:03 pm Hi,
francesco.faleschini wrote: Wed Dec 21, 2022 9:59 am FIRST QUESTION: webpage loaded with 2 seconds delay, how to avoid?
I notice that when I call LoadUrl, the first time I open a URL the embedded chromium takes around 2-3 seconds to load the page, if the page is opened from Google Chrome this delay is not noticeable.
This looks like a networking issue. Perhaps the browser needs to resolve the website address and the DNS server takes some time to return some result the first time.

Other users also report some initial delays when Windows uses a proxy to connect to Internet.

Run the MiniBrowser demo and open the DevTools. Switch to the networking tab and try to load the initial web page to see what could be happening.
First of all happy new year in late!

Thanks a lot! with TChromium.DeleteCookies you solved my second question perfectly.
I still have problems with the first one.
I used the DevTools/Network to see if the slowliness was because of the data transfer from website to my PC, but this is not the case. I tried the minibrowser demo and iI kept google as defaultURL: it took around 7 seconds to "initialize" and then a little more than 1 second (this was visible in the network tab) to load the page.
So there is some delay in the initialization, I notice this even if I use 'about:blank' as default URL, so it does not seem to be a DNS issue or an internet speed issue. Moreover, this is noticeable only when I load a URL for the first time after initializing TChromium.
Please suggest what I can try to resolve this problem.
To better express myself I recorded a short video of me using the app I attached to the original question. You can see that briskbard.com appears after 6 seconds when I switch to the "browser" tab on the page control, but there are no DNS problems or network connection issues.

Thanks a lot for the support!
You do not have the required permissions to view the files attached to this post.
User avatar
salvadordf
Posts: 4056
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to avoid to wait more than 1 second when loading page for the first time? How to restart a browser session?

Post by salvadordf »

The web hosting service used by briskbard.com is not very fast. Use google.com to make tests.

Please, download the official CEF sample application from here :
https://cef-builds.spotifycdn.com/cef_binary_108.4.13%2Bga98cd4c%2Bchromium-108.0.5359.125_windows64_client.tar.bz2

Decompress the package and test the initialization time with cefclient.exe. It loads google.com by default.

If you still get a long delay with cefclient then try disabling your antivirus for a minute and repeat the test.

Read this thread from the official CEF forum for more information :
https://magpcss.org/ceforum/viewtopic.php?f=6&t=17965

If the solution in the last message fixes this issue then try the MiniBrowser demo, click on the top-right button and select "Preferences...". Then select "Direct" as proxy type and navigate to other web pages to test that proxy configuration.
Post Reply