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.

DOMVisitor example clarifications

Post Reply
PioPio
Posts: 42
Joined: Sun Nov 05, 2017 10:25 pm

DOMVisitor example clarifications

Post by PioPio »

Hello,

I was looking into the DOMVisitor example but I cannot see where the procedure GlobalCEFApp_OnProcessMessageReceived is triggered from. Is this procedure triggered by CEF4Delphi internally ?

In addition, why the prcedures SimpleDOMIteration, SimpleNodeSearch and DOMVisitor_OnDocAvailable are not incapsulated in TDOMVisitorFrm ?

Many thanks
Alberto
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: DOMVisitor example clarifications

Post by salvadordf »

Hi Alberto,
PioPio wrote: Fri Dec 29, 2017 7:40 pm I was looking into the DOMVisitor example but I cannot see where the procedure GlobalCEFApp_OnProcessMessageReceived is triggered from. Is this procedure triggered by CEF4Delphi internally ?
That demo is sending messages from the browser process to the render process, and from the render process to the browser process.

To send a message from the browser process you must use the TChromium.SendProcessMessage procedure with a PID_RENDERER parameter. You can find it in the uDOMVisitor.pas file, line 281. The render process receives those messages in the GlobalCEFApp.OnProcessMessageReceived event

To send messages from the render process you must use the browser.SendProcessMessage procedure with a PID_BROWSER parameter. You can find it on the uDOMVisitor.pas file, line 187. The browser process receives those messages in the TChromium.OnProcessMessageReceived event.
PioPio wrote: Fri Dec 29, 2017 7:40 pm In addition, why the prcedures SimpleDOMIteration, SimpleNodeSearch and DOMVisitor_OnDocAvailable are not incapsulated in TDOMVisitorFrm ?
Those procedures are executed in the render process and TDOMVisitorFrm is only available in the browser process.

I'll add all this info as comments in that demo.
PioPio
Posts: 42
Joined: Sun Nov 05, 2017 10:25 pm

Re: DOMVisitor example clarifications

Post by PioPio »

Hi Salvador,

I am still looking into the same example and I have another question.

Why are the following instructions necessary in GlobalCEFApp_OnProcessMessageReceived:
TempVisitor := TCefFastDomVisitor2.Create(browser, DOMVisitor_OnDocAvailable);
TempFrame.VisitDom(TempVisitor);
Why cannot I just replace the code above with the one in DOMVisitor_OnDocAvailable ? What does ICefFrame.VisitDom do ?
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: DOMVisitor example clarifications

Post by salvadordf »

PioPio wrote: Sat Dec 30, 2017 11:58 am Why are the following instructions necessary in GlobalCEFApp_OnProcessMessageReceived:
TempVisitor := TCefFastDomVisitor2.Create(browser, DOMVisitor_OnDocAvailable);
TempFrame.VisitDom(TempVisitor);
Why cannot I just replace the code above with the one in DOMVisitor_OnDocAvailable ? What does ICefFrame.VisitDom do ?
This is what the API documents say about ICefFrame.VisitDom :
VisitDOM
Visit the DOM document. This method can only be called from the render process.
http://magpcss.org/ceforum/apidocs3/pro ... Frame.html
https://bitbucket.org/chromiumembedded/ ... ew-default

If you call TempFrame.VisitDom from the browser process it won't work. It must be called from the render process.

Many other things in CEF3 can only be called or accessed from a certain process or thread but the API documents or the CEF source comments have that information.

CefFrame.VisitDom is asynchronous and it will call the Visit method of ICefDomVisitor when the Document is available. TCefFastDomVisitor2 implements ICefDomVisitor and calls DOMVisitor_OnDocAvailable inside the Visit method.

http://magpcss.org/ceforum/apidocs3/pro ... sitor.html
https://github.com/salvadordf/CEF4Delph ... isitor.pas
PioPio
Posts: 42
Joined: Sun Nov 05, 2017 10:25 pm

Re: DOMVisitor example clarifications

Post by PioPio »

Thank you for your extensive answer, Salvador.
PioPio
Posts: 42
Joined: Sun Nov 05, 2017 10:25 pm

Re: DOMVisitor example clarifications

Post by PioPio »

I just tried the same example with the latest CEF4Delphi release but GlobalCEFApp_OnProcessMessageReceived is never triggered. Is it just me ?
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: DOMVisitor example clarifications

Post by salvadordf »

I tested that demo again and it seems to work on google.com.

The document title is shown in the status bar and the log has some information about the DOM nodes.

A few days ago there was a report in the official CEF3 forum about lost messages between processes in the latest branch :
http://magpcss.org/ceforum/viewtopic.php?f=6&t=15677

Try setting GlobalCEFApp.SitePerProcess to False before the GlobalCEFApp.StartMainProcess call.
PioPio
Posts: 42
Joined: Sun Nov 05, 2017 10:25 pm

Re: DOMVisitor example clarifications

Post by PioPio »

Apologises, I put some breakpoints in the IDE but the application never stopped in these points. Not sure why but this is ok.
The log file is been generated correctly tho. I used all the information from there.

Alberto
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: DOMVisitor example clarifications

Post by salvadordf »

GlobalCEFApp_OnProcessMessageReceived is executed in the render process and Delphi is debugging the browser process.

If you need to debug other processes read the Debugging section in this page :
https://www.briskbard.com/index.php?lang=en&pageid=cef
Post Reply