2017-02-24 26 views
0

我需要从devtools中触发此事件。它从使用mainWindow.webContents.send('get-holdings', 'get holdings!');触发电子BrowserWindow中devtools的ipcRenderer事件

主要过程(js)呼吁时,我有webPrefences镶有nodeIntegration: false如果nodeIntegration设置为true因为有jqueryangular错误触发。

对于调试,我想从devtools控制台执行它。我正在寻找需要放入devtools控制台的代码来触发get-holdings事件。

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

请帮忙!

回答

0

从devtron代码借用的想法,我解决它在预加载脚本中使用此

window.__electron = require('electron'); 

然后,我可以简单地做到以下几点:

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