Is it possible to have a Delphi callback (event listener, etc) or is only Javascript possible?

1,495 views
Skip to first unread message

David Millington

unread,
Mar 7, 2016, 1:37:14 PM3/7/16
to delphichromiumembedded
I'm experimenting with Chromium trying to get some kind of callback into the Delphi host process - for example, so a button click could call a Delphi method, or a Javascript object's addEventListener() could eventually call back into Delphi. So far I've had no success and some of what I've read implies that it's not possible, callbacks to Delphi cannot occur, and that only Javascript can be attached to event listeners. Is that true?

Long version of the question

(The first paragraph is the short version :))

I have been trying a number of ways to add an event listener to an object in the loaded DOM. Visiting the DOM, by four separate methods so far, never calls into the visit method.

Compiles; the visit method is never called.

Oddly, even when the HTML page has apparently successfully loaded - I can see it in the browser - the loop in this code never terminates because the status is always 0, not 200. Also, VisitDOMProc doesn't end up calling the visit method. Note that avoiding Application.ProcessMessages is one main reason to use Chromium over embedded IE, too.

The OnProcessMessageReceived method is never called. I tried sending a message to PID_RENDERER and PID_BROWSER, both. My TCustomRenderProcessHandler instance is created in the form constructor. I could not find, in that code sample, a way to register the instance - wouldn't it need to be registered somewhere in order for the callback to work? The code sample shows nothing other than just creating it. Looking through all the browser and frame methods, there didn't seem to be any property or method to attach some other object like this handler.

4. Implementing ICefDomVisitor and then using it something like "Chromium.Browser.MainFrame.VisitDom(TDomVisitor.Create);". (This is an alternative to the VisitDOM that takes a method.) I can implement it, but am unsure what to return for Wrap(), which returns a pointer. Nil results in the visit() method never being called. Self, which is presumably wrong, causes an AV.

It's been disabled completely?

Henri Gourmets commented (22/11/2015) that you have to use a Javascript extension, and the updated guiclient demo uses ExecuteJavascript to add a JS method for an event listener (not Delphi.) This matches to some CEF threads I read too: https://bitbucket.org/chromiumembedded/cef/issues/933/provide-alternate-implementation-for where it mentions addEventListener being removed, with no alternative because "equivalent functionality can currently be achieved using JavaScript".

So - it is not possible for a JS object's addEventListener to, in any way, eventually call back into Delphi?

If so, I'm surprised - it's a really useful, and I'd think common, thing for a web browser to be used as a UI and so to interact with the host. Is that a scenario CEF supports these days? If it does, how do you do it?

Thanks for going through the long read (if you read it all ;)),

David



Costa Basil

unread,
Apr 23, 2016, 5:09:20 AM4/23/16
to delphichromiumembedded
Hi: I have the same question as you had. Did you find answers? Thanks

Amrut Patil

unread,
Nov 11, 2016, 6:44:49 AM11/11/16
to delphichromiumembedded
Hi David,

Did you got solution to your problem, I am trying to use CEF3 in Delphi 7 and not able to detect the click event, wanted to know which element was clicked

Thanks,
Amrut
Reply all
Reply to author
Forward
0 new messages