electron/spec/fixtures/extensions/content-script/all_frames-preload.js

15 lines
544 B
JavaScript
Raw Normal View History

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