Page 1 of 1

DOMVisitor example clarifications

Posted: Fri Dec 29, 2017 7:40 pm
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

Re: DOMVisitor example clarifications

Posted: Fri Dec 29, 2017 9:06 pm
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.

Re: DOMVisitor example clarifications

Posted: Sat Dec 30, 2017 11:58 am
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 ?

Re: DOMVisitor example clarifications

Posted: Sat Dec 30, 2017 1:06 pm
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

Re: DOMVisitor example clarifications

Posted: Sat Dec 30, 2017 5:26 pm
by PioPio
Thank you for your extensive answer, Salvador.

Re: DOMVisitor example clarifications

Posted: Sun Jan 07, 2018 4:02 pm
by PioPio
I just tried the same example with the latest CEF4Delphi release but GlobalCEFApp_OnProcessMessageReceived is never triggered. Is it just me ?

Re: DOMVisitor example clarifications

Posted: Sun Jan 07, 2018 4:32 pm
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.

Re: DOMVisitor example clarifications

Posted: Mon Jan 08, 2018 10:45 am
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

Re: DOMVisitor example clarifications

Posted: Mon Jan 08, 2018 11:02 am
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