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.
CloseBrowser safely
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: CloseBrowser safely
If you need several browsers create an array of TDTBrowser and destroy all of them.
If you create browsers with a reference count then it's possible that only the first one will be properly destroyed.
If you create browsers with a reference count then it's possible that only the first one will be properly destroyed.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: CloseBrowser safely
To be honest, I'm not sure. You're using a custom browser class with a nil owner and that means that you must destroy all the browsers manually.Winexcel wrote: Sat Feb 17, 2018 2:57 pmFBrowserRefCount is a variable which show how much popup Browsers this browser have.If you create browsers with a reference count then it's possible that only the first one will be properly destroyed.
When popup Browser is closing it invoke TChromium.Browser.CloseBrowser(True) of Main Browser (which created this popup), after that main browser check FBrowserRefCount and if FBrowserRefCount = 0 then it will be destroyed.
I'm developing this mechanism in order to work easy with popup windows and close main browser correctly(when all popup which was created this main browser were closed)
I'm interested, Is it possible?
Using this reference count destruction you would always need to destroy the popups browsers first and then the main browser.
Each browser can call CloseBrowser only one time.Winexcel wrote: Sat Feb 17, 2018 2:57 pmTo call TChromium.Browser.Host.CloseBrowser(True) more than one time?
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: CloseBrowser safely
When you let CEF create the popups it creates new ICefBrowser instances but CEF uses the same ICefClient and the same TCefBrowserSettings for the new ICefBrowser.Winexcel wrote: Sat Feb 17, 2018 4:17 pm In method doOnClose i call inherited method only one time(when the FBrowserRefCount = 0), but the method
TChromium.Browser.Host.CloseBrowser(True) is triggered method doOnClose many times which may called by popup browsers. It seems to work but I'm not sure that it's a right solution.
ICefClient is responsible for calling the doOnClose method and all other "doOn..." methods in TChromium. This means that the popup browsers will also call the "doOn..." methods in the main TChromium. In your case, when CEF destroys a popup browser it will call "popupbrowser.host.closebrowser" and this will call the doOnClose method in your TChromium because it has the same ICefClient.
You must return the default values in doOnClose and all other "doOn..." methods if the "browser" parameter is a popup.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: CloseBrowser safely
Please check that CreateClientHandler returns True or you will be using the default ICefClient, which is the ICefClient from the main form.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: CloseBrowser safely
I had some difficulties testing "testpopup.rar" and I couldn't make it show a browser.
Anyway, this is a very complicated issue that needs a new demo so I just uploaded the "PopupBrowser" demo showing all the steps to handle popup windows with custom forms.
Please, read the code comments in the *.pas files.
Anyway, this is a very complicated issue that needs a new demo so I just uploaded the "PopupBrowser" demo showing all the steps to handle popup windows with custom forms.
Please, read the code comments in the *.pas files.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: CloseBrowser safely
I clicked the "CreateBrowser" button and then the "Load" button but I couldn't see a browser window to click the "Sign in via FaceBook" button.
All bug reports, bug fixes and optimizations are welcome!Winexcel wrote: Mon Feb 19, 2018 2:21 pm I had rewrote your example on FMX, the example is based on TDTBrowser, I think that it is really more simple to realise counting popup browsers like I did with the variable FBrowsersCount. I'll post my example later, it isn't clean at the moment.

Loading "about:blank" is one of the steps to close TWebBrowser but CEF3 has a different destruction sequence.Winexcel wrote: Mon Feb 19, 2018 2:21 pm I don't know why, but sometimes my solution on FMX crashes in closing time, but It helps:I invoke it before CloseBrowser(True).Code: Select all
LoadURL('about:blank');
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: CloseBrowser safely
Thanks for the demo!
I'll take a look as soon as I can.

I'll take a look as soon as I can.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: CloseBrowser safely
Sorry for the delay.
I took a look at PopupFMX and it seems to destroy the browsers correctly.
To be honest, I'm not sure why it crashes when you don't load "about:blank".
Perhaps CEF3 doesn't support "WindowInfoAsClipWindow" or there's some kind of problem using TThread.Synchronize.
Sorry but I don't know the cause of this problem.
I took a look at PopupFMX and it seems to destroy the browsers correctly.
To be honest, I'm not sure why it crashes when you don't load "about:blank".

Perhaps CEF3 doesn't support "WindowInfoAsClipWindow" or there's some kind of problem using TThread.Synchronize.
Sorry but I don't know the cause of this problem.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: CloseBrowser safely
Feel free to attach it if you want to share your work with the rest of us.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: CloseBrowser safely
Check that there are no blocked threads in the "Thread Status" tab when you debug your app in Delphi and close a popup browser.
Click on "Program Pause" in the "Run" menu to see what threads are blocked.
Also check that the BrowserOnBeforeClose function only destroys the popup browser.
Click on "Program Pause" in the "Run" menu to see what threads are blocked.
Also check that the BrowserOnBeforeClose function only destroys the popup browser.