2020-03-20 14:28:31 -06:00
|
|
|
const { ipcRenderer, webFrame } = require('electron');
|
2019-03-08 16:53:25 -07:00
|
|
|
|
|
|
|
if (process.isMainFrame) {
|
|
|
|
// https://github.com/electron/electron/issues/17252
|
|
|
|
ipcRenderer.on('executeJavaScriptInFrame', (event, frameRoutingId, code, responseId) => {
|
2020-03-20 14:28:31 -06:00
|
|
|
const frame = webFrame.findFrameByRoutingId(frameRoutingId);
|
2019-03-08 16:53:25 -07:00
|
|
|
if (!frame) {
|
2020-03-20 14:28:31 -06:00
|
|
|
throw new Error(`Can't find frame for routing ID ${frameRoutingId}`);
|
2019-03-08 16:53:25 -07:00
|
|
|
}
|
2019-04-30 08:08:33 -06:00
|
|
|
frame.executeJavaScript(code, false).then(result => {
|
2020-03-20 14:28:31 -06:00
|
|
|
event.sender.send(`executeJavaScriptInFrame_${responseId}`, result);
|
|
|
|
});
|
|
|
|
});
|
2019-03-08 16:53:25 -07:00
|
|
|
}
|