Page 1 of 1

Handle javascript postMessage events

PostPosted: Mon Oct 28, 2019 11:08 am
by QuentinHP
Hi,
I'm new to Java implementation of CEF and would like to know if it possible to handle the "window.postMessage(...)" event.
I searched in the Java documentation and found examples of "CefMessageRouterHandler" but I'm not sure about the needed implementation.
Have a nice day,

Quentin

Re: Handle javascript postMessage events

PostPosted: Wed Oct 30, 2019 1:59 am
by Phylanx
Hi!

Yes, you will need the MessageRouter for that (has to be added on the CefClient).
First you will have to register the event. For this you might need to call a JavaScript on the browser instance to install the event (CefBrowser.executeJavaScript).
In the handling of the event you'll have to call the window.cefQuery method.
This will trigger the MessageRouters "onQuery" method.

See the detailed example app, there's some JavaScript handling shown.

Re: Handle javascript postMessage events

PostPosted: Wed Oct 30, 2019 6:59 am
by QuentinHP
Phylanx wrote:Hi!

Yes, you will need the MessageRouter for that (has to be added on the CefClient).
First you will have to register the event. For this you might need to call a JavaScript on the browser instance to install the event (CefBrowser.executeJavaScript).
In the handling of the event you'll have to call the window.cefQuery method.
This will trigger the MessageRouters "onQuery" method.

See the detailed example app, there's some JavaScript handling shown.

Hello and thanks, I'll give it a try.