Вот мои настройки:
Шаг 1. Создайте файл preload.js с кодом:
window.ipcRenderer = require('electron').ipcRenderer;
Шаг 2. Предварительно загрузите этот файл в ваш main.js через webPreferences:
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false,
preload: __dirname + '/preload.js'
}
});
Шаг 3. В визуализаторе:
console.log(window.ipcRenderer); // Works!
Теперь, следуя руководству по безопасности Electron, я хочу включить contextIsolation=true
: https://electronjs.org/docs/tutorial/security#3-enable-context-isolation-for-remote-content
Шаг 2-бис.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
preload: __dirname + '/preload.js'
}
});
Шаг 3бис. В рендерере:
console.log(window.ipcRenderer); // undefined
Вопрос: можно ли использовать ipcRenderer при contextIsolation=true
?