Handle javascript postMessage events

Having problems with building or using the JCEF Java binding? Ask your questions here.

Handle javascript postMessage events

Postby QuentinHP » Mon Oct 28, 2019 11:08 am

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
QuentinHP
Newbie
 
Posts: 2
Joined: Mon Oct 28, 2019 10:43 am

Re: Handle javascript postMessage events

Postby Phylanx » Wed Oct 30, 2019 1:59 am

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.
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: Handle javascript postMessage events

Postby QuentinHP » Wed Oct 30, 2019 6:59 am

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.
QuentinHP
Newbie
 
Posts: 2
Joined: Mon Oct 28, 2019 10:43 am


Return to JCEF Forum

Who is online

Users browsing this forum: Google [Bot] and 11 guests