增加上下文隔离

This commit is contained in:
gaoshuaixing
2022-09-07 15:03:17 +08:00
parent 92bf43ac6f
commit ffcb16809e
3 changed files with 9 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
'use strict';
const dayjs = require('dayjs');
const path = require('path');
/**
* 默认配置
@@ -52,8 +53,9 @@ module.exports = (appInfo) => {
minHeight: 650,
webPreferences: {
//webSecurity: false,
contextIsolation: false, // 设置此项为false后,才可在渲染进程中使用electron api
contextIsolation: false, // false->可在渲染进程中使用electronApitrue->需要bridge.js(contextBridge)
nodeIntegration: true,
preload: path.join(appInfo.baseDir, 'preload', 'bridge.js'),
},
frame: true,
show: true,

View File

@@ -0,0 +1,5 @@
const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld('electron', {
ipcRenderer: ipcRenderer,
})

View File

@@ -1,4 +1,4 @@
const { ipcRenderer: ipc } = window.require && window.require('electron') || {}
const { ipcRenderer: ipc } = (window.require && window.require('electron')) || window.electron || {}
/**
* (将废弃,请使用 $ipcInvoke 代替)异步调用主函数