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.

Closing issues

Post Reply
Hitman
Posts: 73
Joined: Sat May 20, 2017 11:08 am

Closing issues

Post by Hitman »

Hi All,
i am having hard time with closing my browser application by using Windows Shortcuts keys or any other options.
No matter what i do, i always get "Application not responding" or "Application has stopped working" before it closes itself.

are there any ways to terminate the browser without having errors?

Thanks!!
User avatar
salvadordf
Posts: 4044
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Closing issues

Post by salvadordf »

Hi,

You need to follow the destruction sequence described in the demos.
Read the code comments in the demo you used as template for your application to know the details.
Hitman
Posts: 73
Joined: Sat May 20, 2017 11:08 am

Re: Closing issues

Post by Hitman »

I am sorry :(
I have checked the simple browser demo and followed the closing options.
It seems to close okay now.

Many thanks for the advices!! :) :)
User avatar
salvadordf
Posts: 4044
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Closing issues

Post by salvadordf »

CEF (Chromium) uses several threads and processes that need to be closed correctly before the application can exit.

In general, you should use TForm.OnCloseQuery to cancel the close request while the browser is being destroyed.

There's a slightly different destruction sequence depending on what CEF4Delphi components you used and how you used them :
  • TChromium and TCEFWindowParent in normal mode.
  • TChromium in OSR mode.
  • TChromiumWindow.
Basically, all of them do something like this :
  • Cancel the form destruction and call the TChromium.CloseBrowser procedure.
  • Wait until the TChromium.OnClose event is triggered.
  • Wait until the TChromium.OnBeforeClose event is triggered and then continue closing the form normally.
The last point is a little bit tricky because the TChromium.OnBeforeClose event is triggered in different ways depending on the components you use in your application.

Many demos use a couple of boolean variables called FCanClose and FClosing to ensure the destruction sequence is done only one time and the form is closed after the browser is correctly destroyed.

If you used TChromium and TCEFWindowParent in normal mode then you have to :
  • Use TForm.OnFormCloseQuery and set CanClose to FALSE. This will cancel the form destruction while you destroy the browser.
  • Call TChromium.CloseBrowser inside TForm.OnFormCloseQuery, which will trigger the TChromium.OnClose event.
  • Use the TChromium.OnClose event and send a CEFBROWSER_DESTROY message to the form with the TChromium component. You need to send a message because TChromium.OnClose is executed in a different thread and you must destroy all VCL components in the main thread.
  • The procedure that handles CEFBROWSER_DESTROY destroys TCEFWindowParent in the main thread, which will trigger the TChromium.OnBeforeClose event.
  • Use TChromium.OnBeforeClose to set FCanClose to TRUE and send WM_CLOSE to the form again.
  • This time the TForm.OnFormCloseQuery event will set CanClose to TRUE because FCanClose is true and the form can be closed normally.
Hitman
Posts: 73
Joined: Sat May 20, 2017 11:08 am

Re: Closing issues

Post by Hitman »

Thank you!! :) :)
User avatar
salvadordf
Posts: 4044
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Closing issues

Post by salvadordf »

Hi,

The last CEF versions have some issues with some new features and you need to disable them.

Assuming you use the latest CEF4Delphi version, add this code line before the GlobalCEFApp.StartMainProcess call in the LPR file :

Code: Select all

GlobalCEFApp.DisableFeatures := 'NetworkService,OutOfBlinkCors';
This line was added to many demos in the last CEF4Delphi versions.
ForestListener
Posts: 44
Joined: Sun Jul 07, 2019 1:46 pm

Re: Closing issues

Post by ForestListener »

salvadordf wrote: Sun Aug 04, 2019 7:10 am Hi,

The last CEF versions have some issues with some new features and you need to disable them.

Assuming you use the latest CEF4Delphi version, add this code line before the GlobalCEFApp.StartMainProcess call in the LPR file :

Code: Select all

GlobalCEFApp.DisableFeatures := 'NetworkService,OutOfBlinkCors';
This line was added to many demos in the last CEF4Delphi versions.
Hello.

Should everybody add this string?
User avatar
salvadordf
Posts: 4044
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Closing issues

Post by salvadordf »

You should add it if you're using the latest CEF4Delphi version and you notice some issues in your app : closing errors, features not working, etc

If future CEF versions we will not be able to disable the Network Service and that line won't be effective but for now, it's recommended to add it.
Post Reply