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.

Migration from CEF1 on CEF3

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

Re: Migration from CEF1 on CEF3

Post by salvadordf »

Hi,

There are several ways to get JavaScript results. I haven't tested this way but I think it should work.

Unless there's some unexpected problem executing JavaScript at 300 ms intervals you should be able to receive the results in the TChromium.OnConsoleMessage event.

Please, don't use the single process mode unless you want to debug other processes. This mode is NOT supported by CEF3 and it's known to cause errors and access violations.

It's also recommended to use GlobalCEFApp.MultiThreadedMessageLoop := TRUE in Windows.

Remember that the TChromium.OnConsoleMessage event is executed in a thread. I would use synchronization objects to store the JSON text and exit from that event as soon as possible without parsing the text or storing it in the database.

Post a message to the main form every time a new JSON text is stored to parse the JSON text and store the results in the database.

The text parsing should be done in a different thread to have a responsive user interface.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Migration from CEF1 on CEF3

Post by salvadordf »

parserMan wrote: Mon Mar 26, 2018 2:04 pm So, i understand that i must do separate thread to parse JSON, write in log and and in database.
Is there some example of this? May be in Demo folder? (CEF4 delphi master)
I'm sorry but that's out of the scope of CEF4Delphi's project.

All demos are related to CEF4Delphi's functionality but here you can find more info about Delphi threads :
http://docwiki.embarcadero.com/RADStudi ... plications
https://www.safaribooksonline.com/libra ... /ch04.html
http://www.thedelphigeek.com/2012/02/bl ... -four.html
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Migration from CEF1 on CEF3

Post by salvadordf »

parserMan wrote: Mon Mar 26, 2018 3:15 pm 1. For what purpose the Off Screen mode was done ? It was done to minimaze resources spent on displaying the page? Or for what?
Some apps need to show a browser inside a customized GUI, for example a game might want to show a web page inside a 3D scene.
If I remember correctly, OSR mode is used in some other platforms.
parserMan wrote: Mon Mar 26, 2018 3:15 pm In the future i need to parse 10 000 pages in the same time by JS script))) (it is very ambitious target)))
I have to use OSR mode? (By some reasons i cant use simple GET http method. All these pages are formed by JS on client side, and every second content are change)
Windows has limitations for the amount of resources a process is using, number of subprocesses created by a process, etc.
You will need several HUNDRED computers to do that.
parserMan wrote: Mon Mar 26, 2018 3:15 pm 2. In your second post you write:
salvadordf wrote: Mon Mar 26, 2018 12:30 pm There are several ways to get JavaScript results.
What ways do you mean? (except OnConsoleMessage).
I think that OnConsoleMessage is not best way.
You can receive the results from JavaScript in other ways like CEF process messages, customized process messages and websockets.
Some demos in the JavaScript directory use CEF process messages.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Migration from CEF1 on CEF3

Post by salvadordf »

If you use TChromium and TCEFWindowParent this is the destruction sequence :
  • 1. FormCloseQuery sets CanClose to False and calls TChromium.CloseBrowser, which triggers the TChromium.OnClose event.
  • 2. TChromium.OnClose sends a message to the form to destroy TCEFWindowParent in the main thread, which triggers the TChromiumWindow.OnBeforeClose event.
  • 3. TChromium.OnBeforeClose sets FCanClose := True and sends WM_CLOSE to the form.
Several demos like MDIBrowser or ToolBoxBrowser use this sequence but if you use the OSR mode then it's slightly different. Read the code comments for more details, specially if you create several browsers in one app.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Migration from CEF1 on CEF3

Post by salvadordf »

You can send a custom message from the Chromium0BeforeClose procedure to the main form to free chromium0 in the main app thread.

Your code should work but you can take a llok at the MDIBrowser, ToolBoxBrowser or any other demo with an external pump to see see how to destroy browsers safely. Some of the demos use different components and the destruction sequence is slightly different but all of them follow the CloseBrowser -> OnClose -> OnBeforeClose sequence.
Post Reply