1.electron webview 动态添加preload
const mainWindow = new BrowserWindow({
width: 1400,
height: 670,
show: false,
menuBarVisible:false,
...(process.platform === 'linux' ? { icon } : {}),
webPreferences: {
},
})
2.监听窗口will-attach-webview事件完成后,动态添加 webPreferences.preload
mainWindow.webContents.on('will-attach-webview', (e, webPreferences) => {
webPreferences.sandbox = false
webPreferences.contextIsolation = true
webPreferences.preload = join(__dirname, '../preload/index.js')
})