SOLVED: Trigger ipcRenderer event from devtools


#1

I need to trigger this event from devtools. It gets triggered when called from the main process (js).
For debugging, I want to do it from devtools console.

ipcRenderer.on('get-holdings', (event, arg) => {
	var holdings;
	$.getJSON('https://mysite.com/api/holdings', function(res){
		holdings = res.data;
		console.log(holdings);
		ipcRenderer.send('save-holdings', holdings);
	});
	console.log(arg);
})

Please help!

I looking for the code that needs to be put into the devtools console to trigger the get-holdings event.


#2

Borrowing ideas from the code in devtron, I solved it using this in the pre-load script

window.__electron = require('electron');

Then, I could simply do the following:

win = window.__electron.remote.getCurrentWindow()
win.webContents.send('get-holdings', 'get holdings!');