Communicate between guest/webview and render process


#1

preload.js

    let ipcRenderer = require('electron').ipcRenderer; //used to communicate with webview
    document.addEventListener('contextmenu', function(e) {
         console.log("right click detected")
         let data = {
            x: e.pageX,
            y: e.pageY,
            hasSelection: !!window.getSelection.toString(),
            href: false,
            img: false,
            video: false
        };
        let el = document.elementFromPoint(e.pageX - window.pageXOffset, e.pageY - window.pageYOffset);
        while (el && el.tagName) {
            if (!data.img && el.tagName === 'IMG')
                data.img = el.src;
            if (!data.href && el.href)
                data.href = el.href;
            el = el.parentNode;
        }
        ipcRenderer.sendToHost('contextmenu-data', data);
    });

Render.js

webview.addEventListener('ipc-message', (event,data) => {
    console.log(event.channel);
});

Webview tag:

let web_preferences = 'contextIsolation=true,offscreen=true,experimentalCanvasFeatures=false,experimentalFeatures=false,plugins=false,webaudio=false,allowRunningInsecureContent,webgl=no,minWidth=1200,minHeight=800,alwaysOnTop=true';
// Build tab and hit url if url available
if (url) {
`    iframeInit += "<div class='webview'><webview class='tabs-pane active'  webpreferences="+web_preferences +"autosize  id='' src='" + url + "' preload='file://" + __dirname + "/resources/projectfiles/browser/"+injection_script+"' ></webview></div>";`
} 
else {
`    iframeInit += "<div class='webview'><webview class='tabs-pane active' webpreferences='"+web_preferences +"autosize  id='' src='' preload='file://" + __dirname + "/resources/projectfiles/browser/"+injection_script+"' ></webview></div>";`
}

Expected Solution
When i do right click all required info is send to render.js -- event.channel

What is happening
Message is not received in render process

How to receive the guest page message from render.

Thanks
Jk