我有一个包装为电子应用程序的角度应用程序。现在,当我在渲染器进程中调用 Window.open 以获取内部路由时,我收到一条消息说Not allowed to load a local resource
并打开一个空白窗口。我该如何解决这个问题?
preload.js
const { contextBridge, ipcRenderer } = require("electron");
const validChannels = ['sample-event-1', 'sample-event-2', 'sample-event-3'];
contextBridge.exposeInMainWorld(
"api", {
send: (channel, data) => {
// whitelist channels To Main Process
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
}
},
receive: (channel, func) => {
// From Main Process
if (validChannels.includes(channel)) {
console.log('receive: ' + channel);
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
}
}
);
main.js
mywindow = new BrowserWindow({
width: 1024,
height: 768,
webPreferences: {
nodeIntegration: false,
webSecurity: true,
allowEval: false,
allowRunningInsecureContent: false,
contextIsolation: true, // protect against prototype pollution
enableRemoteModule: false, // turn off remote
preload: path.join(__dirname, "preload.js") // use a preload script
},
title: this._appTitle,
autoHideMenuBar: true,
icon: path.join(__dirname, '/../../favicon.ico')
});
我尝试过的事情
- 添加了一个监听器
new-window
:没有工作
myWindow.webContents.on('new-window', (event, url, frameName, disposition, options) => {
event.preventDefault()
const win = new BrowserWindow({
webContents: options.webContents, // use existing webContents if provided
show: false
})
win.once('ready-to-show', () => win.show())
if (!options.webContents) {
win.loadURL(url) // existing webContents will be navigated automatically
}
event.newGuest = win
});
nativeWindowOpen
向创建主 BrowserWindow 的主进程添加了标志。:没有工作
我不想使用这些require('electron')
模块,或者nodeIntegration:true
因为根据可用的在线/文档材料,它增加了安全问题。请建议!