Javascript event listener

Post Reply
zeeh1975
Posts: 1
Joined: Tue Apr 27, 2021 2:48 pm

Javascript event listener

Post by zeeh1975 »

Is there any way to reproduce this functionality in CEF4Delphi? i.e. listen to those events generated by a web page. Web page is third party so I don't control the way how messages are generated.

Code: Select all

function receiveMessage(event) {
var context = callbackFrontEnd;
	if (event.origin == context) {
		console.log('event.data', event.data);
      		switch (event.data.intencion.evento) {
			case 'EVENT1':
				// Actions for event 1
				console.log('Event 1');
				break;
			case 'EVENT2':
				// Actions for event 2
				console.log('Event 2');
				break;
			case 'ERROR':
				// Actions for error
				console.log('Error');
			break;
		}
	} 
return;
}

// Loads message event listener
function loadEventListener() {
console.log('Loading message event listener...');
window.addEventListener('message', receiveMessage);
console.log('Message event listener loaded.');
}
User avatar
salvadordf
Posts: 2966
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Javascript event listener

Post by salvadordf »

Hi,

You can inject your custom JavaScript code that overrides event listeners :
https://stackoverflow.com/questions/50370156/overriding-the-event-listener-in-javascript

Then use that listener to call a function you defined in a "JavaScript extension".

Open any of these demos for more details about JS extensions : JSExtension or JSRTTIExtension.

Read the code comments in the JSExtension demo.
Post Reply