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.
DOMVisitor example clarifications
DOMVisitor example clarifications
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
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
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: DOMVisitor example clarifications
Hi Alberto,
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.
I'll add all this info as comments in that demo.
That demo is sending messages from the browser process to the render process, and from the render process to the browser process.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 ?
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.
Those procedures are executed in the render process and TDOMVisitorFrm is only available in the browser process.PioPio wrote: Fri Dec 29, 2017 7:40 pm In addition, why the prcedures SimpleDOMIteration, SimpleNodeSearch and DOMVisitor_OnDocAvailable are not incapsulated in TDOMVisitorFrm ?
I'll add all this info as comments in that demo.
Re: DOMVisitor example clarifications
Hi Salvador,
I am still looking into the same example and I have another question.
Why are the following instructions necessary in GlobalCEFApp_OnProcessMessageReceived:
I am still looking into the same example and I have another question.
Why are the following instructions necessary in GlobalCEFApp_OnProcessMessageReceived:
Why cannot I just replace the code above with the one in DOMVisitor_OnDocAvailable ? What does ICefFrame.VisitDom do ?TempVisitor := TCefFastDomVisitor2.Create(browser, DOMVisitor_OnDocAvailable);
TempFrame.VisitDom(TempVisitor);
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: DOMVisitor example clarifications
This is what the API documents say about ICefFrame.VisitDom :PioPio wrote: Sat Dec 30, 2017 11:58 am Why are the following instructions necessary in GlobalCEFApp_OnProcessMessageReceived:
Why cannot I just replace the code above with the one in DOMVisitor_OnDocAvailable ? What does ICefFrame.VisitDom do ?TempVisitor := TCefFastDomVisitor2.Create(browser, DOMVisitor_OnDocAvailable);
TempFrame.VisitDom(TempVisitor);
http://magpcss.org/ceforum/apidocs3/pro ... Frame.htmlVisitDOM
Visit the DOM document. This method can only be called from the render process.
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
Thank you for your extensive answer, Salvador.
Re: DOMVisitor example clarifications
I just tried the same example with the latest CEF4Delphi release but GlobalCEFApp_OnProcessMessageReceived is never triggered. Is it just me ?
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: DOMVisitor example clarifications
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.
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
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
The log file is been generated correctly tho. I used all the information from there.
Alberto
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: DOMVisitor example clarifications
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
If you need to debug other processes read the Debugging section in this page :
https://www.briskbard.com/index.php?lang=en&pageid=cef